@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,80 +0,0 @@
1
- /**
2
- * APIClaw Metered Billing - Pay-per-call execution wrapper
3
- *
4
- * Usage:
5
- * 1. Customer signs up with metered subscription
6
- * 2. Each API call via executeMetered() reports usage to Stripe
7
- * 3. Customer is billed at end of billing period based on usage
8
- */
9
- import { executeAPICall } from './execute.js';
10
- import { reportUsage, hasActiveMeteredSubscription, METERED_BILLING } from './stripe.js';
11
- /**
12
- * Execute an API call with metered billing tracking
13
- *
14
- * If customerId is provided and has active metered subscription,
15
- * usage is reported to Stripe after successful execution.
16
- */
17
- export async function executeMetered(providerId, action, params, options = {}) {
18
- const { customerId, skipBilling, customerKey, userId } = options;
19
- // Execute the API call
20
- const result = await executeAPICall(providerId, action, params, userId, customerKey);
21
- // Build response
22
- const response = {
23
- ...result,
24
- billing: {
25
- tracked: false,
26
- pricePerCall: METERED_BILLING.pricePerCall,
27
- },
28
- };
29
- // Skip billing if requested or no customer
30
- if (skipBilling || !customerId) {
31
- return response;
32
- }
33
- // Skip billing for failed calls
34
- if (!result.success) {
35
- return response;
36
- }
37
- // Check for active metered subscription
38
- const subscription = await hasActiveMeteredSubscription(customerId);
39
- if (!subscription.active) {
40
- console.log(`Customer ${customerId} has no active metered subscription`);
41
- return response;
42
- }
43
- // Report usage to Stripe meter
44
- const usageReport = await reportUsage(customerId, 1, `${customerId}_${providerId}_${action}_${Date.now()}`);
45
- if (usageReport.success) {
46
- response.billing = {
47
- tracked: true,
48
- customerId,
49
- pricePerCall: METERED_BILLING.pricePerCall,
50
- };
51
- }
52
- else {
53
- console.error(`Failed to report usage for ${customerId}:`, usageReport.error);
54
- }
55
- return response;
56
- }
57
- /**
58
- * Execute multiple API calls in batch with usage tracking
59
- */
60
- export async function executeMeteredBatch(calls, options = {}) {
61
- const results = await Promise.all(calls.map((call) => executeMetered(call.provider, call.action, call.params, options)));
62
- return results;
63
- }
64
- /**
65
- * Calculate estimated cost for a number of API calls
66
- */
67
- export function estimateCost(callCount) {
68
- return {
69
- calls: callCount,
70
- pricePerCall: METERED_BILLING.pricePerCall,
71
- totalCost: callCount * METERED_BILLING.pricePerCall,
72
- currency: 'USD',
73
- };
74
- }
75
- /**
76
- * Get metered billing configuration
77
- */
78
- export function getMeteredConfig() {
79
- return METERED_BILLING;
80
- }
@@ -1,276 +0,0 @@
1
- /**
2
- * APIClaw Open APIs - Free APIs that don't require authentication
3
- * These are called directly but still logged for analytics
4
- */
5
- /**
6
- * Registry of open APIs
7
- */
8
- export const openAPIs = {
9
- // Frankfurter - Free currency exchange rates (ECB data)
10
- frankfurter: {
11
- name: 'Frankfurter',
12
- description: 'Free currency exchange rates from European Central Bank',
13
- baseUrl: 'https://api.frankfurter.app',
14
- actions: {
15
- convert: {
16
- method: 'GET',
17
- path: (p) => `/latest?from=${p.from || 'SEK'}&to=${p.to || 'USD'}&amount=${p.amount || 1}`,
18
- transform: (data, params) => ({
19
- from: params.from || 'SEK',
20
- to: params.to || 'USD',
21
- amount: data.amount,
22
- result: data.rates?.[params.to || 'USD'],
23
- rate: data.rates?.[params.to || 'USD'] / data.amount,
24
- date: data.date,
25
- }),
26
- },
27
- latest: {
28
- method: 'GET',
29
- path: (p) => `/latest?from=${p.base || 'SEK'}${p.symbols ? `&to=${p.symbols}` : ''}`,
30
- transform: (data) => ({
31
- base: data.base,
32
- date: data.date,
33
- rates: data.rates,
34
- }),
35
- },
36
- historical: {
37
- method: 'GET',
38
- path: (p) => `/${p.date}?from=${p.base || 'SEK'}${p.symbols ? `&to=${p.symbols}` : ''}`,
39
- transform: (data) => ({
40
- base: data.base,
41
- date: data.date,
42
- rates: data.rates,
43
- }),
44
- },
45
- currencies: {
46
- method: 'GET',
47
- path: () => '/currencies',
48
- transform: (data) => ({ currencies: data }),
49
- },
50
- },
51
- },
52
- // CoinGecko - Free crypto data
53
- coingecko: {
54
- name: 'CoinGecko',
55
- description: 'Free cryptocurrency data - prices, market cap, volume',
56
- baseUrl: 'https://api.coingecko.com/api/v3',
57
- actions: {
58
- price: {
59
- method: 'GET',
60
- path: (p) => `/simple/price?ids=${p.ids || 'bitcoin'}&vs_currencies=${p.vs_currencies || 'usd'}`,
61
- },
62
- coins_list: {
63
- method: 'GET',
64
- path: () => '/coins/list',
65
- },
66
- coin: {
67
- method: 'GET',
68
- path: (p) => `/coins/${p.id}?localization=false&tickers=false&community_data=false&developer_data=false`,
69
- transform: (data) => ({
70
- id: data.id,
71
- symbol: data.symbol,
72
- name: data.name,
73
- price_usd: data.market_data?.current_price?.usd,
74
- market_cap_usd: data.market_data?.market_cap?.usd,
75
- price_change_24h: data.market_data?.price_change_percentage_24h,
76
- }),
77
- },
78
- trending: {
79
- method: 'GET',
80
- path: () => '/search/trending',
81
- transform: (data) => ({
82
- coins: data.coins?.map((c) => ({
83
- id: c.item.id,
84
- name: c.item.name,
85
- symbol: c.item.symbol,
86
- market_cap_rank: c.item.market_cap_rank,
87
- })),
88
- }),
89
- },
90
- },
91
- },
92
- // IP-API - Free IP geolocation
93
- ipapi: {
94
- name: 'IP-API',
95
- description: 'Free IP geolocation - get location from IP address',
96
- baseUrl: 'http://ip-api.com',
97
- actions: {
98
- lookup: {
99
- method: 'GET',
100
- path: (p) => `/json/${p.ip || ''}`,
101
- transform: (data) => ({
102
- ip: data.query,
103
- country: data.country,
104
- countryCode: data.countryCode,
105
- region: data.regionName,
106
- city: data.city,
107
- lat: data.lat,
108
- lon: data.lon,
109
- isp: data.isp,
110
- timezone: data.timezone,
111
- }),
112
- },
113
- },
114
- },
115
- // Kroki - Diagrams as code
116
- kroki: {
117
- name: 'Kroki',
118
- description: 'Generate diagrams from text. Supports: mermaid, d2, plantuml, graphviz, c4plantuml, blockdiag, bpmn. D2 is SVG-only.',
119
- baseUrl: 'https://kroki.io',
120
- actions: {
121
- render: {
122
- method: 'POST',
123
- path: () => '', // Custom handling below
124
- },
125
- },
126
- },
127
- };
128
- /**
129
- * Check if a provider is an open API
130
- */
131
- export function isOpenAPI(providerId) {
132
- return providerId in openAPIs;
133
- }
134
- /**
135
- * Get available actions for an open API
136
- */
137
- export function getOpenAPIActions(providerId) {
138
- return Object.keys(openAPIs[providerId]?.actions || {});
139
- }
140
- /**
141
- * Execute an open API call
142
- */
143
- export async function executeOpenAPI(providerId, action, params) {
144
- const config = openAPIs[providerId];
145
- if (!config) {
146
- return {
147
- success: false,
148
- provider: providerId,
149
- action,
150
- error: `Unknown open API: ${providerId}`,
151
- };
152
- }
153
- const actionConfig = config.actions[action];
154
- if (!actionConfig) {
155
- return {
156
- success: false,
157
- provider: providerId,
158
- action,
159
- error: `Unknown action '${action}' for ${providerId}. Available: ${Object.keys(config.actions).join(', ')}`,
160
- };
161
- }
162
- try {
163
- // Special handling for Kroki - use POST to get actual image data
164
- if (providerId === 'kroki') {
165
- const type = params.type || 'mermaid';
166
- let format = params.format || 'svg';
167
- const diagram = params.diagram || '';
168
- if (!diagram) {
169
- return {
170
- success: false,
171
- provider: providerId,
172
- action,
173
- error: 'Missing required param: diagram',
174
- };
175
- }
176
- // D2 only supports SVG
177
- if (type === 'd2' && format !== 'svg') {
178
- format = 'svg';
179
- }
180
- try {
181
- const response = await fetch(`https://kroki.io/${type}/${format}`, {
182
- method: 'POST',
183
- headers: { 'Content-Type': 'text/plain' },
184
- body: diagram,
185
- });
186
- if (!response.ok) {
187
- const err = await response.text();
188
- return {
189
- success: false,
190
- provider: providerId,
191
- action,
192
- error: `Kroki error: ${err}`,
193
- };
194
- }
195
- // For SVG, return the content directly; for binary, return base64
196
- if (format === 'svg') {
197
- const svg = await response.text();
198
- return {
199
- success: true,
200
- provider: providerId,
201
- action,
202
- data: {
203
- type,
204
- format: 'svg',
205
- content: svg,
206
- content_type: 'image/svg+xml',
207
- supported_types: ['mermaid', 'd2', 'plantuml', 'graphviz', 'c4plantuml', 'blockdiag', 'bpmn'],
208
- },
209
- };
210
- }
211
- else {
212
- const buffer = await response.arrayBuffer();
213
- const base64 = Buffer.from(buffer).toString('base64');
214
- return {
215
- success: true,
216
- provider: providerId,
217
- action,
218
- data: {
219
- type,
220
- format,
221
- content_base64: base64,
222
- content_type: format === 'png' ? 'image/png' : 'application/pdf',
223
- },
224
- };
225
- }
226
- }
227
- catch (e) {
228
- return {
229
- success: false,
230
- provider: providerId,
231
- action,
232
- error: e.message || 'Kroki request failed',
233
- };
234
- }
235
- }
236
- const url = config.baseUrl + actionConfig.path(params);
237
- const response = await fetch(url, { method: actionConfig.method });
238
- if (!response.ok) {
239
- return {
240
- success: false,
241
- provider: providerId,
242
- action,
243
- error: `HTTP ${response.status}: ${response.statusText}`,
244
- };
245
- }
246
- let data = await response.json();
247
- if (actionConfig.transform) {
248
- data = actionConfig.transform(data, params);
249
- }
250
- return {
251
- success: true,
252
- provider: providerId,
253
- action,
254
- data,
255
- };
256
- }
257
- catch (e) {
258
- return {
259
- success: false,
260
- provider: providerId,
261
- action,
262
- error: e.message || 'Request failed',
263
- };
264
- }
265
- }
266
- /**
267
- * List all open APIs with their actions
268
- */
269
- export function listOpenAPIs() {
270
- return Object.entries(openAPIs).map(([id, config]) => ({
271
- provider: id,
272
- name: config.name,
273
- description: config.description,
274
- actions: Object.keys(config.actions),
275
- }));
276
- }
package/dist/src/proxy.js DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * APIClaw Proxy - Fallback to hosted API when no local credentials
3
- */
4
- import { readSession, getMachineFingerprint } from './session.js';
5
- const PROXY_BASE = "https://brilliant-puffin-712.eu-west-1.convex.site/proxy";
6
- export async function callProxy(provider, params) {
7
- const url = `${PROXY_BASE}/${provider}`;
8
- // Get session and fingerprint for tracking
9
- const session = readSession();
10
- const fingerprint = getMachineFingerprint();
11
- const identifier = session?.workspaceId || `anon:${fingerprint}`;
12
- const response = await fetch(url, {
13
- method: "POST",
14
- headers: {
15
- "Content-Type": "application/json",
16
- "X-APIClaw-Identifier": identifier,
17
- "X-APIClaw-Provider": provider,
18
- "X-APIClaw-Action": params.action || "call",
19
- },
20
- body: JSON.stringify(params),
21
- });
22
- if (!response.ok) {
23
- const errorData = await response.json().catch(() => ({ error: "Proxy request failed" }));
24
- throw new Error(errorData.error || `Proxy error: ${response.status}`);
25
- }
26
- return response.json();
27
- }
28
- export const PROXY_PROVIDERS = ["openrouter", "brave_search", "resend", "elevenlabs", "46elks", "twilio", "replicate", "firecrawl", "e2b", "groq", "deepgram", "serper", "mistral", "cohere", "together", "stability", "assemblyai", "github", "apilayer"];
@@ -1,86 +0,0 @@
1
- /**
2
- * Session management for APIClaw MCP server
3
- * Stores session token locally at ~/.apiclaw/session
4
- */
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import * as os from 'os';
8
- const SESSION_DIR = path.join(os.homedir(), '.apiclaw');
9
- const SESSION_FILE = path.join(SESSION_DIR, 'session');
10
- /**
11
- * Ensure the ~/.apiclaw directory exists
12
- */
13
- function ensureSessionDir() {
14
- if (!fs.existsSync(SESSION_DIR)) {
15
- fs.mkdirSync(SESSION_DIR, { mode: 0o700 });
16
- }
17
- }
18
- /**
19
- * Read session from ~/.apiclaw/session
20
- * Returns null if no session file exists or if it's invalid
21
- */
22
- export function readSession() {
23
- try {
24
- if (!fs.existsSync(SESSION_FILE)) {
25
- return null;
26
- }
27
- const content = fs.readFileSync(SESSION_FILE, 'utf8');
28
- const data = JSON.parse(content);
29
- // Validate required fields
30
- if (!data.sessionToken || !data.workspaceId || !data.email) {
31
- console.error('[APIClaw] Invalid session file, clearing...');
32
- clearSession();
33
- return null;
34
- }
35
- return data;
36
- }
37
- catch (error) {
38
- console.error('[APIClaw] Error reading session:', error);
39
- return null;
40
- }
41
- }
42
- /**
43
- * Write session to ~/.apiclaw/session
44
- */
45
- export function writeSession(sessionToken, workspaceId, email) {
46
- try {
47
- ensureSessionDir();
48
- const data = {
49
- sessionToken,
50
- workspaceId,
51
- email,
52
- createdAt: Date.now(),
53
- };
54
- fs.writeFileSync(SESSION_FILE, JSON.stringify(data, null, 2), {
55
- mode: 0o600, // Read/write for owner only
56
- });
57
- console.error(`[APIClaw] Session saved for ${email}`);
58
- }
59
- catch (error) {
60
- console.error('[APIClaw] Error writing session:', error);
61
- throw error;
62
- }
63
- }
64
- /**
65
- * Clear session file
66
- */
67
- export function clearSession() {
68
- try {
69
- if (fs.existsSync(SESSION_FILE)) {
70
- fs.unlinkSync(SESSION_FILE);
71
- console.error('[APIClaw] Session cleared');
72
- }
73
- }
74
- catch (error) {
75
- console.error('[APIClaw] Error clearing session:', error);
76
- }
77
- }
78
- /**
79
- * Get machine fingerprint (for session binding)
80
- * Uses hostname + username as a simple fingerprint
81
- */
82
- export function getMachineFingerprint() {
83
- const hostname = os.hostname();
84
- const username = os.userInfo().username;
85
- return `${hostname}:${username}`;
86
- }