@l4yercak3/cli 1.3.1 → 2.0.0-alpha.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 (357) hide show
  1. package/README.md +10 -220
  2. package/dist/api/client.d.ts +12 -0
  3. package/dist/api/client.d.ts.map +1 -0
  4. package/dist/api/client.js +37 -0
  5. package/dist/api/client.js.map +1 -0
  6. package/dist/api/platform.d.ts +161 -0
  7. package/dist/api/platform.d.ts.map +1 -0
  8. package/dist/api/platform.js +70 -0
  9. package/dist/api/platform.js.map +1 -0
  10. package/dist/bin/sevenlayers.d.ts +3 -0
  11. package/dist/bin/sevenlayers.d.ts.map +1 -0
  12. package/dist/bin/sevenlayers.js +198 -0
  13. package/dist/bin/sevenlayers.js.map +1 -0
  14. package/dist/commands/agent/catalog.d.ts +5 -0
  15. package/dist/commands/agent/catalog.d.ts.map +1 -0
  16. package/dist/commands/agent/catalog.js +142 -0
  17. package/dist/commands/agent/catalog.js.map +1 -0
  18. package/dist/commands/agent/drift.d.ts +5 -0
  19. package/dist/commands/agent/drift.d.ts.map +1 -0
  20. package/dist/commands/agent/drift.js +113 -0
  21. package/dist/commands/agent/drift.js.map +1 -0
  22. package/dist/commands/agent/init.d.ts +5 -0
  23. package/dist/commands/agent/init.d.ts.map +1 -0
  24. package/dist/commands/agent/init.js +75 -0
  25. package/dist/commands/agent/init.js.map +1 -0
  26. package/dist/commands/agent/permissions.d.ts +5 -0
  27. package/dist/commands/agent/permissions.d.ts.map +1 -0
  28. package/dist/commands/agent/permissions.js +88 -0
  29. package/dist/commands/agent/permissions.js.map +1 -0
  30. package/dist/commands/agent/runner.d.ts +14 -0
  31. package/dist/commands/agent/runner.d.ts.map +1 -0
  32. package/dist/commands/agent/runner.js +59 -0
  33. package/dist/commands/agent/runner.js.map +1 -0
  34. package/dist/commands/agent/shared.d.ts +13 -0
  35. package/dist/commands/agent/shared.d.ts.map +1 -0
  36. package/dist/commands/agent/shared.js +31 -0
  37. package/dist/commands/agent/shared.js.map +1 -0
  38. package/dist/commands/agent/template.d.ts +5 -0
  39. package/dist/commands/agent/template.d.ts.map +1 -0
  40. package/dist/commands/agent/template.js +104 -0
  41. package/dist/commands/agent/template.js.map +1 -0
  42. package/dist/commands/app/connect.d.ts +7 -0
  43. package/dist/commands/app/connect.d.ts.map +1 -0
  44. package/dist/commands/app/connect.js +12 -0
  45. package/dist/commands/app/connect.js.map +1 -0
  46. package/dist/commands/app/init.d.ts +7 -0
  47. package/dist/commands/app/init.d.ts.map +1 -0
  48. package/dist/commands/app/init.js +12 -0
  49. package/dist/commands/app/init.js.map +1 -0
  50. package/dist/commands/app/link.d.ts +3 -0
  51. package/dist/commands/app/link.d.ts.map +1 -0
  52. package/dist/commands/app/link.js +92 -0
  53. package/dist/commands/app/link.js.map +1 -0
  54. package/dist/commands/app/pages.d.ts +15 -0
  55. package/dist/commands/app/pages.d.ts.map +1 -0
  56. package/dist/commands/app/pages.js +180 -0
  57. package/dist/commands/app/pages.js.map +1 -0
  58. package/dist/commands/app/register.d.ts +3 -0
  59. package/dist/commands/app/register.d.ts.map +1 -0
  60. package/dist/commands/app/register.js +120 -0
  61. package/dist/commands/app/register.js.map +1 -0
  62. package/dist/commands/app/remote.d.ts +14 -0
  63. package/dist/commands/app/remote.d.ts.map +1 -0
  64. package/dist/commands/app/remote.js +44 -0
  65. package/dist/commands/app/remote.js.map +1 -0
  66. package/dist/commands/app/setup.d.ts +3 -0
  67. package/dist/commands/app/setup.d.ts.map +1 -0
  68. package/dist/commands/app/setup.js +299 -0
  69. package/dist/commands/app/setup.js.map +1 -0
  70. package/dist/commands/app/shared.d.ts +9 -0
  71. package/dist/commands/app/shared.d.ts.map +1 -0
  72. package/dist/commands/app/shared.js +122 -0
  73. package/dist/commands/app/shared.js.map +1 -0
  74. package/dist/commands/app/sync.d.ts +7 -0
  75. package/dist/commands/app/sync.d.ts.map +1 -0
  76. package/dist/commands/app/sync.js +107 -0
  77. package/dist/commands/app/sync.js.map +1 -0
  78. package/dist/commands/booking/check.d.ts +3 -0
  79. package/dist/commands/booking/check.d.ts.map +1 -0
  80. package/dist/commands/booking/check.js +68 -0
  81. package/dist/commands/booking/check.js.map +1 -0
  82. package/dist/commands/booking/setup.d.ts +3 -0
  83. package/dist/commands/booking/setup.d.ts.map +1 -0
  84. package/dist/commands/booking/setup.js +95 -0
  85. package/dist/commands/booking/setup.js.map +1 -0
  86. package/dist/commands/booking/shared.d.ts +31 -0
  87. package/dist/commands/booking/shared.d.ts.map +1 -0
  88. package/dist/commands/booking/shared.js +112 -0
  89. package/dist/commands/booking/shared.js.map +1 -0
  90. package/dist/commands/booking/smoke.d.ts +3 -0
  91. package/dist/commands/booking/smoke.d.ts.map +1 -0
  92. package/dist/commands/booking/smoke.js +101 -0
  93. package/dist/commands/booking/smoke.js.map +1 -0
  94. package/dist/commands/cms/bind.d.ts +3 -0
  95. package/dist/commands/cms/bind.d.ts.map +1 -0
  96. package/dist/commands/cms/bind.js +212 -0
  97. package/dist/commands/cms/bind.js.map +1 -0
  98. package/dist/commands/cms/content.d.ts +40 -0
  99. package/dist/commands/cms/content.d.ts.map +1 -0
  100. package/dist/commands/cms/content.js +169 -0
  101. package/dist/commands/cms/content.js.map +1 -0
  102. package/dist/commands/cms/doctor.d.ts +3 -0
  103. package/dist/commands/cms/doctor.d.ts.map +1 -0
  104. package/dist/commands/cms/doctor.js +69 -0
  105. package/dist/commands/cms/doctor.js.map +1 -0
  106. package/dist/commands/cms/migrate.d.ts +3 -0
  107. package/dist/commands/cms/migrate.d.ts.map +1 -0
  108. package/dist/commands/cms/migrate.js +78 -0
  109. package/dist/commands/cms/migrate.js.map +1 -0
  110. package/dist/commands/cms/registry.d.ts +3 -0
  111. package/dist/commands/cms/registry.d.ts.map +1 -0
  112. package/dist/commands/cms/registry.js +161 -0
  113. package/dist/commands/cms/registry.js.map +1 -0
  114. package/dist/commands/cms/seed.d.ts +3 -0
  115. package/dist/commands/cms/seed.d.ts.map +1 -0
  116. package/dist/commands/cms/seed.js +102 -0
  117. package/dist/commands/cms/seed.js.map +1 -0
  118. package/dist/commands/cms/shared.d.ts +22 -0
  119. package/dist/commands/cms/shared.d.ts.map +1 -0
  120. package/dist/commands/cms/shared.js +82 -0
  121. package/dist/commands/cms/shared.js.map +1 -0
  122. package/dist/commands/doctor/target.d.ts +3 -0
  123. package/dist/commands/doctor/target.d.ts.map +1 -0
  124. package/dist/commands/doctor/target.js +46 -0
  125. package/dist/commands/doctor/target.js.map +1 -0
  126. package/dist/commands/env/list.d.ts +3 -0
  127. package/dist/commands/env/list.d.ts.map +1 -0
  128. package/dist/commands/env/list.js +28 -0
  129. package/dist/commands/env/list.js.map +1 -0
  130. package/dist/commands/env/set.d.ts +3 -0
  131. package/dist/commands/env/set.d.ts.map +1 -0
  132. package/dist/commands/env/set.js +36 -0
  133. package/dist/commands/env/set.js.map +1 -0
  134. package/dist/commands/env/use.d.ts +3 -0
  135. package/dist/commands/env/use.d.ts.map +1 -0
  136. package/dist/commands/env/use.js +15 -0
  137. package/dist/commands/env/use.js.map +1 -0
  138. package/dist/commands/legacy/connect.d.ts +3 -0
  139. package/dist/commands/legacy/connect.d.ts.map +1 -0
  140. package/dist/commands/legacy/connect.js +8 -0
  141. package/dist/commands/legacy/connect.js.map +1 -0
  142. package/dist/commands/legacy/pages.d.ts +3 -0
  143. package/dist/commands/legacy/pages.d.ts.map +1 -0
  144. package/dist/commands/legacy/pages.js +16 -0
  145. package/dist/commands/legacy/pages.js.map +1 -0
  146. package/dist/commands/legacy/spread.d.ts +3 -0
  147. package/dist/commands/legacy/spread.d.ts.map +1 -0
  148. package/dist/commands/legacy/spread.js +8 -0
  149. package/dist/commands/legacy/spread.js.map +1 -0
  150. package/dist/commands/legacy/sync.d.ts +3 -0
  151. package/dist/commands/legacy/sync.d.ts.map +1 -0
  152. package/dist/commands/legacy/sync.js +8 -0
  153. package/dist/commands/legacy/sync.js.map +1 -0
  154. package/dist/config/env-diff.d.ts +10 -0
  155. package/dist/config/env-diff.d.ts.map +1 -0
  156. package/dist/config/env-diff.js +24 -0
  157. package/dist/config/env-diff.js.map +1 -0
  158. package/dist/config/env-parser.d.ts +20 -0
  159. package/dist/config/env-parser.d.ts.map +1 -0
  160. package/dist/config/env-parser.js +70 -0
  161. package/dist/config/env-parser.js.map +1 -0
  162. package/dist/config/env-writer.d.ts +22 -0
  163. package/dist/config/env-writer.d.ts.map +1 -0
  164. package/dist/config/env-writer.js +172 -0
  165. package/dist/config/env-writer.js.map +1 -0
  166. package/dist/config/profile-store.d.ts +29 -0
  167. package/dist/config/profile-store.d.ts.map +1 -0
  168. package/dist/config/profile-store.js +257 -0
  169. package/dist/config/profile-store.js.map +1 -0
  170. package/dist/core/args.d.ts +11 -0
  171. package/dist/core/args.d.ts.map +1 -0
  172. package/dist/core/args.js +106 -0
  173. package/dist/core/args.js.map +1 -0
  174. package/dist/core/colors.d.ts +6 -0
  175. package/dist/core/colors.d.ts.map +1 -0
  176. package/dist/core/colors.js +29 -0
  177. package/dist/core/colors.js.map +1 -0
  178. package/dist/safety/target-guard.d.ts +16 -0
  179. package/dist/safety/target-guard.d.ts.map +1 -0
  180. package/dist/safety/target-guard.js +55 -0
  181. package/dist/safety/target-guard.js.map +1 -0
  182. package/dist/testing/booking-smoke.d.ts +17 -0
  183. package/dist/testing/booking-smoke.d.ts.map +1 -0
  184. package/dist/testing/booking-smoke.js +43 -0
  185. package/dist/testing/booking-smoke.js.map +1 -0
  186. package/dist/tests/agent-commands.test.d.ts +2 -0
  187. package/dist/tests/agent-commands.test.d.ts.map +1 -0
  188. package/dist/tests/agent-commands.test.js +180 -0
  189. package/dist/tests/agent-commands.test.js.map +1 -0
  190. package/dist/tests/agent-governance.test.d.ts +2 -0
  191. package/dist/tests/agent-governance.test.d.ts.map +1 -0
  192. package/dist/tests/agent-governance.test.js +233 -0
  193. package/dist/tests/agent-governance.test.js.map +1 -0
  194. package/dist/tests/app-commands.test.d.ts +2 -0
  195. package/dist/tests/app-commands.test.d.ts.map +1 -0
  196. package/dist/tests/app-commands.test.js +462 -0
  197. package/dist/tests/app-commands.test.js.map +1 -0
  198. package/dist/tests/booking-commands.test.d.ts +2 -0
  199. package/dist/tests/booking-commands.test.d.ts.map +1 -0
  200. package/dist/tests/booking-commands.test.js +204 -0
  201. package/dist/tests/booking-commands.test.js.map +1 -0
  202. package/dist/tests/booking-smoke.test.d.ts +2 -0
  203. package/dist/tests/booking-smoke.test.d.ts.map +1 -0
  204. package/dist/tests/booking-smoke.test.js +183 -0
  205. package/dist/tests/booking-smoke.test.js.map +1 -0
  206. package/dist/tests/cms-commands.test.d.ts +2 -0
  207. package/dist/tests/cms-commands.test.d.ts.map +1 -0
  208. package/dist/tests/cms-commands.test.js +254 -0
  209. package/dist/tests/cms-commands.test.js.map +1 -0
  210. package/dist/tests/cms-ops.test.d.ts +2 -0
  211. package/dist/tests/cms-ops.test.d.ts.map +1 -0
  212. package/dist/tests/cms-ops.test.js +125 -0
  213. package/dist/tests/cms-ops.test.js.map +1 -0
  214. package/dist/tests/env-writer.test.d.ts +2 -0
  215. package/dist/tests/env-writer.test.d.ts.map +1 -0
  216. package/dist/tests/env-writer.test.js +90 -0
  217. package/dist/tests/env-writer.test.js.map +1 -0
  218. package/dist/tests/profile-store.test.d.ts +2 -0
  219. package/dist/tests/profile-store.test.d.ts.map +1 -0
  220. package/dist/tests/profile-store.test.js +88 -0
  221. package/dist/tests/profile-store.test.js.map +1 -0
  222. package/dist/tests/target-guard.test.d.ts +2 -0
  223. package/dist/tests/target-guard.test.d.ts.map +1 -0
  224. package/dist/tests/target-guard.test.js +132 -0
  225. package/dist/tests/target-guard.test.js.map +1 -0
  226. package/dist/ui/logo.d.ts +2 -0
  227. package/dist/ui/logo.d.ts.map +1 -0
  228. package/dist/ui/logo.js +22 -0
  229. package/dist/ui/logo.js.map +1 -0
  230. package/package.json +17 -53
  231. package/.claude/settings.local.json +0 -36
  232. package/.cursor/rules.md +0 -203
  233. package/.eslintrc.js +0 -31
  234. package/CLAUDE.md +0 -100
  235. package/bin/cli.js +0 -116
  236. package/docs/ADDING_FRAMEWORK_DETECTORS.md +0 -391
  237. package/docs/ADDING_NEW_PROJECT_TYPE.md +0 -156
  238. package/docs/ARCHITECTURE_RELATIONSHIPS.md +0 -411
  239. package/docs/CLI_AUTHENTICATION.md +0 -214
  240. package/docs/CLI_PAGE_DETECTION_REQUIREMENTS.md +0 -519
  241. package/docs/CRM-PIPELINES-SEQUENCES-SPEC.md +0 -429
  242. package/docs/DETECTOR_ARCHITECTURE.md +0 -326
  243. package/docs/DEVELOPMENT.md +0 -194
  244. package/docs/IMPLEMENTATION_PHASES.md +0 -468
  245. package/docs/INTEGRATION_PATHS_ARCHITECTURE.md +0 -1543
  246. package/docs/OAUTH_CLARIFICATION.md +0 -258
  247. package/docs/OAUTH_SETUP_GUIDE_TEMPLATE.md +0 -211
  248. package/docs/PHASE_0_PROGRESS.md +0 -120
  249. package/docs/PHASE_1_COMPLETE.md +0 -366
  250. package/docs/PHASE_SUMMARY.md +0 -149
  251. package/docs/PLAN.md +0 -511
  252. package/docs/README.md +0 -56
  253. package/docs/STRIPE_INTEGRATION.md +0 -447
  254. package/docs/SUMMARY.md +0 -230
  255. package/docs/UPDATED_PLAN.md +0 -447
  256. package/docs/mcp_server/MCP_EXTENSION_GUIDE.md +0 -1313
  257. package/docs/mcp_server/MCP_SERVER_ARCHITECTURE.md +0 -1481
  258. package/docs/mcp_server/applicationOntology.ts +0 -817
  259. package/docs/mcp_server/cliApplications.ts +0 -639
  260. package/docs/mcp_server/crmOntology.ts +0 -1063
  261. package/docs/mcp_server/eventOntology.ts +0 -1183
  262. package/docs/mcp_server/formsOntology.ts +0 -1401
  263. package/docs/mcp_server/ontologySchemas.ts +0 -185
  264. package/docs/mcp_server/schema.ts +0 -250
  265. package/docs/microsass_production_machine/CLI_API_REFERENCE.md +0 -1197
  266. package/docs/microsass_production_machine/CLI_PRODUCT_VISION.md +0 -676
  267. package/docs/microsass_production_machine/CLI_REQUIREMENTS.md +0 -606
  268. package/docs/microsass_production_machine/CONNECTED_APPLICATIONS_SPEC.md +0 -390
  269. package/docs/microsass_production_machine/IMPLEMENTATION_ROADMAP.md +0 -725
  270. package/docs/microsass_production_machine/OBJECT_MAPPINGS.md +0 -808
  271. package/docs/microsass_production_machine/REFERENCE_IMPLEMENTATION.md +0 -532
  272. package/src/api/backend-client.js +0 -449
  273. package/src/commands/api-keys.js +0 -119
  274. package/src/commands/connect.js +0 -243
  275. package/src/commands/login.js +0 -332
  276. package/src/commands/logout.js +0 -30
  277. package/src/commands/mcp-server.js +0 -85
  278. package/src/commands/mcp-setup.js +0 -686
  279. package/src/commands/pages.js +0 -317
  280. package/src/commands/scaffold.js +0 -409
  281. package/src/commands/spread.js +0 -861
  282. package/src/commands/status.js +0 -62
  283. package/src/commands/sync.js +0 -169
  284. package/src/commands/upgrade.js +0 -48
  285. package/src/config/config-manager.js +0 -206
  286. package/src/detectors/api-client-detector.js +0 -85
  287. package/src/detectors/base-detector.js +0 -77
  288. package/src/detectors/database-detector.js +0 -245
  289. package/src/detectors/expo-detector.js +0 -166
  290. package/src/detectors/github-detector.js +0 -74
  291. package/src/detectors/index.js +0 -106
  292. package/src/detectors/mapping-suggestor.js +0 -119
  293. package/src/detectors/model-detector.js +0 -318
  294. package/src/detectors/nextjs-detector.js +0 -139
  295. package/src/detectors/oauth-detector.js +0 -122
  296. package/src/detectors/page-detector.js +0 -480
  297. package/src/detectors/registry.js +0 -121
  298. package/src/generators/api-client-generator.js +0 -223
  299. package/src/generators/api-only/client.js +0 -683
  300. package/src/generators/api-only/index.js +0 -96
  301. package/src/generators/api-only/types.js +0 -618
  302. package/src/generators/api-only/webhooks.js +0 -377
  303. package/src/generators/env-generator.js +0 -191
  304. package/src/generators/expo-auth-generator.js +0 -1009
  305. package/src/generators/gitignore-generator.js +0 -92
  306. package/src/generators/index.js +0 -166
  307. package/src/generators/manifest-generator.js +0 -154
  308. package/src/generators/mcp-guide-generator.js +0 -256
  309. package/src/generators/nextauth-generator.js +0 -247
  310. package/src/generators/oauth-guide-generator.js +0 -277
  311. package/src/generators/quickstart/components/index.js +0 -1699
  312. package/src/generators/quickstart/components-mobile/index.js +0 -1440
  313. package/src/generators/quickstart/database/convex.js +0 -1257
  314. package/src/generators/quickstart/database/index.js +0 -34
  315. package/src/generators/quickstart/database/supabase.js +0 -1132
  316. package/src/generators/quickstart/hooks/index.js +0 -1065
  317. package/src/generators/quickstart/index.js +0 -191
  318. package/src/generators/quickstart/pages/index.js +0 -1466
  319. package/src/generators/quickstart/screens/index.js +0 -1498
  320. package/src/logo.js +0 -116
  321. package/src/mcp/auth.js +0 -127
  322. package/src/mcp/registry/domains/applications.js +0 -516
  323. package/src/mcp/registry/domains/benefits.js +0 -798
  324. package/src/mcp/registry/domains/codegen.js +0 -894
  325. package/src/mcp/registry/domains/core.js +0 -324
  326. package/src/mcp/registry/domains/crm.js +0 -591
  327. package/src/mcp/registry/domains/events.js +0 -649
  328. package/src/mcp/registry/domains/forms.js +0 -696
  329. package/src/mcp/registry/index.js +0 -164
  330. package/src/mcp/server.js +0 -116
  331. package/src/utils/file-utils.js +0 -117
  332. package/src/utils/init-helpers.js +0 -243
  333. package/src/utils/prompt-utils.js +0 -195
  334. package/templates/CLAUDE.md +0 -86
  335. package/tests/api-client-detector.test.js +0 -214
  336. package/tests/api-client-generator.test.js +0 -176
  337. package/tests/backend-client.test.js +0 -640
  338. package/tests/base-detector.test.js +0 -101
  339. package/tests/commands/login.test.js +0 -143
  340. package/tests/commands/logout.test.js +0 -84
  341. package/tests/commands/status.test.js +0 -167
  342. package/tests/config-manager.test.js +0 -321
  343. package/tests/database-detector.test.js +0 -221
  344. package/tests/detector-index.test.js +0 -209
  345. package/tests/detector-registry.test.js +0 -93
  346. package/tests/env-generator.test.js +0 -278
  347. package/tests/expo-detector.test.js +0 -263
  348. package/tests/file-utils.test.js +0 -194
  349. package/tests/generators-index.test.js +0 -454
  350. package/tests/github-detector.test.js +0 -145
  351. package/tests/gitignore-generator.test.js +0 -109
  352. package/tests/logo.test.js +0 -96
  353. package/tests/nextauth-generator.test.js +0 -255
  354. package/tests/nextjs-detector.test.js +0 -235
  355. package/tests/oauth-detector.test.js +0 -264
  356. package/tests/oauth-guide-generator.test.js +0 -273
  357. package/tests/page-detector.test.js +0 -371
