@seamapi/cli 0.18.1 → 0.19.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 (364) hide show
  1. package/README.md +55 -1
  2. package/bin/cli.js +73 -249
  3. package/bin/cli.js.map +1 -1
  4. package/lib/args/coerce.d.ts +28 -0
  5. package/lib/args/coerce.js +131 -0
  6. package/lib/args/coerce.js.map +1 -0
  7. package/lib/{util/cli-args.d.ts → args/parse.d.ts} +12 -15
  8. package/lib/{util/cli-args.js → args/parse.js} +21 -24
  9. package/lib/args/parse.js.map +1 -0
  10. package/lib/args/validate.d.ts +23 -0
  11. package/lib/args/validate.js +42 -0
  12. package/lib/args/validate.js.map +1 -0
  13. package/lib/auth/operations.d.ts +54 -0
  14. package/lib/auth/operations.js +115 -0
  15. package/lib/auth/operations.js.map +1 -0
  16. package/lib/{validate-token.js → auth/validate-token.js} +2 -2
  17. package/lib/auth/validate-token.js.map +1 -0
  18. package/lib/blueprint/cache.d.ts +16 -0
  19. package/lib/blueprint/cache.js +73 -0
  20. package/lib/blueprint/cache.js.map +1 -0
  21. package/lib/blueprint/endpoint.d.ts +14 -0
  22. package/lib/{get-response-key.js → blueprint/endpoint.js} +11 -2
  23. package/lib/blueprint/endpoint.js.map +1 -0
  24. package/lib/blueprint/index.d.ts +12 -0
  25. package/lib/blueprint/index.js +10 -0
  26. package/lib/blueprint/index.js.map +1 -0
  27. package/lib/blueprint/source-npm.d.ts +10 -0
  28. package/lib/{blueprint.js → blueprint/source-npm.js} +20 -74
  29. package/lib/blueprint/source-npm.js.map +1 -0
  30. package/lib/blueprint/source-remote.d.ts +6 -0
  31. package/lib/blueprint/source-remote.js +14 -0
  32. package/lib/blueprint/source-remote.js.map +1 -0
  33. package/lib/commands/api-command.d.ts +8 -0
  34. package/lib/commands/api-command.js +71 -0
  35. package/lib/commands/api-command.js.map +1 -0
  36. package/lib/commands/local/completion.d.ts +18 -0
  37. package/lib/commands/local/completion.js +35 -0
  38. package/lib/commands/local/completion.js.map +1 -0
  39. package/lib/commands/local/config-reveal-location.d.ts +2 -0
  40. package/lib/commands/local/config-reveal-location.js +15 -0
  41. package/lib/commands/local/config-reveal-location.js.map +1 -0
  42. package/lib/commands/local/config-set-fake-server.d.ts +3 -0
  43. package/lib/commands/local/config-set-fake-server.js +20 -0
  44. package/lib/commands/local/config-set-fake-server.js.map +1 -0
  45. package/lib/commands/local/config-use-remote-api-defs.d.ts +2 -0
  46. package/lib/commands/local/config-use-remote-api-defs.js +20 -0
  47. package/lib/commands/local/config-use-remote-api-defs.js.map +1 -0
  48. package/lib/commands/local/health.d.ts +2 -0
  49. package/lib/commands/local/health.js +18 -0
  50. package/lib/commands/local/health.js.map +1 -0
  51. package/lib/commands/local/login.d.ts +2 -0
  52. package/lib/commands/local/login.js +35 -0
  53. package/lib/commands/local/login.js.map +1 -0
  54. package/lib/commands/local/logout.d.ts +2 -0
  55. package/lib/commands/local/logout.js +17 -0
  56. package/lib/commands/local/logout.js.map +1 -0
  57. package/lib/commands/local/select-server.d.ts +2 -0
  58. package/lib/commands/local/select-server.js +27 -0
  59. package/lib/commands/local/select-server.js.map +1 -0
  60. package/lib/commands/local/select-workspace.d.ts +2 -0
  61. package/lib/commands/local/select-workspace.js +22 -0
  62. package/lib/commands/local/select-workspace.js.map +1 -0
  63. package/lib/commands/local/wizard.d.ts +9 -0
  64. package/lib/commands/local/wizard.js +28 -0
  65. package/lib/commands/local/wizard.js.map +1 -0
  66. package/lib/commands/registry.d.ts +54 -0
  67. package/lib/commands/registry.js +64 -0
  68. package/lib/commands/registry.js.map +1 -0
  69. package/lib/{command-spec.d.ts → commands/spec.d.ts} +8 -12
  70. package/lib/{command-spec.js → commands/spec.js} +27 -120
  71. package/lib/commands/spec.js.map +1 -0
  72. package/lib/config/config-store.d.ts +23 -8
  73. package/lib/config/config-store.js +16 -42
  74. package/lib/config/config-store.js.map +1 -1
  75. package/lib/config/index.d.ts +2 -1
  76. package/lib/config/index.js +2 -1
  77. package/lib/config/index.js.map +1 -1
  78. package/lib/config/memory-config-store.d.ts +21 -0
  79. package/lib/config/memory-config-store.js +48 -0
  80. package/lib/config/memory-config-store.js.map +1 -0
  81. package/lib/config/migrate.js +1 -1
  82. package/lib/config/migrate.js.map +1 -1
  83. package/lib/config/values.d.ts +12 -0
  84. package/lib/config/values.js +50 -0
  85. package/lib/config/values.js.map +1 -0
  86. package/lib/context.d.ts +37 -0
  87. package/lib/context.js +31 -0
  88. package/lib/context.js.map +1 -0
  89. package/lib/env.d.ts +5 -0
  90. package/lib/env.js +5 -0
  91. package/lib/env.js.map +1 -1
  92. package/lib/errors.d.ts +31 -0
  93. package/lib/errors.js +58 -0
  94. package/lib/errors.js.map +1 -0
  95. package/lib/http/api.d.ts +37 -0
  96. package/lib/http/api.js +20 -0
  97. package/lib/http/api.js.map +1 -0
  98. package/lib/http/client.d.ts +4 -0
  99. package/lib/{get-seam.js → http/client.js} +16 -17
  100. package/lib/http/client.js.map +1 -0
  101. package/lib/http/follow-ups.d.ts +6 -0
  102. package/lib/http/follow-ups.js +30 -0
  103. package/lib/http/follow-ups.js.map +1 -0
  104. package/lib/http/memory-seam-api.d.ts +22 -0
  105. package/lib/http/memory-seam-api.js +41 -0
  106. package/lib/http/memory-seam-api.js.map +1 -0
  107. package/lib/http/request.d.ts +19 -0
  108. package/lib/http/request.js +39 -0
  109. package/lib/http/request.js.map +1 -0
  110. package/lib/{interact-for-access-code.js → interactions/access-code.js} +4 -4
  111. package/lib/interactions/access-code.js.map +1 -0
  112. package/lib/{interact-for-acs-entrance.js → interactions/acs-entrance.js} +3 -3
  113. package/lib/interactions/acs-entrance.js.map +1 -0
  114. package/lib/{interact-for-acs-system.js → interactions/acs-system.js} +3 -3
  115. package/lib/interactions/acs-system.js.map +1 -0
  116. package/lib/{interact-for-acs-user.js → interactions/acs-user.js} +4 -4
  117. package/lib/interactions/acs-user.js.map +1 -0
  118. package/lib/{interact-for-action-attempt-poll.js → interactions/action-attempt-poll.js} +5 -5
  119. package/lib/interactions/action-attempt-poll.js.map +1 -0
  120. package/lib/{interact-for-array.js → interactions/array.js} +4 -3
  121. package/lib/interactions/array.js.map +1 -0
  122. package/lib/{interact-for-blueprint-object.d.ts → interactions/blueprint-object.d.ts} +3 -2
  123. package/lib/{interact-for-blueprint-object.js → interactions/blueprint-object.js} +49 -20
  124. package/lib/interactions/blueprint-object.js.map +1 -0
  125. package/lib/{interact-for-command-params.d.ts → interactions/command-params.d.ts} +2 -2
  126. package/lib/{interact-for-command-params.js → interactions/command-params.js} +4 -3
  127. package/lib/interactions/command-params.js.map +1 -0
  128. package/lib/interactions/command-selection.d.ts +10 -0
  129. package/lib/{interact-for-command-selection.js → interactions/command-selection.js} +9 -15
  130. package/lib/interactions/command-selection.js.map +1 -0
  131. package/lib/{interact-for-connected-account.js → interactions/connected-account.js} +3 -3
  132. package/lib/interactions/connected-account.js.map +1 -0
  133. package/lib/{interact-for-custom-metadata.js → interactions/custom-metadata.js} +4 -3
  134. package/lib/interactions/custom-metadata.js.map +1 -0
  135. package/lib/{interact-for-device.js → interactions/device.js} +3 -3
  136. package/lib/interactions/device.js.map +1 -0
  137. package/lib/interactions/index.d.ts +19 -0
  138. package/lib/interactions/index.js +20 -0
  139. package/lib/interactions/index.js.map +1 -0
  140. package/lib/{interact-for-login.js → interactions/login.js} +16 -14
  141. package/lib/interactions/login.js.map +1 -0
  142. package/lib/{interact-for-resource.js → interactions/resource.js} +3 -3
  143. package/lib/interactions/resource.js.map +1 -0
  144. package/lib/{interact-for-server-selection.js → interactions/server-selection.js} +10 -13
  145. package/lib/interactions/server-selection.js.map +1 -0
  146. package/lib/{interact-for-timestamp.js → interactions/timestamp.js} +2 -2
  147. package/lib/interactions/timestamp.js.map +1 -0
  148. package/lib/{interact-for-use-remote-api-defs.js → interactions/use-remote-api-defs.js} +5 -6
  149. package/lib/interactions/use-remote-api-defs.js.map +1 -0
  150. package/lib/{interact-for-user-identity.js → interactions/user-identity.js} +3 -3
  151. package/lib/interactions/user-identity.js.map +1 -0
  152. package/lib/{interact-for-workspace-id.js → interactions/workspace-id.js} +11 -10
  153. package/lib/interactions/workspace-id.js.map +1 -0
  154. package/lib/memory-prompt.d.ts +32 -0
  155. package/lib/memory-prompt.js +41 -0
  156. package/lib/memory-prompt.js.map +1 -0
  157. package/lib/output/get-output.d.ts +1 -1
  158. package/lib/output/get-output.js +1 -1
  159. package/lib/output/get-output.js.map +1 -1
  160. package/lib/output/{create-memory-output.d.ts → memory-output.d.ts} +1 -1
  161. package/lib/output/{create-memory-output.js → memory-output.js} +2 -2
  162. package/lib/output/memory-output.js.map +1 -0
  163. package/lib/output/{create-output.d.ts → output.d.ts} +18 -1
  164. package/lib/output/output.js +46 -0
  165. package/lib/output/output.js.map +1 -0
  166. package/lib/output/read-stdin-json.js.map +1 -0
  167. package/lib/output/resolve-output-format.d.ts +1 -1
  168. package/lib/{util → output}/with-loading.js +1 -1
  169. package/lib/output/with-loading.js.map +1 -0
  170. package/lib/prompt.d.ts +101 -0
  171. package/lib/{util/prompt.js → prompt.js} +83 -56
  172. package/lib/prompt.js.map +1 -0
  173. package/lib/{completion → render/completion}/describe.js +1 -2
  174. package/lib/render/completion/describe.js.map +1 -0
  175. package/lib/{completion → render/completion}/index.d.ts +2 -2
  176. package/lib/{completion → render/completion}/index.js +1 -2
  177. package/lib/render/completion/index.js.map +1 -0
  178. package/lib/{completion → render/completion}/render-bash.d.ts +1 -1
  179. package/lib/{completion → render/completion}/render-bash.js +1 -1
  180. package/lib/render/completion/render-bash.js.map +1 -0
  181. package/lib/{completion → render/completion}/render-fish.d.ts +1 -1
  182. package/lib/render/completion/render-fish.js.map +1 -0
  183. package/lib/{completion → render/completion}/render-zsh.d.ts +1 -1
  184. package/lib/{completion → render/completion}/render-zsh.js +1 -1
  185. package/lib/render/completion/render-zsh.js.map +1 -0
  186. package/lib/{render-help.d.ts → render/help.d.ts} +1 -1
  187. package/lib/{render-help.js → render/help.js} +2 -2
  188. package/lib/render/help.js.map +1 -0
  189. package/lib/render/text.d.ts +4 -0
  190. package/lib/render/text.js +16 -0
  191. package/lib/render/text.js.map +1 -0
  192. package/lib/version.d.ts +2 -2
  193. package/lib/version.js +2 -2
  194. package/package.json +4 -3
  195. package/src/bin/cli.ts +91 -332
  196. package/src/lib/args/coerce.ts +164 -0
  197. package/src/lib/{util/cli-args.ts → args/parse.ts} +30 -25
  198. package/src/lib/args/validate.ts +73 -0
  199. package/src/lib/auth/operations.ts +169 -0
  200. package/src/lib/{validate-token.ts → auth/validate-token.ts} +2 -2
  201. package/src/lib/blueprint/cache.ts +97 -0
  202. package/src/lib/{get-response-key.ts → blueprint/endpoint.ts} +17 -3
  203. package/src/lib/blueprint/index.ts +27 -0
  204. package/src/lib/{blueprint.ts → blueprint/source-npm.ts} +27 -99
  205. package/src/lib/blueprint/source-remote.ts +17 -0
  206. package/src/lib/commands/api-command.ts +109 -0
  207. package/src/lib/commands/local/completion.ts +51 -0
  208. package/src/lib/commands/local/config-reveal-location.ts +16 -0
  209. package/src/lib/commands/local/config-set-fake-server.ts +21 -0
  210. package/src/lib/commands/local/config-use-remote-api-defs.ts +23 -0
  211. package/src/lib/commands/local/health.ts +22 -0
  212. package/src/lib/commands/local/login.ts +42 -0
  213. package/src/lib/commands/local/logout.ts +18 -0
  214. package/src/lib/commands/local/select-server.ts +30 -0
  215. package/src/lib/commands/local/select-workspace.ts +25 -0
  216. package/src/lib/commands/local/wizard.ts +31 -0
  217. package/src/lib/commands/registry.ts +127 -0
  218. package/src/lib/{command-spec.ts → commands/spec.ts} +30 -131
  219. package/src/lib/config/config-store.ts +39 -64
  220. package/src/lib/config/index.ts +8 -1
  221. package/src/lib/config/memory-config-store.ts +62 -0
  222. package/src/lib/config/migrate.ts +1 -1
  223. package/src/lib/config/values.ts +72 -0
  224. package/src/lib/context.ts +84 -0
  225. package/src/lib/env.ts +9 -2
  226. package/src/lib/errors.ts +67 -0
  227. package/src/lib/http/api.ts +61 -0
  228. package/src/lib/{get-seam.ts → http/client.ts} +19 -18
  229. package/src/lib/http/follow-ups.ts +42 -0
  230. package/src/lib/http/memory-seam-api.ts +57 -0
  231. package/src/lib/http/request.ts +69 -0
  232. package/src/lib/{interact-for-access-code.ts → interactions/access-code.ts} +4 -3
  233. package/src/lib/{interact-for-acs-entrance.ts → interactions/acs-entrance.ts} +3 -2
  234. package/src/lib/{interact-for-acs-system.ts → interactions/acs-system.ts} +3 -2
  235. package/src/lib/{interact-for-acs-user.ts → interactions/acs-user.ts} +4 -3
  236. package/src/lib/{interact-for-action-attempt-poll.ts → interactions/action-attempt-poll.ts} +4 -4
  237. package/src/lib/{interact-for-array.ts → interactions/array.ts} +3 -3
  238. package/src/lib/{interact-for-blueprint-object.ts → interactions/blueprint-object.ts} +57 -24
  239. package/src/lib/{interact-for-command-params.ts → interactions/command-params.ts} +6 -4
  240. package/src/lib/{interact-for-command-selection.ts → interactions/command-selection.ts} +11 -23
  241. package/src/lib/{interact-for-connected-account.ts → interactions/connected-account.ts} +3 -2
  242. package/src/lib/{interact-for-custom-metadata.ts → interactions/custom-metadata.ts} +3 -7
  243. package/src/lib/{interact-for-device.ts → interactions/device.ts} +3 -2
  244. package/src/lib/interactions/index.ts +19 -0
  245. package/src/lib/{interact-for-login.ts → interactions/login.ts} +16 -13
  246. package/src/lib/{interact-for-resource.ts → interactions/resource.ts} +2 -2
  247. package/src/lib/{interact-for-server-selection.ts → interactions/server-selection.ts} +12 -17
  248. package/src/lib/{interact-for-timestamp.ts → interactions/timestamp.ts} +1 -1
  249. package/src/lib/{interact-for-use-remote-api-defs.ts → interactions/use-remote-api-defs.ts} +4 -5
  250. package/src/lib/{interact-for-user-identity.ts → interactions/user-identity.ts} +3 -2
  251. package/src/lib/{interact-for-workspace-id.ts → interactions/workspace-id.ts} +10 -17
  252. package/src/lib/memory-prompt.ts +89 -0
  253. package/src/lib/output/get-output.ts +1 -1
  254. package/src/lib/output/{create-memory-output.ts → memory-output.ts} +1 -1
  255. package/src/lib/output/{create-output.ts → output.ts} +47 -32
  256. package/src/lib/output/resolve-output-format.ts +1 -1
  257. package/src/lib/{util → output}/with-loading.ts +1 -1
  258. package/src/lib/prompt.ts +306 -0
  259. package/src/lib/{completion → render/completion}/describe.ts +1 -2
  260. package/src/lib/{completion → render/completion}/index.ts +3 -4
  261. package/src/lib/{completion → render/completion}/render-bash.ts +1 -1
  262. package/src/lib/{completion → render/completion}/render-fish.ts +2 -1
  263. package/src/lib/{completion → render/completion}/render-zsh.ts +2 -1
  264. package/src/lib/{render-help.ts → render/help.ts} +1 -1
  265. package/src/lib/render/text.ts +17 -0
  266. package/src/lib/version.ts +2 -2
  267. package/lib/blueprint.d.ts +0 -7
  268. package/lib/blueprint.js.map +0 -1
  269. package/lib/command-spec.js.map +0 -1
  270. package/lib/completion/describe.js.map +0 -1
  271. package/lib/completion/index.js.map +0 -1
  272. package/lib/completion/render-bash.js.map +0 -1
  273. package/lib/completion/render-fish.js.map +0 -1
  274. package/lib/completion/render-zsh.js.map +0 -1
  275. package/lib/get-api-blueprint.d.ts +0 -6
  276. package/lib/get-api-blueprint.js +0 -18
  277. package/lib/get-api-blueprint.js.map +0 -1
  278. package/lib/get-command-blueprint-def.d.ts +0 -2
  279. package/lib/get-command-blueprint-def.js +0 -11
  280. package/lib/get-command-blueprint-def.js.map +0 -1
  281. package/lib/get-credentials.d.ts +0 -15
  282. package/lib/get-credentials.js +0 -35
  283. package/lib/get-credentials.js.map +0 -1
  284. package/lib/get-current-workspace-id.d.ts +0 -1
  285. package/lib/get-current-workspace-id.js +0 -9
  286. package/lib/get-current-workspace-id.js.map +0 -1
  287. package/lib/get-response-key.d.ts +0 -9
  288. package/lib/get-response-key.js.map +0 -1
  289. package/lib/get-seam.d.ts +0 -3
  290. package/lib/get-seam.js.map +0 -1
  291. package/lib/get-server.d.ts +0 -6
  292. package/lib/get-server.js +0 -17
  293. package/lib/get-server.js.map +0 -1
  294. package/lib/interact-for-access-code.js.map +0 -1
  295. package/lib/interact-for-acs-entrance.js.map +0 -1
  296. package/lib/interact-for-acs-system.js.map +0 -1
  297. package/lib/interact-for-acs-user.js.map +0 -1
  298. package/lib/interact-for-action-attempt-poll.js.map +0 -1
  299. package/lib/interact-for-array.js.map +0 -1
  300. package/lib/interact-for-blueprint-object.js.map +0 -1
  301. package/lib/interact-for-command-params.js.map +0 -1
  302. package/lib/interact-for-command-selection.d.ts +0 -2
  303. package/lib/interact-for-command-selection.js.map +0 -1
  304. package/lib/interact-for-connected-account.js.map +0 -1
  305. package/lib/interact-for-custom-metadata.js.map +0 -1
  306. package/lib/interact-for-device.js.map +0 -1
  307. package/lib/interact-for-login.js.map +0 -1
  308. package/lib/interact-for-resource.js.map +0 -1
  309. package/lib/interact-for-server-selection.js.map +0 -1
  310. package/lib/interact-for-timestamp.js.map +0 -1
  311. package/lib/interact-for-use-remote-api-defs.js.map +0 -1
  312. package/lib/interact-for-user-identity.js.map +0 -1
  313. package/lib/interact-for-workspace-id.js.map +0 -1
  314. package/lib/output/create-memory-output.js.map +0 -1
  315. package/lib/output/create-output.js +0 -34
  316. package/lib/output/create-output.js.map +0 -1
  317. package/lib/render-help.js.map +0 -1
  318. package/lib/types.d.ts +0 -6
  319. package/lib/types.js +0 -2
  320. package/lib/types.js.map +0 -1
  321. package/lib/util/cli-args.js.map +0 -1
  322. package/lib/util/ellipsis.d.ts +0 -1
  323. package/lib/util/ellipsis.js +0 -6
  324. package/lib/util/ellipsis.js.map +0 -1
  325. package/lib/util/prompt.d.ts +0 -80
  326. package/lib/util/prompt.js.map +0 -1
  327. package/lib/util/read-stdin-json.js.map +0 -1
  328. package/lib/util/request-seam-api.d.ts +0 -7
  329. package/lib/util/request-seam-api.js +0 -26
  330. package/lib/util/request-seam-api.js.map +0 -1
  331. package/lib/util/with-loading.js.map +0 -1
  332. package/lib/validate-token.js.map +0 -1
  333. package/src/lib/get-api-blueprint.ts +0 -31
  334. package/src/lib/get-command-blueprint-def.ts +0 -15
  335. package/src/lib/get-credentials.ts +0 -38
  336. package/src/lib/get-current-workspace-id.ts +0 -9
  337. package/src/lib/get-server.ts +0 -20
  338. package/src/lib/types.ts +0 -7
  339. package/src/lib/util/ellipsis.ts +0 -4
  340. package/src/lib/util/prompt.ts +0 -229
  341. package/src/lib/util/request-seam-api.ts +0 -47
  342. /package/lib/{validate-token.d.ts → auth/validate-token.d.ts} +0 -0
  343. /package/lib/{interact-for-access-code.d.ts → interactions/access-code.d.ts} +0 -0
  344. /package/lib/{interact-for-acs-entrance.d.ts → interactions/acs-entrance.d.ts} +0 -0
  345. /package/lib/{interact-for-acs-system.d.ts → interactions/acs-system.d.ts} +0 -0
  346. /package/lib/{interact-for-acs-user.d.ts → interactions/acs-user.d.ts} +0 -0
  347. /package/lib/{interact-for-action-attempt-poll.d.ts → interactions/action-attempt-poll.d.ts} +0 -0
  348. /package/lib/{interact-for-array.d.ts → interactions/array.d.ts} +0 -0
  349. /package/lib/{interact-for-connected-account.d.ts → interactions/connected-account.d.ts} +0 -0
  350. /package/lib/{interact-for-custom-metadata.d.ts → interactions/custom-metadata.d.ts} +0 -0
  351. /package/lib/{interact-for-device.d.ts → interactions/device.d.ts} +0 -0
  352. /package/lib/{interact-for-login.d.ts → interactions/login.d.ts} +0 -0
  353. /package/lib/{interact-for-resource.d.ts → interactions/resource.d.ts} +0 -0
  354. /package/lib/{interact-for-server-selection.d.ts → interactions/server-selection.d.ts} +0 -0
  355. /package/lib/{interact-for-timestamp.d.ts → interactions/timestamp.d.ts} +0 -0
  356. /package/lib/{interact-for-use-remote-api-defs.d.ts → interactions/use-remote-api-defs.d.ts} +0 -0
  357. /package/lib/{interact-for-user-identity.d.ts → interactions/user-identity.d.ts} +0 -0
  358. /package/lib/{interact-for-workspace-id.d.ts → interactions/workspace-id.d.ts} +0 -0
  359. /package/lib/{util → output}/read-stdin-json.d.ts +0 -0
  360. /package/lib/{util → output}/read-stdin-json.js +0 -0
  361. /package/lib/{util → output}/with-loading.d.ts +0 -0
  362. /package/lib/{completion → render/completion}/describe.d.ts +0 -0
  363. /package/lib/{completion → render/completion}/render-fish.js +0 -0
  364. /package/src/lib/{util → output}/read-stdin-json.ts +0 -0
