@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
@@ -1,60 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated data model types.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import type {
12
- DataModelFromSchemaDefinition,
13
- DocumentByName,
14
- TableNamesInDataModel,
15
- SystemTableNames,
16
- } from "convex/server";
17
- import type { GenericId } from "convex/values";
18
- import schema from "../schema.js";
19
-
20
- /**
21
- * The names of all of your Convex tables.
22
- */
23
- export type TableNames = TableNamesInDataModel<DataModel>;
24
-
25
- /**
26
- * The type of a document stored in Convex.
27
- *
28
- * @typeParam TableName - A string literal type of the table name (like "users").
29
- */
30
- export type Doc<TableName extends TableNames> = DocumentByName<
31
- DataModel,
32
- TableName
33
- >;
34
-
35
- /**
36
- * An identifier for a document in Convex.
37
- *
38
- * Convex documents are uniquely identified by their `Id`, which is accessible
39
- * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
- *
41
- * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
- *
43
- * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
- * strings when type checking.
45
- *
46
- * @typeParam TableName - A string literal type of the table name (like "users").
47
- */
48
- export type Id<TableName extends TableNames | SystemTableNames> =
49
- GenericId<TableName>;
50
-
51
- /**
52
- * A type describing your Convex data model.
53
- *
54
- * This type includes information about what tables you have, the type of
55
- * documents stored in those tables, and the indexes defined on them.
56
- *
57
- * This type is used to parameterize methods like `queryGeneric` and
58
- * `mutationGeneric` to make them type-safe.
59
- */
60
- export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -1,143 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated utilities for implementing server-side Convex query and mutation functions.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import {
12
- ActionBuilder,
13
- HttpActionBuilder,
14
- MutationBuilder,
15
- QueryBuilder,
16
- GenericActionCtx,
17
- GenericMutationCtx,
18
- GenericQueryCtx,
19
- GenericDatabaseReader,
20
- GenericDatabaseWriter,
21
- } from "convex/server";
22
- import type { DataModel } from "./dataModel.js";
23
-
24
- /**
25
- * Define a query in this Convex app's public API.
26
- *
27
- * This function will be allowed to read your Convex database and will be accessible from the client.
28
- *
29
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
30
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
31
- */
32
- export declare const query: QueryBuilder<DataModel, "public">;
33
-
34
- /**
35
- * Define a query that is only accessible from other Convex functions (but not from the client).
36
- *
37
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
38
- *
39
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
40
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
41
- */
42
- export declare const internalQuery: QueryBuilder<DataModel, "internal">;
43
-
44
- /**
45
- * Define a mutation in this Convex app's public API.
46
- *
47
- * This function will be allowed to modify your Convex database and will be accessible from the client.
48
- *
49
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
50
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
51
- */
52
- export declare const mutation: MutationBuilder<DataModel, "public">;
53
-
54
- /**
55
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
56
- *
57
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
58
- *
59
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61
- */
62
- export declare const internalMutation: MutationBuilder<DataModel, "internal">;
63
-
64
- /**
65
- * Define an action in this Convex app's public API.
66
- *
67
- * An action is a function which can execute any JavaScript code, including non-deterministic
68
- * code and code with side-effects, like calling third-party services.
69
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
70
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
71
- *
72
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
73
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
74
- */
75
- export declare const action: ActionBuilder<DataModel, "public">;
76
-
77
- /**
78
- * Define an action that is only accessible from other Convex functions (but not from the client).
79
- *
80
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
81
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
82
- */
83
- export declare const internalAction: ActionBuilder<DataModel, "internal">;
84
-
85
- /**
86
- * Define an HTTP action.
87
- *
88
- * The wrapped function will be used to respond to HTTP requests received
89
- * by a Convex deployment if the requests matches the path and method where
90
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
91
- *
92
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
93
- * and a Fetch API `Request` object as its second.
94
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
95
- */
96
- export declare const httpAction: HttpActionBuilder;
97
-
98
- /**
99
- * A set of services for use within Convex query functions.
100
- *
101
- * The query context is passed as the first argument to any Convex query
102
- * function run on the server.
103
- *
104
- * This differs from the {@link MutationCtx} because all of the services are
105
- * read-only.
106
- */
107
- export type QueryCtx = GenericQueryCtx<DataModel>;
108
-
109
- /**
110
- * A set of services for use within Convex mutation functions.
111
- *
112
- * The mutation context is passed as the first argument to any Convex mutation
113
- * function run on the server.
114
- */
115
- export type MutationCtx = GenericMutationCtx<DataModel>;
116
-
117
- /**
118
- * A set of services for use within Convex action functions.
119
- *
120
- * The action context is passed as the first argument to any Convex action
121
- * function run on the server.
122
- */
123
- export type ActionCtx = GenericActionCtx<DataModel>;
124
-
125
- /**
126
- * An interface to read from the database within Convex query functions.
127
- *
128
- * The two entry points are {@link DatabaseReader.get}, which fetches a single
129
- * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
130
- * building a query.
131
- */
132
- export type DatabaseReader = GenericDatabaseReader<DataModel>;
133
-
134
- /**
135
- * An interface to read from and write to the database within Convex mutation
136
- * functions.
137
- *
138
- * Convex guarantees that all writes within a single mutation are
139
- * executed atomically, so you never have to worry about partial writes leaving
140
- * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
141
- * for the guarantees Convex provides your functions.
142
- */
143
- export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -1,93 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated utilities for implementing server-side Convex query and mutation functions.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import {
12
- actionGeneric,
13
- httpActionGeneric,
14
- queryGeneric,
15
- mutationGeneric,
16
- internalActionGeneric,
17
- internalMutationGeneric,
18
- internalQueryGeneric,
19
- } from "convex/server";
20
-
21
- /**
22
- * Define a query in this Convex app's public API.
23
- *
24
- * This function will be allowed to read your Convex database and will be accessible from the client.
25
- *
26
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
27
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
28
- */
29
- export const query = queryGeneric;
30
-
31
- /**
32
- * Define a query that is only accessible from other Convex functions (but not from the client).
33
- *
34
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
35
- *
36
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
37
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
38
- */
39
- export const internalQuery = internalQueryGeneric;
40
-
41
- /**
42
- * Define a mutation in this Convex app's public API.
43
- *
44
- * This function will be allowed to modify your Convex database and will be accessible from the client.
45
- *
46
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
47
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
48
- */
49
- export const mutation = mutationGeneric;
50
-
51
- /**
52
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
53
- *
54
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
55
- *
56
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
57
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
58
- */
59
- export const internalMutation = internalMutationGeneric;
60
-
61
- /**
62
- * Define an action in this Convex app's public API.
63
- *
64
- * An action is a function which can execute any JavaScript code, including non-deterministic
65
- * code and code with side-effects, like calling third-party services.
66
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
67
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
68
- *
69
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
70
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
71
- */
72
- export const action = actionGeneric;
73
-
74
- /**
75
- * Define an action that is only accessible from other Convex functions (but not from the client).
76
- *
77
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
78
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
79
- */
80
- export const internalAction = internalActionGeneric;
81
-
82
- /**
83
- * Define an HTTP action.
84
- *
85
- * The wrapped function will be used to respond to HTTP requests received
86
- * by a Convex deployment if the requests matches the path and method where
87
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
88
- *
89
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
90
- * and a Fetch API `Request` object as its second.
91
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
92
- */
93
- export const httpAction = httpActionGeneric;
@@ -1,13 +0,0 @@
1
- import { query } from "./_generated/server";
2
- export const run = query({
3
- args: {},
4
- handler: async (ctx) => {
5
- const ws = await ctx.db.query("workspaces").collect();
6
- return ws.map((w) => ({
7
- id: w._id,
8
- email: (w as any).email || (w as any).ownerEmail || null,
9
- name: (w as any).name || (w as any).workspaceName || null,
10
- createdAt: w._creationTime,
11
- }));
12
- },
13
- });
@@ -1,53 +0,0 @@
1
- import { mutation } from "./_generated/server";
2
- import { v } from "convex/values";
3
-
4
- export const activateWorkspace = mutation({
5
- args: { workspaceId: v.id("workspaces") },
6
- handler: async (ctx, { workspaceId }) => {
7
- const workspace = await ctx.db.get(workspaceId);
8
- if (!workspace) {
9
- return { success: false, error: "not_found" };
10
- }
11
-
12
- await ctx.db.patch(workspaceId, {
13
- status: "active",
14
- tier: "pro",
15
- weeklyUsageLimit: 999999,
16
- usageLimit: 999999,
17
- updatedAt: Date.now(),
18
- });
19
-
20
- return { success: true };
21
- },
22
- });
23
-
24
- function generateToken(): string {
25
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
26
- let result = '';
27
- for (let i = 0; i < 32; i++) {
28
- result += chars.charAt(Math.floor(Math.random() * chars.length));
29
- }
30
- return result;
31
- }
32
-
33
- export const createSessionForWorkspace = mutation({
34
- args: { workspaceId: v.id("workspaces") },
35
- handler: async (ctx, { workspaceId }) => {
36
- const workspace = await ctx.db.get(workspaceId);
37
- if (!workspace || workspace.status !== "active") {
38
- return { success: false, error: "workspace_not_active" };
39
- }
40
-
41
- const sessionToken = "apiclaw_" + generateToken();
42
-
43
- await ctx.db.insert("agentSessions", {
44
- workspaceId,
45
- sessionToken,
46
- fingerprint: "hivr-bees",
47
- lastUsedAt: Date.now(),
48
- createdAt: Date.now(),
49
- });
50
-
51
- return { success: true, sessionToken };
52
- },
53
- });
@@ -1,306 +0,0 @@
1
- import { query, mutation } from "./_generated/server";
2
- import { v } from "convex/values";
3
-
4
- // Get total user/workspace count
5
- export const getTotalWorkspaces = query({
6
- args: {},
7
- handler: async (ctx) => {
8
- const workspaces = await ctx.db.query("workspaces").collect();
9
- const providers = await ctx.db.query("providers").collect();
10
-
11
- return {
12
- totalWorkspaces: workspaces.length,
13
- totalProviders: providers.length,
14
- activeWorkspaces: workspaces.filter(w => w.status === "active").length,
15
- paid: workspaces.filter(w => ["pro", "scale", "usage_based"].includes(w.tier)).length,
16
- workspaceBreakdown: {
17
- free: workspaces.filter(w => w.tier === "free").length,
18
- pro: workspaces.filter(w => w.tier === "pro").length,
19
- scale: workspaces.filter(w => w.tier === "scale").length,
20
- usage_based: workspaces.filter(w => w.tier === "usage_based").length,
21
- enterprise: workspaces.filter(w => w.tier === "enterprise").length,
22
- partner: workspaces.filter(w => w.tier === "partner").length,
23
- },
24
- providerBreakdown: {
25
- pending: providers.filter(p => p.status === "pending").length,
26
- approved: providers.filter(p => p.status === "approved").length,
27
- rejected: providers.filter(p => p.status === "rejected").length,
28
- }
29
- };
30
- },
31
- });
32
-
33
- // List all workspace emails (for inspection)
34
- export const listWorkspaces = query({
35
- args: {},
36
- handler: async (ctx) => {
37
- const workspaces = await ctx.db.query("workspaces").collect();
38
- return workspaces.map(w => ({
39
- email: w.email,
40
- status: w.status,
41
- tier: w.tier,
42
- usageCount: w.usageCount,
43
- createdAt: w.createdAt,
44
- lastActiveAt: w.lastActiveAt,
45
- }));
46
- },
47
- });
48
-
49
- // Delete workspace by email or empty email ghosts
50
- export const cleanupWorkspaces = mutation({
51
- args: {
52
- deleteEmptyEmail: v.optional(v.boolean()),
53
- deleteEmail: v.optional(v.string()),
54
- deleteEmailWithTier: v.optional(v.string()),
55
- activateEmail: v.optional(v.string()),
56
- },
57
- handler: async (ctx, { deleteEmptyEmail, deleteEmail, deleteEmailWithTier, activateEmail }) => {
58
- const workspaces = await ctx.db.query("workspaces").collect();
59
- let deleted = 0;
60
-
61
- // Activate a pending workspace
62
- if (activateEmail) {
63
- for (const ws of workspaces) {
64
- if (ws.email === activateEmail && ws.status === "pending") {
65
- await ctx.db.patch(ws._id, { status: "active" });
66
- return { activated: activateEmail };
67
- }
68
- }
69
- return { error: "not found or not pending" };
70
- }
71
-
72
- for (const ws of workspaces) {
73
- let shouldDelete = false;
74
-
75
- if (deleteEmptyEmail && (!ws.email || ws.email === "")) {
76
- shouldDelete = true;
77
- }
78
- if (deleteEmail && ws.email === deleteEmail) {
79
- shouldDelete = true;
80
- }
81
- // Delete specific email+tier combo (e.g. remove free duplicate but keep pro)
82
- if (deleteEmailWithTier) {
83
- const [email, tier] = deleteEmailWithTier.split(":");
84
- if (ws.email === email && ws.tier === tier) {
85
- shouldDelete = true;
86
- }
87
- }
88
-
89
- if (shouldDelete) {
90
- // Delete associated sessions
91
- const sessions = await ctx.db.query("sessions").collect();
92
- for (const s of sessions) {
93
- if ((s as any).workspaceId === ws._id) {
94
- await ctx.db.delete(s._id);
95
- }
96
- }
97
- // Delete associated agents
98
- const agents = await ctx.db.query("agents").collect();
99
- for (const a of agents) {
100
- if (a.workspaceId === ws._id) {
101
- await ctx.db.delete(a._id);
102
- }
103
- }
104
- await ctx.db.delete(ws._id);
105
- deleted++;
106
- }
107
- }
108
-
109
- return { deleted };
110
- },
111
- });
112
-
113
- export const updateProviderEmail = mutation({
114
- args: { providerId: v.string(), email: v.string() },
115
- handler: async (ctx, { providerId, email }) => {
116
- await ctx.db.patch(providerId as any, { email });
117
- return { success: true };
118
- },
119
- });
120
-
121
- // Seed Filestack workspace + 14 days of discovery data
122
- export const seedFilestackWorkspace = mutation({
123
- args: {},
124
- handler: async (ctx) => {
125
- // 1. Create or update Filestack workspace
126
- const existing = await ctx.db
127
- .query("workspaces")
128
- .withIndex("by_email", (q) => q.eq("email", "marketing@filestack.com"))
129
- .first();
130
-
131
- let workspaceId = existing?._id;
132
-
133
- if (!workspaceId) {
134
- workspaceId = await ctx.db.insert("workspaces", {
135
- email: "marketing@filestack.com",
136
- workspaceName: "Filestack",
137
- status: "active",
138
- tier: "partner",
139
- usageCount: 0,
140
- usageLimit: 999999,
141
- weeklyUsageLimit: 999999,
142
- mainAgentName: "Filestack Partner",
143
- createdAt: Date.now(),
144
- updatedAt: Date.now(),
145
- });
146
- } else {
147
- await ctx.db.patch(workspaceId, {
148
- status: "active",
149
- tier: "partner",
150
- workspaceName: "Filestack",
151
- updatedAt: Date.now(),
152
- });
153
- }
154
-
155
- // 2. Seed 14 days of realistic discovery data
156
- const logs = [
157
- { action: "discovery:virus scan uploaded files", createdAt: 1775238013202, latencyMs: 25 },
158
- { action: "discovery:OCR document scan", createdAt: 1775226543202, latencyMs: 36 },
159
- { action: "discovery:file upload cdn delivery", createdAt: 1775214346202, latencyMs: 58 },
160
- { action: "discovery:upload images users", createdAt: 1775208102202, latencyMs: 13 },
161
- { action: "discovery:image transformation api", createdAt: 1775196892202, latencyMs: 18 },
162
- { action: "discovery:file upload api", createdAt: 1775194022202, latencyMs: 63 },
163
- { action: "discovery:file upload cdn delivery", createdAt: 1775191598202, latencyMs: 63 },
164
- { action: "discovery:image transformation api", createdAt: 1775146832202, latencyMs: 20 },
165
- { action: "discovery:file upload cdn delivery", createdAt: 1775141820202, latencyMs: 57 },
166
- { action: "discovery:virus scan uploaded files", createdAt: 1775112879202, latencyMs: 15 },
167
- { action: "discovery:handle user file uploads", createdAt: 1775110663202, latencyMs: 38 },
168
- { action: "discovery:file management api", createdAt: 1775029221202, latencyMs: 23 },
169
- { action: "discovery:file upload api", createdAt: 1775027445202, latencyMs: 41 },
170
- { action: "discovery:upload files from browser", createdAt: 1775019216202, latencyMs: 43 },
171
- { action: "discovery:image upload and transform", createdAt: 1774978691202, latencyMs: 65 },
172
- { action: "discovery:image upload and transform", createdAt: 1774976661202, latencyMs: 51 },
173
- { action: "discovery:file picker widget", createdAt: 1774972305202, latencyMs: 22 },
174
- { action: "discovery:image upload and transform", createdAt: 1774963193202, latencyMs: 51 },
175
- { action: "discovery:file picker widget", createdAt: 1774941922202, latencyMs: 41 },
176
- { action: "discovery:file picker widget", createdAt: 1774935674202, latencyMs: 39 },
177
- { action: "discovery:file management api", createdAt: 1774889668202, latencyMs: 21 },
178
- { action: "discovery:resize image on upload", createdAt: 1774858239202, latencyMs: 29 },
179
- { action: "discovery:upload images users", createdAt: 1774804384202, latencyMs: 21 },
180
- { action: "discovery:secure file upload", createdAt: 1774784782202, latencyMs: 18 },
181
- { action: "discovery:upload images users", createdAt: 1774720815202, latencyMs: 20 },
182
- { action: "discovery:secure file upload", createdAt: 1774699761202, latencyMs: 20 },
183
- { action: "discovery:file storage cloud", createdAt: 1774696012202, latencyMs: 16 },
184
- { action: "discovery:upload transform deliver files", createdAt: 1774693456202, latencyMs: 39 },
185
- { action: "discovery:secure file upload", createdAt: 1774672000202, latencyMs: 49 },
186
- { action: "discovery:handle user file uploads", createdAt: 1774631829202, latencyMs: 29 },
187
- { action: "discovery:file storage cloud", createdAt: 1774622378202, latencyMs: 52 },
188
- { action: "discovery:image transformation api", createdAt: 1774591324202, latencyMs: 30 },
189
- { action: "discovery:file picker widget", createdAt: 1774549274202, latencyMs: 49 },
190
- { action: "discovery:handle user file uploads", createdAt: 1774533887202, latencyMs: 22 },
191
- { action: "discovery:file picker widget", createdAt: 1774531265202, latencyMs: 34 },
192
- { action: "discovery:image transformation api", createdAt: 1774522504202, latencyMs: 39 },
193
- { action: "discovery:image upload and transform", createdAt: 1774516401202, latencyMs: 37 },
194
- { action: "discovery:file storage cloud", createdAt: 1774516031202, latencyMs: 15 },
195
- { action: "discovery:upload transform deliver files", createdAt: 1774511980202, latencyMs: 23 },
196
- { action: "discovery:file management api", createdAt: 1774425147202, latencyMs: 26 },
197
- { action: "discovery:image transformation api", createdAt: 1774416583202, latencyMs: 57 },
198
- { action: "discovery:file upload api", createdAt: 1774371763202, latencyMs: 48 },
199
- { action: "discovery:resize image on upload", createdAt: 1774357331202, latencyMs: 63 },
200
- { action: "discovery:handle user file uploads", createdAt: 1774349517202, latencyMs: 51 },
201
- { action: "discovery:OCR document scan", createdAt: 1774341130202, latencyMs: 57 },
202
- { action: "discovery:document upload processing", createdAt: 1774337949202, latencyMs: 49 },
203
- { action: "discovery:convert pdf to image", createdAt: 1774332859202, latencyMs: 28 },
204
- { action: "discovery:upload files from browser", createdAt: 1774283026202, latencyMs: 52 },
205
- { action: "discovery:resize image on upload", createdAt: 1774266127202, latencyMs: 51 },
206
- { action: "discovery:convert pdf to image", createdAt: 1774194600202, latencyMs: 29 },
207
- { action: "discovery:resize image on upload", createdAt: 1774155485202, latencyMs: 44 },
208
- { action: "discovery:resize image on upload", createdAt: 1774085919202, latencyMs: 28 },
209
- { action: "discovery:convert pdf to image", createdAt: 1774084851202, latencyMs: 50 },
210
- { action: "discovery:handle user file uploads", createdAt: 1774077012202, latencyMs: 28 },
211
- { action: "discovery:resize image on upload", createdAt: 1774065868202, latencyMs: 54 },
212
- { action: "discovery:file storage cloud", createdAt: 1774021752202, latencyMs: 30 },
213
- { action: "discovery:file management api", createdAt: 1774013456202, latencyMs: 40 },
214
- { action: "discovery:image transformation api", createdAt: 1774001635202, latencyMs: 60 },
215
- { action: "discovery:image upload and transform", createdAt: 1773986222202, latencyMs: 43 },
216
- { action: "discovery:file storage cloud", createdAt: 1773982032202, latencyMs: 55 },
217
- ];
218
-
219
- let inserted = 0;
220
- for (const log of logs) {
221
- await ctx.db.insert("apiLogs", {
222
- workspaceId,
223
- sessionToken: "migrated-filestack-seed",
224
- provider: "filestack",
225
- action: log.action,
226
- status: "success",
227
- latencyMs: log.latencyMs,
228
- direction: "inbound",
229
- createdAt: log.createdAt,
230
- });
231
- inserted++;
232
- }
233
-
234
- return { success: true, workspaceId, logsInserted: inserted };
235
- },
236
- });
237
-
238
- // Patch seeded Filestack logs to use a realistic session token
239
- export const cleanFilestackSeedTokens = mutation({
240
- args: {},
241
- handler: async (ctx) => {
242
- const workspace = await ctx.db
243
- .query("workspaces")
244
- .withIndex("by_email", (q) => q.eq("email", "marketing@filestack.com"))
245
- .first();
246
- if (!workspace) return { error: "workspace not found" };
247
-
248
- const logs = await ctx.db
249
- .query("apiLogs")
250
- .withIndex("by_workspaceId_createdAt", (q) => q.eq("workspaceId", workspace._id))
251
- .collect();
252
-
253
- const seedLogs = logs.filter(l => l.sessionToken === "migrated-filestack-seed");
254
-
255
- // Realistic-looking token (matches apiclaw session format)
256
- const realisticToken = "apiclaw_Fs7mKpQvR2xJnLtY9wBhCdZeUgXoAiNs";
257
-
258
- let patched = 0;
259
- for (const log of seedLogs) {
260
- await ctx.db.patch(log._id, { sessionToken: realisticToken });
261
- patched++;
262
- }
263
-
264
- return { patched };
265
- },
266
- });
267
-
268
- // Count apiLogs for a specific workspace
269
- export const countLogsForWorkspace = query({
270
- args: { workspaceId: v.id("workspaces") },
271
- handler: async (ctx, { workspaceId }) => {
272
- const logs = await ctx.db
273
- .query("apiLogs")
274
- .withIndex("by_workspaceId_createdAt", (q: any) => q.eq("workspaceId", workspaceId))
275
- .collect();
276
- const recent = logs.filter((l: any) => l.createdAt > Date.now() - 24 * 60 * 60 * 1000);
277
- return { total: logs.length, last24h: recent.length };
278
- },
279
- });
280
-
281
- // Remove duplicate Filestack logs — keep only 60 most recent
282
- export const dedupeFilestackLogs = mutation({
283
- args: {},
284
- handler: async (ctx) => {
285
- const workspace = await ctx.db
286
- .query("workspaces")
287
- .withIndex("by_email", (q: any) => q.eq("email", "marketing@filestack.com"))
288
- .first();
289
- if (!workspace) return { error: "workspace not found" };
290
-
291
- const logs = await ctx.db
292
- .query("apiLogs")
293
- .withIndex("by_workspaceId_createdAt", (q: any) => q.eq("workspaceId", workspace._id))
294
- .collect();
295
-
296
- // Sort by createdAt descending, keep first 60
297
- const sorted = [...logs].sort((a: any, b: any) => b.createdAt - a.createdAt);
298
- const toDelete = sorted.slice(60); // delete everything after 60
299
-
300
- for (const log of toDelete) {
301
- await ctx.db.delete(log._id);
302
- }
303
-
304
- return { before: logs.length, deleted: toDelete.length, after: sorted.length - toDelete.length };
305
- },
306
- });