@@ -1,639 +0,0 @@
1
- /**
2
- * CLI APPLICATIONS API
3
- *
4
- * HTTP handlers for CLI application registration and management.
5
- * Uses CLI session token authentication (Bearer token).
6
- *
7
- * Endpoints:
8
- * - POST /api/v1/cli/applications - Register new application
9
- * - GET /api/v1/cli/applications - List all applications
10
- * - GET /api/v1/cli/applications/by-path?hash={hash} - Find by project path
11
- * - GET /api/v1/cli/applications/:id - Get application details
12
- * - PATCH /api/v1/cli/applications/:id - Update application
13
- */
14
-
15
- import { httpAction } from "../../_generated/server";
16
- import { internal } from "../../_generated/api";
17
- import { getCorsHeaders, handleOptionsRequest } from "./corsHeaders";
18
- import type { Id } from "../../_generated/dataModel";
19
-
20
- // ============================================================================
21
- // HELPER: Verify CLI Token
22
- // ============================================================================
23
-
24
- async function verifyCliToken(
25
- ctx: { runQuery: (fn: any, args: any) => Promise<any> },
26
- authHeader: string | null
27
- ): Promise<{
28
- userId: Id<"users">;
29
- email: string;
30
- organizationId: Id<"organizations">;
31
- } | null> {
32
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
33
- return null;
34
- }
35
-
36
- const token = authHeader.substring(7);
37
-
38
- // Validate CLI session
39
- const session = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.validateCliTokenInternal, {
40
- token,
41
- });
42
-
43
- return session;
44
- }
45
-
46
- // ============================================================================
47
- // POST /api/v1/cli/applications - Register Application
48
- // ============================================================================
49
-
50
- export const registerApplication = httpAction(async (ctx, request) => {
51
- const origin = request.headers.get("origin");
52
- const corsHeaders = getCorsHeaders(origin);
53
-
54
- try {
55
- // Verify CLI token
56
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
57
- if (!authContext) {
58
- return new Response(
59
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
60
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
61
- );
62
- }
63
-
64
- // Parse request body
65
- const body = await request.json();
66
- const {
67
- organizationId,
68
- name,
69
- description,
70
- source,
71
- connection,
72
- modelMappings,
73
- } = body;
74
-
75
- // Validate required fields
76
- if (!name || !source || !connection) {
77
- return new Response(
78
- JSON.stringify({ error: "Missing required fields: name, source, connection", code: "VALIDATION_ERROR" }),
79
- { status: 400, headers: { "Content-Type": "application/json", ...corsHeaders } }
80
- );
81
- }
82
-
83
- // Use provided organizationId or default from session
84
- const targetOrgId = organizationId || authContext.organizationId;
85
-
86
- // Verify user has access to the organization
87
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
88
- userId: authContext.userId,
89
- organizationId: targetOrgId,
90
- });
91
-
92
- if (!hasAccess) {
93
- return new Response(
94
- JSON.stringify({ error: "Not authorized to access this organization", code: "UNAUTHORIZED" }),
95
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
96
- );
97
- }
98
-
99
- // Register application
100
- const result = await ctx.runMutation(internal.applicationOntology.registerApplicationInternal, {
101
- organizationId: targetOrgId,
102
- name,
103
- description,
104
- source: {
105
- type: source.type || "cli",
106
- projectPathHash: source.projectPathHash,
107
- cliVersion: source.cliVersion,
108
- framework: source.framework,
109
- frameworkVersion: source.frameworkVersion,
110
- hasTypeScript: source.hasTypeScript,
111
- routerType: source.routerType,
112
- },
113
- connection: {
114
- features: connection.features || [],
115
- hasFrontendDatabase: connection.hasFrontendDatabase,
116
- frontendDatabaseType: connection.frontendDatabaseType,
117
- },
118
- modelMappings: modelMappings?.map((m: any) => ({
119
- localModel: m.localModel,
120
- layerCakeType: m.layerCakeType,
121
- syncDirection: m.syncDirection || "none",
122
- confidence: m.confidence || 0,
123
- isAutoDetected: m.isAutoDetected || false,
124
- })),
125
- });
126
-
127
- // If this was an existing application, return 200 with existing flag
128
- if (result.existingApplication) {
129
- return new Response(
130
- JSON.stringify({
131
- success: true,
132
- applicationId: result.applicationId,
133
- existingApplication: true,
134
- message: "Application already registered for this project",
135
- }),
136
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
137
- );
138
- }
139
-
140
- // Generate API key for the new application
141
- const apiKeyResult = await ctx.runAction(internal.api.v1.cliAuth.generateCliApiKeyInternal, {
142
- organizationId: targetOrgId,
143
- userId: authContext.userId,
144
- name: `${name} API Key`,
145
- scopes: ["*"],
146
- });
147
-
148
- // Link API key to application
149
- await ctx.runMutation(internal.api.v1.cliApplicationsInternal.linkApiKeyToApplication, {
150
- applicationId: result.applicationId,
151
- apiKeyId: apiKeyResult.id,
152
- });
153
-
154
- return new Response(
155
- JSON.stringify({
156
- success: true,
157
- applicationId: result.applicationId,
158
- existingApplication: false,
159
- apiKey: {
160
- id: apiKeyResult.id,
161
- key: apiKeyResult.key,
162
- prefix: apiKeyResult.key.substring(0, 12) + "...",
163
- },
164
- backendUrl: result.backendUrl,
165
- }),
166
- { status: 201, headers: { "Content-Type": "application/json", ...corsHeaders } }
167
- );
168
- } catch (error) {
169
- console.error("[CLI Applications] Register error:", error);
170
- return new Response(
171
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
172
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
173
- );
174
- }
175
- });
176
-
177
- // ============================================================================
178
- // GET /api/v1/cli/applications - List Applications
179
- // ============================================================================
180
-
181
- export const listApplications = httpAction(async (ctx, request) => {
182
- const origin = request.headers.get("origin");
183
- const corsHeaders = getCorsHeaders(origin);
184
-
185
- try {
186
- // Verify CLI token
187
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
188
- if (!authContext) {
189
- return new Response(
190
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
191
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
192
- );
193
- }
194
-
195
- // Parse query params
196
- const url = new URL(request.url);
197
- const organizationId = url.searchParams.get("organizationId") || authContext.organizationId;
198
- const status = url.searchParams.get("status") || undefined;
199
- const limit = Math.min(parseInt(url.searchParams.get("limit") || "50"), 100);
200
- const offset = parseInt(url.searchParams.get("offset") || "0");
201
-
202
- // Verify user has access to the organization
203
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
204
- userId: authContext.userId,
205
- organizationId: organizationId as Id<"organizations">,
206
- });
207
-
208
- if (!hasAccess) {
209
- return new Response(
210
- JSON.stringify({ error: "Not authorized to access this organization", code: "UNAUTHORIZED" }),
211
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
212
- );
213
- }
214
-
215
- // List applications
216
- const result = await ctx.runQuery(internal.applicationOntology.listApplicationsInternal, {
217
- organizationId: organizationId as Id<"organizations">,
218
- status,
219
- limit,
220
- offset,
221
- });
222
-
223
- return new Response(
224
- JSON.stringify({
225
- success: true,
226
- applications: result.applications.map((app: any) => ({
227
- id: app._id,
228
- name: app.name,
229
- description: app.description,
230
- status: app.status,
231
- framework: app.customProperties?.source?.framework,
232
- features: app.customProperties?.connection?.features || [],
233
- registeredAt: app.customProperties?.cli?.registeredAt,
234
- lastActivityAt: app.customProperties?.cli?.lastActivityAt,
235
- })),
236
- total: result.total,
237
- hasMore: result.hasMore,
238
- }),
239
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
240
- );
241
- } catch (error) {
242
- console.error("[CLI Applications] List error:", error);
243
- return new Response(
244
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
245
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
246
- );
247
- }
248
- });
249
-
250
- // ============================================================================
251
- // GET /api/v1/cli/applications/by-path - Find by Path Hash
252
- // ============================================================================
253
-
254
- export const getApplicationByPath = httpAction(async (ctx, request) => {
255
- const origin = request.headers.get("origin");
256
- const corsHeaders = getCorsHeaders(origin);
257
-
258
- try {
259
- // Verify CLI token
260
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
261
- if (!authContext) {
262
- return new Response(
263
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
264
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
265
- );
266
- }
267
-
268
- // Parse query params
269
- const url = new URL(request.url);
270
- const hash = url.searchParams.get("hash");
271
- const organizationId = url.searchParams.get("organizationId") || authContext.organizationId;
272
-
273
- if (!hash) {
274
- return new Response(
275
- JSON.stringify({ error: "Missing required parameter: hash", code: "VALIDATION_ERROR" }),
276
- { status: 400, headers: { "Content-Type": "application/json", ...corsHeaders } }
277
- );
278
- }
279
-
280
- // Verify user has access to the organization
281
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
282
- userId: authContext.userId,
283
- organizationId: organizationId as Id<"organizations">,
284
- });
285
-
286
- if (!hasAccess) {
287
- return new Response(
288
- JSON.stringify({ error: "Not authorized to access this organization", code: "UNAUTHORIZED" }),
289
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
290
- );
291
- }
292
-
293
- // Find application
294
- const app = await ctx.runQuery(internal.applicationOntology.getApplicationByPathHashInternal, {
295
- organizationId: organizationId as Id<"organizations">,
296
- projectPathHash: hash,
297
- });
298
-
299
- if (!app) {
300
- return new Response(
301
- JSON.stringify({ found: false }),
302
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
303
- );
304
- }
305
-
306
- return new Response(
307
- JSON.stringify({
308
- found: true,
309
- application: app,
310
- }),
311
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
312
- );
313
- } catch (error) {
314
- console.error("[CLI Applications] Get by path error:", error);
315
- return new Response(
316
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
317
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
318
- );
319
- }
320
- });
321
-
322
- // ============================================================================
323
- // GET /api/v1/cli/applications/:id - Get Application Details
324
- // ============================================================================
325
-
326
- export const getApplication = httpAction(async (ctx, request) => {
327
- const origin = request.headers.get("origin");
328
- const corsHeaders = getCorsHeaders(origin);
329
-
330
- try {
331
- // Verify CLI token
332
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
333
- if (!authContext) {
334
- return new Response(
335
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
336
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
337
- );
338
- }
339
-
340
- // Extract application ID from URL
341
- const url = new URL(request.url);
342
- const pathParts = url.pathname.split("/");
343
- const applicationId = pathParts[pathParts.length - 1];
344
-
345
- // Skip handling for special paths that should be handled by other routes
346
- if (!applicationId || applicationId === "by-path" || applicationId === "applications") {
347
- return new Response(
348
- JSON.stringify({ error: "Application ID required", code: "VALIDATION_ERROR" }),
349
- { status: 400, headers: { "Content-Type": "application/json", ...corsHeaders } }
350
- );
351
- }
352
-
353
- // Get application
354
- const app = await ctx.runQuery(internal.applicationOntology.getApplicationInternal, {
355
- applicationId: applicationId as Id<"objects">,
356
- organizationId: authContext.organizationId,
357
- });
358
-
359
- if (!app) {
360
- return new Response(
361
- JSON.stringify({ error: "Application not found", code: "NOT_FOUND" }),
362
- { status: 404, headers: { "Content-Type": "application/json", ...corsHeaders } }
363
- );
364
- }
365
-
366
- // Verify user has access to the application's organization
367
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
368
- userId: authContext.userId,
369
- organizationId: app.organizationId,
370
- });
371
-
372
- if (!hasAccess) {
373
- return new Response(
374
- JSON.stringify({ error: "Not authorized to access this application", code: "UNAUTHORIZED" }),
375
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
376
- );
377
- }
378
-
379
- const props = app.customProperties as any;
380
-
381
- return new Response(
382
- JSON.stringify({
383
- success: true,
384
- application: {
385
- id: app._id,
386
- name: app.name,
387
- description: app.description,
388
- status: app.status,
389
- source: props?.source,
390
- connection: {
391
- ...props?.connection,
392
- apiKeyPrefix: props?.connection?.apiKeyId ? "***" : undefined,
393
- },
394
- modelMappings: props?.modelMappings,
395
- deployment: props?.deployment,
396
- sync: props?.sync,
397
- cli: props?.cli,
398
- createdAt: app.createdAt,
399
- updatedAt: app.updatedAt,
400
- },
401
- }),
402
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
403
- );
404
- } catch (error) {
405
- console.error("[CLI Applications] Get error:", error);
406
- return new Response(
407
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
408
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
409
- );
410
- }
411
- });
412
-
413
- // ============================================================================
414
- // PATCH /api/v1/cli/applications/:id - Update Application
415
- // ============================================================================
416
-
417
- export const updateApplication = httpAction(async (ctx, request) => {
418
- const origin = request.headers.get("origin");
419
- const corsHeaders = getCorsHeaders(origin);
420
-
421
- try {
422
- // Verify CLI token
423
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
424
- if (!authContext) {
425
- return new Response(
426
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
427
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
428
- );
429
- }
430
-
431
- // Extract application ID from URL
432
- const url = new URL(request.url);
433
- const pathParts = url.pathname.split("/");
434
- const applicationId = pathParts[pathParts.length - 1];
435
-
436
- if (!applicationId) {
437
- return new Response(
438
- JSON.stringify({ error: "Application ID required", code: "VALIDATION_ERROR" }),
439
- { status: 400, headers: { "Content-Type": "application/json", ...corsHeaders } }
440
- );
441
- }
442
-
443
- // Get application to verify ownership
444
- const app = await ctx.runQuery(internal.applicationOntology.getApplicationInternal, {
445
- applicationId: applicationId as Id<"objects">,
446
- organizationId: authContext.organizationId,
447
- });
448
-
449
- if (!app) {
450
- return new Response(
451
- JSON.stringify({ error: "Application not found", code: "NOT_FOUND" }),
452
- { status: 404, headers: { "Content-Type": "application/json", ...corsHeaders } }
453
- );
454
- }
455
-
456
- // Verify user has access
457
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
458
- userId: authContext.userId,
459
- organizationId: app.organizationId,
460
- });
461
-
462
- if (!hasAccess) {
463
- return new Response(
464
- JSON.stringify({ error: "Not authorized to update this application", code: "UNAUTHORIZED" }),
465
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
466
- );
467
- }
468
-
469
- // Parse request body
470
- const body = await request.json();
471
-
472
- // Update application
473
- await ctx.runMutation(internal.applicationOntology.updateApplicationInternal, {
474
- applicationId: applicationId as Id<"objects">,
475
- organizationId: app.organizationId,
476
- name: body.name,
477
- description: body.description,
478
- status: body.status,
479
- connection: body.connection,
480
- deployment: body.deployment,
481
- modelMappings: body.modelMappings,
482
- });
483
-
484
- return new Response(
485
- JSON.stringify({ success: true }),
486
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
487
- );
488
- } catch (error) {
489
- console.error("[CLI Applications] Update error:", error);
490
- return new Response(
491
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
492
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
493
- );
494
- }
495
- });
496
-
497
- // ============================================================================
498
- // POST /api/v1/cli/applications/:id/sync - Sync Application
499
- // ============================================================================
500
-
501
- export const syncApplication = httpAction(async (ctx, request) => {
502
- const origin = request.headers.get("origin");
503
- const corsHeaders = getCorsHeaders(origin);
504
-
505
- try {
506
- // Verify CLI token
507
- const authContext = await verifyCliToken(ctx, request.headers.get("Authorization"));
508
- if (!authContext) {
509
- return new Response(
510
- JSON.stringify({ error: "Invalid or expired CLI session", code: "INVALID_SESSION" }),
511
- { status: 401, headers: { "Content-Type": "application/json", ...corsHeaders } }
512
- );
513
- }
514
-
515
- // Extract application ID from URL
516
- const url = new URL(request.url);
517
- const pathParts = url.pathname.split("/");
518
- // URL: /api/v1/cli/applications/:id/sync
519
- const syncIndex = pathParts.indexOf("sync");
520
- const applicationId = syncIndex > 0 ? pathParts[syncIndex - 1] : null;
521
-
522
- if (!applicationId) {
523
- return new Response(
524
- JSON.stringify({ error: "Application ID required", code: "VALIDATION_ERROR" }),
525
- { status: 400, headers: { "Content-Type": "application/json", ...corsHeaders } }
526
- );
527
- }
528
-
529
- // Get application to verify ownership
530
- const app = await ctx.runQuery(internal.applicationOntology.getApplicationInternal, {
531
- applicationId: applicationId as Id<"objects">,
532
- organizationId: authContext.organizationId,
533
- });
534
-
535
- if (!app) {
536
- return new Response(
537
- JSON.stringify({ error: "Application not found", code: "NOT_FOUND" }),
538
- { status: 404, headers: { "Content-Type": "application/json", ...corsHeaders } }
539
- );
540
- }
541
-
542
- // Verify user has access
543
- const hasAccess = await ctx.runQuery(internal.api.v1.cliApplicationsInternal.checkOrgAccessInternal, {
544
- userId: authContext.userId,
545
- organizationId: app.organizationId,
546
- });
547
-
548
- if (!hasAccess) {
549
- return new Response(
550
- JSON.stringify({ error: "Not authorized to sync this application", code: "UNAUTHORIZED" }),
551
- { status: 403, headers: { "Content-Type": "application/json", ...corsHeaders } }
552
- );
553
- }
554
-
555
- // Parse request body
556
- const body = await request.json();
557
- const {
558
- direction = "bidirectional",
559
- models,
560
- dryRun = false,
561
- // Sync results (if CLI is reporting completed sync)
562
- results,
563
- } = body;
564
-
565
- // If CLI is reporting sync results
566
- if (results) {
567
- // Record sync event
568
- await ctx.runMutation(internal.api.v1.cliApplicationsInternal.recordSyncEvent, {
569
- applicationId: applicationId as Id<"objects">,
570
- direction: results.direction || direction,
571
- status: results.status || "success",
572
- recordsProcessed: results.recordsProcessed || 0,
573
- recordsCreated: results.recordsCreated || 0,
574
- recordsUpdated: results.recordsUpdated || 0,
575
- errors: results.errors || 0,
576
- });
577
-
578
- return new Response(
579
- JSON.stringify({
580
- success: true,
581
- message: "Sync results recorded",
582
- syncId: `sync_${Date.now()}`,
583
- }),
584
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
585
- );
586
- }
587
-
588
- // Otherwise, this is a sync request - return what should be synced
589
- // For now, return sync configuration (CLI will execute the actual sync)
590
- const props = app.customProperties as any;
591
- const modelMappings = props?.modelMappings || [];
592
- const features = props?.connection?.features || [];
593
-
594
- // Filter mappings by requested models if specified
595
- const filteredMappings = models
596
- ? modelMappings.filter((m: any) => models.includes(m.localModel))
597
- : modelMappings;
598
-
599
- return new Response(
600
- JSON.stringify({
601
- success: true,
602
- syncId: `sync_${Date.now()}`,
603
- dryRun,
604
- direction,
605
- application: {
606
- id: app._id,
607
- name: app.name,
608
- features,
609
- },
610
- modelMappings: filteredMappings,
611
- // Sync instructions for CLI
612
- instructions: {
613
- backendUrl: props?.connection?.backendUrl,
614
- endpoints: features.map((feature: string) => ({
615
- feature,
616
- push: `/api/v1/${feature}/bulk`,
617
- pull: `/api/v1/${feature}`,
618
- })),
619
- },
620
- }),
621
- { status: 200, headers: { "Content-Type": "application/json", ...corsHeaders } }
622
- );
623
- } catch (error) {
624
- console.error("[CLI Applications] Sync error:", error);
625
- return new Response(
626
- JSON.stringify({ error: "Internal server error", code: "INTERNAL_ERROR" }),
627
- { status: 500, headers: { "Content-Type": "application/json", ...corsHeaders } }
628
- );
629
- }
630
- });
631
-
632
- // ============================================================================
633
- // OPTIONS Handler (CORS)
634
- // ============================================================================
635
-
636
- export const handleOptions = httpAction(async (ctx, request) => {
637
- const origin = request.headers.get("origin");
638
- return handleOptionsRequest(origin);
639
- });