@@ -0,0 +1,84 @@
1
+ import type { Interactivity } from './args/parse.js'
2
+ import type { ApiBlueprint } from './blueprint/index.js'
3
+ import { type ConfigStore, getConfigStore } from './config/index.js'
4
+ import {
5
+ getEndpointFromEnv,
6
+ getTokenFromEnv,
7
+ getWorkspaceIdFromEnv,
8
+ } from './env.js'
9
+ import type { SeamApi } from './http/api.js'
10
+ import type { Output } from './output/output.js'
11
+
12
+ export const defaultServer = 'https://connect.getseam.com'
13
+
14
+ /** Where a resolved value came from, e.g., to refuse writes the env shadows. */
15
+ export type ValueSource = 'env' | 'config' | 'default'
16
+
17
+ /**
18
+ * The server, token, and workspace requests are made with.
19
+ *
20
+ * Resolved in one place so the precedence rule exists once: an environment
21
+ * variable wins over the stored value, and the server falls back to Seam.
22
+ * The source tags say where each value came from.
23
+ */
24
+ export interface AuthContext {
25
+ server: string
26
+ serverSource: ValueSource
27
+ token: string | null
28
+ tokenSource: Exclude<ValueSource, 'default'> | null
29
+ workspaceId: string | null
30
+ workspaceIdSource: Exclude<ValueSource, 'default'> | null
31
+ }
32
+
33
+ export const resolveAuth = (
34
+ config: ConfigStore = getConfigStore(),
35
+ ): AuthContext => {
36
+ const envServer = getEndpointFromEnv()
37
+ const storedServer = config.get('server')
38
+ const server =
39
+ envServer ?? (typeof storedServer === 'string' ? storedServer : null)
40
+
41
+ const envToken = getTokenFromEnv()
42
+ const storedToken = readString(config.get(`${server ?? defaultServer}.pat`))
43
+
44
+ const envWorkspaceId = getWorkspaceIdFromEnv()
45
+ const storedWorkspaceId = readString(config.get('current_workspace_id'))
46
+
47
+ return {
48
+ server: server ?? defaultServer,
49
+ serverSource:
50
+ envServer != null ? 'env' : server != null ? 'config' : 'default',
51
+ token: envToken ?? storedToken,
52
+ tokenSource:
53
+ envToken != null ? 'env' : storedToken != null ? 'config' : null,
54
+ workspaceId: envWorkspaceId ?? storedWorkspaceId,
55
+ workspaceIdSource:
56
+ envWorkspaceId != null
57
+ ? 'env'
58
+ : storedWorkspaceId != null
59
+ ? 'config'
60
+ : null,
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Everything a command runs with: the stores and auth it reads, the API
66
+ * shape it acts on, and how it may interact with the user.
67
+ */
68
+ export interface CliContext {
69
+ config: ConfigStore
70
+ auth: AuthContext
71
+ output: Output
72
+ blueprint: ApiBlueprint
73
+ interactivity: Interactivity
74
+ /** The Seam API, constructed on first use and shared for the run. */
75
+ api: () => Promise<SeamApi>
76
+ }
77
+
78
+ const readString = (value: unknown): string | null => {
79
+ if (typeof value !== 'string') return null
80
+
81
+ const trimmedValue = value.trim()
82
+
83
+ return trimmedValue === '' ? null : trimmedValue
84
+ }
package/src/lib/env.ts CHANGED
@@ -16,7 +16,7 @@ export const workspaceIdEnvVar = 'SEAM_CLI_WORKSPACE_ID'
16
16
  export const endpointEnvVar = 'SEAM_CLI_ENDPOINT'
17
17
 
18
18
  /** Every variable read here is declared on `ProcessEnv` in `env.d.ts`. */
19
- type SeamCliEnvVar =
19
+ type CliEnvVar =
20
20
  typeof endpointEnvVar | typeof tokenEnvVar | typeof workspaceIdEnvVar
21
21
 
22
22
  export const getTokenFromEnv = (): string | null => readEnvVar(tokenEnvVar)
@@ -52,7 +52,14 @@ export const assertEnvVarUnset = (
52
52
  )
53
53
  }
54
54
 
55
- const readEnvVar = (envVar: SeamCliEnvVar): string | null => {
55
+ /**
56
+ * Whether the CLI runs inside a hosted web terminal, where it cannot open
57
+ * anything in a browser of its own.
58
+ */
59
+ export const isInsideWebBrowser = (): boolean =>
60
+ process.env['INSIDE_WEB_BROWSER'] === '1'
61
+
62
+ const readEnvVar = (envVar: CliEnvVar): string | null => {
56
63
  const value = process.env[envVar]
57
64
 
58
65
  if (value == null) return null
@@ -0,0 +1,67 @@
1
+ import chalk from 'chalk'
2
+
3
+ import { EnvVarOverrideError } from './env.js'
4
+ import type { Output } from './output/output.js'
5
+
6
+ /**
7
+ * Thrown when the CLI needs input it cannot prompt for.
8
+ */
9
+ export class NonInteractiveError extends Error {
10
+ override name = 'NonInteractiveError'
11
+ }
12
+
13
+ /**
14
+ * Thrown when the user dismisses a prompt with ctrl-c or escape instead of
15
+ * answering it.
16
+ */
17
+ export class PromptCancelledError extends Error {
18
+ constructor() {
19
+ super('Cancelled')
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Thrown when the arguments do not name something the CLI can run.
25
+ */
26
+ export class UsageError extends Error {
27
+ override name = 'UsageError'
28
+
29
+ /** What to run instead, reported after the message. */
30
+ readonly hint: string
31
+
32
+ constructor(message: string, { hint = '' }: { hint?: string } = {}) {
33
+ super(message)
34
+ this.hint = hint
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Report a failure and set the exit code: usage mistakes read as one line
40
+ * with a hint, environment overrides without a stack trace, and anything
41
+ * else as an unexpected CLI error.
42
+ */
43
+ export const reportErrorAndExit = (e: unknown, output: Output): void => {
44
+ process.exitCode = 1
45
+
46
+ if (e instanceof UsageError) {
47
+ output.error(chalk.red(e.message))
48
+ if (e.hint !== '') output.error(e.hint)
49
+ return
50
+ }
51
+
52
+ if (e instanceof NonInteractiveError || e instanceof EnvVarOverrideError) {
53
+ output.error(chalk.red(e.message))
54
+ return
55
+ }
56
+
57
+ // Dismissing a prompt is the user stopping the CLI, not the CLI failing:
58
+ // note it quietly, without the alarm of an error.
59
+ if (e instanceof PromptCancelledError) {
60
+ output.error(chalk.gray(e.message))
61
+ return
62
+ }
63
+
64
+ const error = e instanceof Error ? e : new Error(String(e))
65
+ output.error(chalk.red(`CLI Error: ${error.message}`))
66
+ if (error.stack != null) output.error(chalk.gray(error.stack))
67
+ }
@@ -0,0 +1,61 @@
1
+ import { type SeamHttp, SeamHttpRequest } from '@seamapi/http/connect'
2
+
3
+ import type { AuthContext } from 'lib/context.js'
4
+
5
+ import { getSeam } from './client.js'
6
+
7
+ export interface ApiRequestOptions {
8
+ path: string
9
+ params: Record<string, unknown>
10
+ /** Response key documented for the endpoint, e.g., `devices`. */
11
+ responseKey?: string | null | undefined
12
+ }
13
+
14
+ /**
15
+ * A prepared call to the Seam API: inspectable before it is sent, e.g., to
16
+ * report the URL, then sent with {@link SeamApiRequest.fetchResponse}.
17
+ *
18
+ * The real implementation is the SDK's own `SeamHttpRequest`; sending one
19
+ * rejects with a `SeamHttpApiError` when the API reports an error.
20
+ */
21
+ export interface SeamApiRequest {
22
+ readonly url: URL
23
+ readonly method: string
24
+ readonly body: unknown
25
+ /** Send the request and return the full response body. */
26
+ fetchResponse: () => Promise<unknown>
27
+ }
28
+
29
+ /**
30
+ * How the blueprint-driven CLI reaches the Seam API: prepare a request for
31
+ * an endpoint path. Tests fake at this port with `createMemorySeamApi()` —
32
+ * the in-process mirror of the e2e suite's HTTP server.
33
+ */
34
+ export interface SeamApi {
35
+ createRequest: (options: ApiRequestOptions) => SeamApiRequest
36
+ }
37
+
38
+ /** The only place `SeamHttp` appears for raw requests. */
39
+ export class HttpSeamApi implements SeamApi {
40
+ constructor(private readonly seam: SeamHttp) {}
41
+
42
+ createRequest = ({
43
+ path,
44
+ params,
45
+ responseKey,
46
+ }: ApiRequestOptions): SeamApiRequest =>
47
+ new SeamHttpRequest<Record<string, unknown>, string | undefined>(
48
+ this.seam,
49
+ {
50
+ pathname: path,
51
+ method: 'POST',
52
+ body: params,
53
+ responseKey: responseKey ?? undefined,
54
+ },
55
+ )
56
+ }
57
+
58
+ export const createSeamApi = async (auth?: AuthContext): Promise<SeamApi> => {
59
+ const seam = await getSeam(auth)
60
+ return new HttpSeamApi(seam)
61
+ }
@@ -5,19 +5,20 @@ import {
5
5
  SeamHttpWithoutWorkspace,
6
6
  } from '@seamapi/http/connect'
7
7
 
8
- import { tokenEnvVar, workspaceIdEnvVar } from './env.js'
9
- import { getToken, getWorkspaceId } from './get-credentials.js'
10
- import { getServer } from './get-server.js'
8
+ import { type AuthContext, resolveAuth } from 'lib/context.js'
9
+ import { tokenEnvVar, workspaceIdEnvVar } from 'lib/env.js'
11
10
 
12
- export const getSeam = async (): Promise<SeamHttp> => {
13
- const token = getRequiredToken()
11
+ export const getSeam = async (
12
+ auth: AuthContext = resolveAuth(),
13
+ ): Promise<SeamHttp> => {
14
+ const token = getRequiredToken(auth)
14
15
 
15
- const options = { endpoint: getServer() }
16
+ const options = { endpoint: auth.server }
16
17
 
17
18
  if (isPersonalAccessToken(token)) {
18
19
  return SeamHttp.fromPersonalAccessToken(
19
20
  token,
20
- getRequiredWorkspaceId(),
21
+ getRequiredWorkspaceId(auth),
21
22
  options,
22
23
  )
23
24
  }
@@ -25,7 +26,7 @@ export const getSeam = async (): Promise<SeamHttp> => {
25
26
  if (isConsoleSessionToken(token)) {
26
27
  return SeamHttp.fromConsoleSessionToken(
27
28
  token,
28
- getRequiredWorkspaceId(),
29
+ getRequiredWorkspaceId(auth),
29
30
  options,
30
31
  )
31
32
  }
@@ -33,21 +34,21 @@ export const getSeam = async (): Promise<SeamHttp> => {
33
34
  return SeamHttp.fromApiKey(token, options)
34
35
  }
35
36
 
36
- export const getSeamMultiWorkspace = async (): Promise<
37
- SeamHttpWithoutWorkspace | SeamHttp
38
- > => {
39
- const token = getRequiredToken()
40
- const options = { endpoint: getServer() }
37
+ export const getSeamMultiWorkspace = async (
38
+ auth: AuthContext = resolveAuth(),
39
+ ): Promise<SeamHttpWithoutWorkspace | SeamHttp> => {
40
+ const token = getRequiredToken(auth)
41
+ const options = { endpoint: auth.server }
41
42
 
42
43
  if (isPersonalAccessToken(token)) {
43
44
  return SeamHttpWithoutWorkspace.fromPersonalAccessToken(token, options)
44
45
  }
45
46
 
46
- return await getSeam()
47
+ return await getSeam(auth)
47
48
  }
48
49
 
49
- const getRequiredToken = (): string => {
50
- const token = getToken()
50
+ const getRequiredToken = (auth: AuthContext): string => {
51
+ const { token } = auth
51
52
 
52
53
  if (token == null) {
53
54
  throw new Error(
@@ -58,8 +59,8 @@ const getRequiredToken = (): string => {
58
59
  return token
59
60
  }
60
61
 
61
- const getRequiredWorkspaceId = (): string => {
62
- const workspaceId = getWorkspaceId()
62
+ const getRequiredWorkspaceId = (auth: AuthContext): string => {
63
+ const { workspaceId } = auth
63
64
 
64
65
  if (workspaceId == null) {
65
66
  throw new Error(
@@ -0,0 +1,42 @@
1
+ import type { CliContext } from 'lib/context.js'
2
+ import { isInsideWebBrowser } from 'lib/env.js'
3
+ import { interactForActionAttemptPoll } from 'lib/interactions/index.js'
4
+ import { promptConfirm } from 'lib/prompt.js'
5
+
6
+ /**
7
+ * Follow-ups a response may call for: opening a connect webview in the
8
+ * browser, and offering to poll a pending action attempt.
9
+ */
10
+ export const runResponseFollowUps = async (
11
+ data: any,
12
+ ctx: CliContext,
13
+ ): Promise<void> => {
14
+ const isNonInteractive = ctx.interactivity === 'non-interactive'
15
+
16
+ if (data?.connect_webview) {
17
+ await handleConnectWebview(data.connect_webview, isNonInteractive)
18
+ }
19
+
20
+ if (data?.action_attempt && !isNonInteractive) {
21
+ await interactForActionAttemptPoll(data.action_attempt)
22
+ }
23
+ }
24
+
25
+ const handleConnectWebview = async (
26
+ connectWebview: any,
27
+ isNonInteractive: boolean,
28
+ ): Promise<void> => {
29
+ const url = connectWebview.url
30
+
31
+ if (!isNonInteractive && !isInsideWebBrowser()) {
32
+ const action = await promptConfirm({
33
+ message: 'Would you like to open the webview in your browser?',
34
+ initialValue: false,
35
+ })
36
+
37
+ if (action) {
38
+ const { default: open } = await import('open')
39
+ await open(url)
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,57 @@
1
+ import {
2
+ SeamHttpApiError,
3
+ SeamHttpInvalidInputError,
4
+ } from '@seamapi/http/connect'
5
+
6
+ import type { ApiRequestOptions, SeamApi, SeamApiRequest } from './api.js'
7
+
8
+ export interface MemorySeamApiResponse {
9
+ status: number
10
+ data: unknown
11
+ }
12
+
13
+ /**
14
+ * A real {@link SeamApi} answering from a routes table and recording every
15
+ * request, for tests: the in-process mirror of the e2e suite's HTTP server.
16
+ * Error statuses reject with the SDK's own error classes, exactly as the
17
+ * real transport does.
18
+ */
19
+ export class MemorySeamApi implements SeamApi {
20
+ /** Every request sent, in order — assert on the outbound messages. */
21
+ readonly requests: Array<{ path: string; params: Record<string, unknown> }> =
22
+ []
23
+
24
+ constructor(private readonly routes: Record<string, MemorySeamApiResponse>) {}
25
+
26
+ createRequest = ({ path, params }: ApiRequestOptions): SeamApiRequest => ({
27
+ url: new URL(`https://memory.seam.example${path}`),
28
+ method: 'POST',
29
+ body: params,
30
+ fetchResponse: async () => {
31
+ this.requests.push({ path, params })
32
+
33
+ const route = this.routes[path] ?? {
34
+ status: 404,
35
+ data: { error: { type: 'not_found', message: 'Not Found' } },
36
+ }
37
+
38
+ if (route.status >= 400) {
39
+ throw toSeamHttpError(route)
40
+ }
41
+ return route.data
42
+ },
43
+ })
44
+ }
45
+
46
+ const toSeamHttpError = (route: MemorySeamApiResponse): SeamHttpApiError => {
47
+ const error = (route.data as { error: { type: string; message: string } })
48
+ .error
49
+ if (error.type === 'invalid_input') {
50
+ return new SeamHttpInvalidInputError(error, route.status, 'request_memory')
51
+ }
52
+ return new SeamHttpApiError(error, route.status, 'request_memory')
53
+ }
54
+
55
+ export const createMemorySeamApi = (
56
+ routes: Record<string, MemorySeamApiResponse>,
57
+ ): MemorySeamApi => new MemorySeamApi(routes)
@@ -0,0 +1,69 @@
1
+ import {
2
+ isSeamHttpApiError,
3
+ type SeamHttpApiError,
4
+ } from '@seamapi/http/connect'
5
+ import chalk from 'chalk'
6
+
7
+ import type { Output } from 'lib/output/output.js'
8
+ import { selectResponsePayload } from 'lib/output/select-response-payload.js'
9
+ import { withLoading } from 'lib/output/with-loading.js'
10
+
11
+ import type { SeamApi } from './api.js'
12
+
13
+ export interface RequestSeamApiOptions {
14
+ path: string
15
+ params: Record<string, any>
16
+ /** Response key for the endpoint, used to trim the reported payload. */
17
+ responseKey?: string | null | undefined
18
+ }
19
+
20
+ export interface RequestSeamApiDependencies {
21
+ api: SeamApi
22
+ output: Output
23
+ }
24
+
25
+ /**
26
+ * Make a request and report the result: the request URL and params go to
27
+ * stderr, the trimmed payload to stdout. An API error reports its status
28
+ * and payload and sets the exit code. Returns the response body, or `null`
29
+ * when the API reported an error.
30
+ */
31
+ export const requestSeamApi = async (
32
+ options: RequestSeamApiOptions,
33
+ { api, output }: RequestSeamApiDependencies,
34
+ ): Promise<unknown> => {
35
+ const request = api.createRequest(options)
36
+
37
+ output.info(`\n${chalk.green(request.url.toString())}`)
38
+ output.info(`Request Params:`)
39
+ output.info(formatParams(options.params))
40
+
41
+ let body: unknown
42
+ try {
43
+ body = await withLoading('Making request...', async () => {
44
+ return await request.fetchResponse()
45
+ })
46
+ } catch (error) {
47
+ if (!isSeamHttpApiError(error)) throw error
48
+
49
+ output.warn(chalk.red(`[${error.statusCode}]`))
50
+ process.exitCode = 1
51
+ output.data({ error: toErrorPayload(error) })
52
+ return null
53
+ }
54
+
55
+ output.data(selectResponsePayload(body, { responseKey: options.responseKey }))
56
+
57
+ return body
58
+ }
59
+
60
+ const toErrorPayload = (
61
+ error: SeamHttpApiError,
62
+ ): { type: string; message: string; data?: unknown } => ({
63
+ type: error.code,
64
+ message: error.message,
65
+ ...(error.data === undefined ? {} : { data: error.data }),
66
+ })
67
+
68
+ const formatParams = (params: Record<string, any>): string =>
69
+ JSON.stringify(params, null, 2)
@@ -1,6 +1,7 @@
1
- import { getSeam } from './get-seam.js'
2
- import { interactForDevice } from './interact-for-device.js'
3
- import { interactForResource } from './interact-for-resource.js'
1
+ import { getSeam } from 'lib/http/client.js'
2
+
3
+ import { interactForDevice } from './device.js'
4
+ import { interactForResource } from './resource.js'
4
5
 
5
6
  export const interactForAccessCode = async ({
6
7
  // The key is a Seam API parameter name: callers pass the blueprint params
@@ -1,5 +1,6 @@
1
- import { getSeam } from './get-seam.js'
2
- import { interactForResource } from './interact-for-resource.js'
1
+ import { getSeam } from 'lib/http/client.js'
2
+
3
+ import { interactForResource } from './resource.js'
3
4
 
4
5
  export const interactForAcsEntrance = async () => {
5
6
  const seam = await getSeam()
@@ -1,5 +1,6 @@
1
- import { getSeam } from './get-seam.js'
2
- import { interactForResource } from './interact-for-resource.js'
1
+ import { getSeam } from 'lib/http/client.js'
2
+
3
+ import { interactForResource } from './resource.js'
3
4
 
4
5
  export const interactForAcsSystem = async (message?: string) => {
5
6
  const seam = await getSeam()
@@ -1,6 +1,7 @@
1
- import { getSeam } from './get-seam.js'
2
- import { interactForAcsSystem } from './interact-for-acs-system.js'
3
- import { interactForResource } from './interact-for-resource.js'
1
+ import { getSeam } from 'lib/http/client.js'
2
+
3
+ import { interactForAcsSystem } from './acs-system.js'
4
+ import { interactForResource } from './resource.js'
4
5
 
5
6
  export const interactForAcsUser = async () => {
6
7
  const seam = await getSeam()
@@ -1,9 +1,9 @@
1
1
  import type { ActionAttemptsGetResponse } from '@seamapi/http/connect'
2
2
 
3
- import { getSeam } from './get-seam.js'
4
- import { getOutput } from './output/get-output.js'
5
- import { promptConfirm } from './util/prompt.js'
6
- import { withLoading } from './util/with-loading.js'
3
+ import { getSeam } from 'lib/http/client.js'
4
+ import { getOutput } from 'lib/output/get-output.js'
5
+ import { withLoading } from 'lib/output/with-loading.js'
6
+ import { promptConfirm } from 'lib/prompt.js'
7
7
 
8
8
  export const interactForActionAttemptPoll = async (
9
9
  actionAttempt: ActionAttemptsGetResponse['action_attempt'],
@@ -1,11 +1,11 @@
1
- import { getOutput } from './output/get-output.js'
1
+ import { PromptCancelledError } from 'lib/errors.js'
2
+ import { getOutput } from 'lib/output/get-output.js'
2
3
  import {
3
- PromptCancelledError,
4
4
  promptNumber,
5
5
  promptSelect,
6
6
  promptText,
7
7
  withBackHint,
8
- } from './util/prompt.js'
8
+ } from 'lib/prompt.js'
9
9
 
10
10
  export const interactForArray = async (
11
11
  array: string[],