@beezer-pet/instant-cli 0.0.0-stage → 1.0.67-beezer.3

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 (443) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/LICENSE.md +202 -0
  3. package/README.md +34 -2
  4. package/__tests__/appCommands.test.ts +228 -0
  5. package/__tests__/args.test.ts +358 -0
  6. package/__tests__/auth.test.ts +128 -0
  7. package/__tests__/authClientAddApple.test.ts +376 -0
  8. package/__tests__/authClientAddClerk.test.ts +222 -0
  9. package/__tests__/authClientAddGithub.test.ts +245 -0
  10. package/__tests__/authClientAddGoogle.test.ts +373 -0
  11. package/__tests__/authClientAddLinkedin.test.ts +262 -0
  12. package/__tests__/authClientList.test.ts +90 -0
  13. package/__tests__/authClientUpdate.test.ts +583 -0
  14. package/__tests__/authOriginManagement.test.ts +308 -0
  15. package/__tests__/backupDownload.test.ts +206 -0
  16. package/__tests__/backups.test.ts +221 -0
  17. package/__tests__/config.test.ts +57 -0
  18. package/__tests__/e2e/cli.e2e.test.ts +1267 -0
  19. package/__tests__/e2e/helpers.ts +177 -0
  20. package/__tests__/effectHelpers.ts +45 -0
  21. package/__tests__/mergeSchema.test.ts +197 -0
  22. package/__tests__/multiSelect.test.ts +236 -0
  23. package/__tests__/oauthMock.ts +76 -0
  24. package/__tests__/promptOk.test.ts +44 -0
  25. package/__tests__/redirectUriPrompt.test.ts +40 -0
  26. package/__tests__/sdkInstallSpec.test.ts +36 -0
  27. package/__tests__/select.test.ts +224 -0
  28. package/__tests__/webhooks.test.ts +728 -0
  29. package/bin/index.js +3 -0
  30. package/dist/auth/index.d.ts +4 -0
  31. package/dist/auth/index.d.ts.map +1 -0
  32. package/dist/auth/index.js +103 -0
  33. package/dist/auth/index.js.map +1 -0
  34. package/dist/commands/app/delete.d.ts +7 -0
  35. package/dist/commands/app/delete.d.ts.map +1 -0
  36. package/dist/commands/app/delete.js +57 -0
  37. package/dist/commands/app/delete.js.map +1 -0
  38. package/dist/commands/app/list.d.ts +6 -0
  39. package/dist/commands/app/list.d.ts.map +1 -0
  40. package/dist/commands/app/list.js +29 -0
  41. package/dist/commands/app/list.js.map +1 -0
  42. package/dist/commands/auth/client/add.d.ts +9 -0
  43. package/dist/commands/auth/client/add.d.ts.map +1 -0
  44. package/dist/commands/auth/client/add.js +409 -0
  45. package/dist/commands/auth/client/add.js.map +1 -0
  46. package/dist/commands/auth/client/delete.d.ts +11 -0
  47. package/dist/commands/auth/client/delete.d.ts.map +1 -0
  48. package/dist/commands/auth/client/delete.js +48 -0
  49. package/dist/commands/auth/client/delete.js.map +1 -0
  50. package/dist/commands/auth/client/list.d.ts +6 -0
  51. package/dist/commands/auth/client/list.d.ts.map +1 -0
  52. package/dist/commands/auth/client/list.js +38 -0
  53. package/dist/commands/auth/client/list.js.map +1 -0
  54. package/dist/commands/auth/client/shared.d.ts +70 -0
  55. package/dist/commands/auth/client/shared.d.ts.map +1 -0
  56. package/dist/commands/auth/client/shared.js +140 -0
  57. package/dist/commands/auth/client/shared.js.map +1 -0
  58. package/dist/commands/auth/client/update.d.ts +8 -0
  59. package/dist/commands/auth/client/update.d.ts.map +1 -0
  60. package/dist/commands/auth/client/update.js +445 -0
  61. package/dist/commands/auth/client/update.js.map +1 -0
  62. package/dist/commands/auth/email/pull.d.ts +24 -0
  63. package/dist/commands/auth/email/pull.d.ts.map +1 -0
  64. package/dist/commands/auth/email/pull.js +100 -0
  65. package/dist/commands/auth/email/pull.js.map +1 -0
  66. package/dist/commands/auth/email/push.d.ts +8 -0
  67. package/dist/commands/auth/email/push.d.ts.map +1 -0
  68. package/dist/commands/auth/email/push.js +58 -0
  69. package/dist/commands/auth/email/push.js.map +1 -0
  70. package/dist/commands/auth/email/resend.d.ts +3 -0
  71. package/dist/commands/auth/email/resend.d.ts.map +1 -0
  72. package/dist/commands/auth/email/resend.js +7 -0
  73. package/dist/commands/auth/email/resend.js.map +1 -0
  74. package/dist/commands/auth/email/reset.d.ts +5 -0
  75. package/dist/commands/auth/email/reset.d.ts.map +1 -0
  76. package/dist/commands/auth/email/reset.js +25 -0
  77. package/dist/commands/auth/email/reset.js.map +1 -0
  78. package/dist/commands/auth/email/status.d.ts +57 -0
  79. package/dist/commands/auth/email/status.d.ts.map +1 -0
  80. package/dist/commands/auth/email/status.js +96 -0
  81. package/dist/commands/auth/email/status.js.map +1 -0
  82. package/dist/commands/auth/email/verify.d.ts +5 -0
  83. package/dist/commands/auth/email/verify.d.ts.map +1 -0
  84. package/dist/commands/auth/email/verify.js +12 -0
  85. package/dist/commands/auth/email/verify.js.map +1 -0
  86. package/dist/commands/auth/origin/add.d.ts +12 -0
  87. package/dist/commands/auth/origin/add.d.ts.map +1 -0
  88. package/dist/commands/auth/origin/add.js +153 -0
  89. package/dist/commands/auth/origin/add.js.map +1 -0
  90. package/dist/commands/auth/origin/delete.d.ts +8 -0
  91. package/dist/commands/auth/origin/delete.d.ts.map +1 -0
  92. package/dist/commands/auth/origin/delete.js +38 -0
  93. package/dist/commands/auth/origin/delete.js.map +1 -0
  94. package/dist/commands/auth/origin/list.d.ts +9 -0
  95. package/dist/commands/auth/origin/list.d.ts.map +1 -0
  96. package/dist/commands/auth/origin/list.js +52 -0
  97. package/dist/commands/auth/origin/list.js.map +1 -0
  98. package/dist/commands/backup/download.d.ts +10 -0
  99. package/dist/commands/backup/download.d.ts.map +1 -0
  100. package/dist/commands/backup/download.js +174 -0
  101. package/dist/commands/backup/download.js.map +1 -0
  102. package/dist/commands/backup/list.d.ts +11 -0
  103. package/dist/commands/backup/list.d.ts.map +1 -0
  104. package/dist/commands/backup/list.js +74 -0
  105. package/dist/commands/backup/list.js.map +1 -0
  106. package/dist/commands/claim.d.ts +6 -0
  107. package/dist/commands/claim.d.ts.map +1 -0
  108. package/dist/commands/claim.js +22 -0
  109. package/dist/commands/claim.js.map +1 -0
  110. package/dist/commands/explorer.d.ts +6 -0
  111. package/dist/commands/explorer.d.ts.map +1 -0
  112. package/dist/commands/explorer.js +13 -0
  113. package/dist/commands/explorer.js.map +1 -0
  114. package/dist/commands/info.d.ts +9 -0
  115. package/dist/commands/info.d.ts.map +1 -0
  116. package/dist/commands/info.js +41 -0
  117. package/dist/commands/info.js.map +1 -0
  118. package/dist/commands/init.d.ts +5 -0
  119. package/dist/commands/init.d.ts.map +1 -0
  120. package/dist/commands/init.js +41 -0
  121. package/dist/commands/init.js.map +1 -0
  122. package/dist/commands/initWithoutFiles.d.ts +6 -0
  123. package/dist/commands/initWithoutFiles.d.ts.map +1 -0
  124. package/dist/commands/initWithoutFiles.js +64 -0
  125. package/dist/commands/initWithoutFiles.js.map +1 -0
  126. package/dist/commands/login.d.ts +9 -0
  127. package/dist/commands/login.d.ts.map +1 -0
  128. package/dist/commands/login.js +44 -0
  129. package/dist/commands/login.js.map +1 -0
  130. package/dist/commands/logout.d.ts +3 -0
  131. package/dist/commands/logout.d.ts.map +1 -0
  132. package/dist/commands/logout.js +14 -0
  133. package/dist/commands/logout.js.map +1 -0
  134. package/dist/commands/pull.d.ts +5 -0
  135. package/dist/commands/pull.d.ts.map +1 -0
  136. package/dist/commands/pull.js +15 -0
  137. package/dist/commands/pull.js.map +1 -0
  138. package/dist/commands/push.d.ts +6 -0
  139. package/dist/commands/push.d.ts.map +1 -0
  140. package/dist/commands/push.js +20 -0
  141. package/dist/commands/push.js.map +1 -0
  142. package/dist/commands/query.d.ts +7 -0
  143. package/dist/commands/query.d.ts.map +1 -0
  144. package/dist/commands/query.js +52 -0
  145. package/dist/commands/query.js.map +1 -0
  146. package/dist/commands/webhooks/add.d.ts +9 -0
  147. package/dist/commands/webhooks/add.d.ts.map +1 -0
  148. package/dist/commands/webhooks/add.js +75 -0
  149. package/dist/commands/webhooks/add.js.map +1 -0
  150. package/dist/commands/webhooks/delete.d.ts +6 -0
  151. package/dist/commands/webhooks/delete.d.ts.map +1 -0
  152. package/dist/commands/webhooks/delete.js +17 -0
  153. package/dist/commands/webhooks/delete.js.map +1 -0
  154. package/dist/commands/webhooks/disable.d.ts +7 -0
  155. package/dist/commands/webhooks/disable.d.ts.map +1 -0
  156. package/dist/commands/webhooks/disable.js +18 -0
  157. package/dist/commands/webhooks/disable.js.map +1 -0
  158. package/dist/commands/webhooks/enable.d.ts +6 -0
  159. package/dist/commands/webhooks/enable.d.ts.map +1 -0
  160. package/dist/commands/webhooks/enable.js +18 -0
  161. package/dist/commands/webhooks/enable.js.map +1 -0
  162. package/dist/commands/webhooks/events/list.d.ts +7 -0
  163. package/dist/commands/webhooks/events/list.d.ts.map +1 -0
  164. package/dist/commands/webhooks/events/list.js +31 -0
  165. package/dist/commands/webhooks/events/list.js.map +1 -0
  166. package/dist/commands/webhooks/events/payload.d.ts +8 -0
  167. package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
  168. package/dist/commands/webhooks/events/payload.js +39 -0
  169. package/dist/commands/webhooks/events/payload.js.map +1 -0
  170. package/dist/commands/webhooks/events/resend.d.ts +8 -0
  171. package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
  172. package/dist/commands/webhooks/events/resend.js +43 -0
  173. package/dist/commands/webhooks/events/resend.js.map +1 -0
  174. package/dist/commands/webhooks/list.d.ts +8 -0
  175. package/dist/commands/webhooks/list.d.ts.map +1 -0
  176. package/dist/commands/webhooks/list.js +29 -0
  177. package/dist/commands/webhooks/list.js.map +1 -0
  178. package/dist/commands/webhooks/shared.d.ts +40 -0
  179. package/dist/commands/webhooks/shared.d.ts.map +1 -0
  180. package/dist/commands/webhooks/shared.js +248 -0
  181. package/dist/commands/webhooks/shared.js.map +1 -0
  182. package/dist/commands/webhooks/update.d.ts +10 -0
  183. package/dist/commands/webhooks/update.d.ts.map +1 -0
  184. package/dist/commands/webhooks/update.js +189 -0
  185. package/dist/commands/webhooks/update.js.map +1 -0
  186. package/dist/context/authToken.d.ts +29 -0
  187. package/dist/context/authToken.d.ts.map +1 -0
  188. package/dist/context/authToken.js +73 -0
  189. package/dist/context/authToken.js.map +1 -0
  190. package/dist/context/currentApp.d.ts +38 -0
  191. package/dist/context/currentApp.d.ts.map +1 -0
  192. package/dist/context/currentApp.js +222 -0
  193. package/dist/context/currentApp.js.map +1 -0
  194. package/dist/context/globalOpts.d.ts +11 -0
  195. package/dist/context/globalOpts.d.ts.map +1 -0
  196. package/dist/context/globalOpts.js +13 -0
  197. package/dist/context/globalOpts.js.map +1 -0
  198. package/dist/context/platformApi.d.ts +19 -0
  199. package/dist/context/platformApi.d.ts.map +1 -0
  200. package/dist/context/platformApi.js +24 -0
  201. package/dist/context/platformApi.js.map +1 -0
  202. package/dist/context/projectInfo.d.ts +30 -0
  203. package/dist/context/projectInfo.d.ts.map +1 -0
  204. package/dist/context/projectInfo.js +153 -0
  205. package/dist/context/projectInfo.js.map +1 -0
  206. package/dist/errors.d.ts +10 -0
  207. package/dist/errors.d.ts.map +1 -0
  208. package/dist/errors.js +6 -0
  209. package/dist/errors.js.map +1 -0
  210. package/dist/index.d.ts +159 -0
  211. package/dist/index.d.ts.map +1 -0
  212. package/dist/index.js +714 -0
  213. package/dist/index.js.map +1 -0
  214. package/dist/layer.d.ts +25 -0
  215. package/dist/layer.d.ts.map +1 -0
  216. package/dist/layer.js +119 -0
  217. package/dist/layer.js.map +1 -0
  218. package/dist/lib/args.d.ts +212 -0
  219. package/dist/lib/args.d.ts.map +1 -0
  220. package/dist/lib/args.js +313 -0
  221. package/dist/lib/args.js.map +1 -0
  222. package/dist/lib/backupDownload.d.ts +21 -0
  223. package/dist/lib/backupDownload.d.ts.map +1 -0
  224. package/dist/lib/backupDownload.js +151 -0
  225. package/dist/lib/backupDownload.js.map +1 -0
  226. package/dist/lib/backups.d.ts +12 -0
  227. package/dist/lib/backups.d.ts.map +1 -0
  228. package/dist/lib/backups.js +26 -0
  229. package/dist/lib/backups.js.map +1 -0
  230. package/dist/lib/config.d.ts +6 -0
  231. package/dist/lib/config.d.ts.map +1 -0
  232. package/dist/lib/config.js +39 -0
  233. package/dist/lib/config.js.map +1 -0
  234. package/dist/lib/createApp.d.ts +12 -0
  235. package/dist/lib/createApp.d.ts.map +1 -0
  236. package/dist/lib/createApp.js +15 -0
  237. package/dist/lib/createApp.js.map +1 -0
  238. package/dist/lib/email.d.ts +47 -0
  239. package/dist/lib/email.d.ts.map +1 -0
  240. package/dist/lib/email.js +71 -0
  241. package/dist/lib/email.js.map +1 -0
  242. package/dist/lib/handleEnv.d.ts +7 -0
  243. package/dist/lib/handleEnv.d.ts.map +1 -0
  244. package/dist/lib/handleEnv.js +99 -0
  245. package/dist/lib/handleEnv.js.map +1 -0
  246. package/dist/lib/http.d.ts +30 -0
  247. package/dist/lib/http.d.ts.map +1 -0
  248. package/dist/lib/http.js +55 -0
  249. package/dist/lib/http.js.map +1 -0
  250. package/dist/lib/login.d.ts +12 -0
  251. package/dist/lib/login.d.ts.map +1 -0
  252. package/dist/lib/login.js +38 -0
  253. package/dist/lib/login.js.map +1 -0
  254. package/dist/lib/oauth.d.ts +306 -0
  255. package/dist/lib/oauth.d.ts.map +1 -0
  256. package/dist/lib/oauth.js +195 -0
  257. package/dist/lib/oauth.js.map +1 -0
  258. package/dist/lib/platformApi.d.ts +5 -0
  259. package/dist/lib/platformApi.d.ts.map +1 -0
  260. package/dist/lib/platformApi.js +11 -0
  261. package/dist/lib/platformApi.js.map +1 -0
  262. package/dist/lib/pullPerms.d.ts +7 -0
  263. package/dist/lib/pullPerms.d.ts.map +1 -0
  264. package/dist/lib/pullPerms.js +41 -0
  265. package/dist/lib/pullPerms.js.map +1 -0
  266. package/dist/lib/pullSchema.d.ts +12 -0
  267. package/dist/lib/pullSchema.d.ts.map +1 -0
  268. package/dist/lib/pullSchema.js +62 -0
  269. package/dist/lib/pullSchema.js.map +1 -0
  270. package/dist/lib/pushPerms.d.ts +13 -0
  271. package/dist/lib/pushPerms.d.ts.map +1 -0
  272. package/dist/lib/pushPerms.js +54 -0
  273. package/dist/lib/pushPerms.js.map +1 -0
  274. package/dist/lib/pushSchema.d.ts +53 -0
  275. package/dist/lib/pushSchema.d.ts.map +1 -0
  276. package/dist/lib/pushSchema.js +165 -0
  277. package/dist/lib/pushSchema.js.map +1 -0
  278. package/dist/lib/ui.d.ts +18 -0
  279. package/dist/lib/ui.d.ts.map +1 -0
  280. package/dist/lib/ui.js +32 -0
  281. package/dist/lib/ui.js.map +1 -0
  282. package/dist/lib/webhooks.d.ts +27 -0
  283. package/dist/lib/webhooks.d.ts.map +1 -0
  284. package/dist/lib/webhooks.js +95 -0
  285. package/dist/lib/webhooks.js.map +1 -0
  286. package/dist/logging.d.ts +5 -0
  287. package/dist/logging.d.ts.map +1 -0
  288. package/dist/logging.js +25 -0
  289. package/dist/logging.js.map +1 -0
  290. package/dist/old.d.ts +17 -0
  291. package/dist/old.d.ts.map +1 -0
  292. package/dist/old.js +410 -0
  293. package/dist/old.js.map +1 -0
  294. package/dist/program.d.ts +3 -0
  295. package/dist/program.d.ts.map +1 -0
  296. package/dist/program.js +3 -0
  297. package/dist/program.js.map +1 -0
  298. package/dist/renderSchemaPlan.d.ts +19 -0
  299. package/dist/renderSchemaPlan.d.ts.map +1 -0
  300. package/dist/renderSchemaPlan.js +220 -0
  301. package/dist/renderSchemaPlan.js.map +1 -0
  302. package/dist/ui/index.d.ts +292 -0
  303. package/dist/ui/index.d.ts.map +1 -0
  304. package/dist/ui/index.js +1296 -0
  305. package/dist/ui/index.js.map +1 -0
  306. package/dist/ui/lib.d.ts +124 -0
  307. package/dist/ui/lib.d.ts.map +1 -0
  308. package/dist/ui/lib.js +333 -0
  309. package/dist/ui/lib.js.map +1 -0
  310. package/dist/util/findConfigCandidates.d.ts +13 -0
  311. package/dist/util/findConfigCandidates.d.ts.map +1 -0
  312. package/dist/util/findConfigCandidates.js +211 -0
  313. package/dist/util/findConfigCandidates.js.map +1 -0
  314. package/dist/util/fs.d.ts +4 -0
  315. package/dist/util/fs.d.ts.map +1 -0
  316. package/dist/util/fs.js +22 -0
  317. package/dist/util/fs.js.map +1 -0
  318. package/dist/util/getAppName.d.ts +5 -0
  319. package/dist/util/getAppName.d.ts.map +1 -0
  320. package/dist/util/getAppName.js +14 -0
  321. package/dist/util/getAppName.js.map +1 -0
  322. package/dist/util/instantConfig.d.ts +9 -0
  323. package/dist/util/instantConfig.d.ts.map +1 -0
  324. package/dist/util/instantConfig.js +13 -0
  325. package/dist/util/instantConfig.js.map +1 -0
  326. package/dist/util/isHeadlessEnvironment.d.ts +4 -0
  327. package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
  328. package/dist/util/isHeadlessEnvironment.js +11 -0
  329. package/dist/util/isHeadlessEnvironment.js.map +1 -0
  330. package/dist/util/loadConfig.d.ts +3 -0
  331. package/dist/util/loadConfig.d.ts.map +1 -0
  332. package/dist/util/loadConfig.js +72 -0
  333. package/dist/util/loadConfig.js.map +1 -0
  334. package/dist/util/loadEnv.d.ts +2 -0
  335. package/dist/util/loadEnv.d.ts.map +1 -0
  336. package/dist/util/loadEnv.js +10 -0
  337. package/dist/util/loadEnv.js.map +1 -0
  338. package/dist/util/mergeSchema.d.ts +10 -0
  339. package/dist/util/mergeSchema.d.ts.map +1 -0
  340. package/dist/util/mergeSchema.js +338 -0
  341. package/dist/util/mergeSchema.js.map +1 -0
  342. package/dist/util/projectDir.d.ts +7 -0
  343. package/dist/util/projectDir.d.ts.map +1 -0
  344. package/dist/util/projectDir.js +43 -0
  345. package/dist/util/projectDir.js.map +1 -0
  346. package/dist/util/renamePrompt.d.ts +15 -0
  347. package/dist/util/renamePrompt.d.ts.map +1 -0
  348. package/dist/util/renamePrompt.js +57 -0
  349. package/dist/util/renamePrompt.js.map +1 -0
  350. package/dist/util/sdkInstallSpec.d.ts +13 -0
  351. package/dist/util/sdkInstallSpec.d.ts.map +1 -0
  352. package/dist/util/sdkInstallSpec.js +37 -0
  353. package/dist/util/sdkInstallSpec.js.map +1 -0
  354. package/dist/version.d.ts +3 -0
  355. package/dist/version.d.ts.map +1 -0
  356. package/dist/version.js +3 -0
  357. package/dist/version.js.map +1 -0
  358. package/package.json +91 -3
  359. package/src/auth/index.ts +125 -0
  360. package/src/commands/app/delete.ts +82 -0
  361. package/src/commands/app/list.ts +44 -0
  362. package/src/commands/auth/client/add.ts +744 -0
  363. package/src/commands/auth/client/delete.ts +60 -0
  364. package/src/commands/auth/client/list.ts +60 -0
  365. package/src/commands/auth/client/shared.ts +190 -0
  366. package/src/commands/auth/client/update.ts +830 -0
  367. package/src/commands/auth/email/pull.ts +143 -0
  368. package/src/commands/auth/email/push.ts +94 -0
  369. package/src/commands/auth/email/resend.ts +8 -0
  370. package/src/commands/auth/email/reset.ts +37 -0
  371. package/src/commands/auth/email/status.ts +154 -0
  372. package/src/commands/auth/email/verify.ts +20 -0
  373. package/src/commands/auth/origin/add.ts +237 -0
  374. package/src/commands/auth/origin/delete.ts +50 -0
  375. package/src/commands/auth/origin/list.ts +66 -0
  376. package/src/commands/backup/download.ts +231 -0
  377. package/src/commands/backup/list.ts +94 -0
  378. package/src/commands/claim.ts +31 -0
  379. package/src/commands/explorer.ts +21 -0
  380. package/src/commands/info.ts +57 -0
  381. package/src/commands/init.ts +60 -0
  382. package/src/commands/initWithoutFiles.ts +107 -0
  383. package/src/commands/login.ts +62 -0
  384. package/src/commands/logout.ts +22 -0
  385. package/src/commands/pull.ts +22 -0
  386. package/src/commands/push.ts +25 -0
  387. package/src/commands/query.ts +61 -0
  388. package/src/commands/webhooks/add.ts +111 -0
  389. package/src/commands/webhooks/delete.ts +23 -0
  390. package/src/commands/webhooks/disable.ts +24 -0
  391. package/src/commands/webhooks/enable.ts +24 -0
  392. package/src/commands/webhooks/events/list.ts +38 -0
  393. package/src/commands/webhooks/events/payload.ts +56 -0
  394. package/src/commands/webhooks/events/resend.ts +66 -0
  395. package/src/commands/webhooks/list.ts +41 -0
  396. package/src/commands/webhooks/shared.ts +339 -0
  397. package/src/commands/webhooks/update.ts +276 -0
  398. package/src/context/authToken.ts +134 -0
  399. package/src/context/currentApp.ts +301 -0
  400. package/src/context/globalOpts.ts +22 -0
  401. package/src/context/platformApi.ts +35 -0
  402. package/src/context/projectInfo.ts +219 -0
  403. package/src/errors.ts +7 -0
  404. package/src/index.ts +1212 -0
  405. package/src/layer.ts +211 -0
  406. package/src/lib/args.ts +453 -0
  407. package/src/lib/backupDownload.ts +188 -0
  408. package/src/lib/backups.ts +33 -0
  409. package/src/lib/config.ts +73 -0
  410. package/src/lib/createApp.ts +28 -0
  411. package/src/lib/email.ts +93 -0
  412. package/src/lib/handleEnv.ts +122 -0
  413. package/src/lib/http.ts +128 -0
  414. package/src/lib/login.ts +48 -0
  415. package/src/lib/oauth.ts +310 -0
  416. package/src/lib/platformApi.ts +11 -0
  417. package/src/lib/pullPerms.ts +50 -0
  418. package/src/lib/pullSchema.ts +95 -0
  419. package/src/lib/pushPerms.ts +80 -0
  420. package/src/lib/pushSchema.ts +248 -0
  421. package/src/lib/ui.ts +48 -0
  422. package/src/lib/webhooks.ts +118 -0
  423. package/src/logging.ts +41 -0
  424. package/src/old.js +487 -0
  425. package/src/program.ts +3 -0
  426. package/src/renderSchemaPlan.ts +324 -0
  427. package/src/ui/index.ts +1615 -0
  428. package/src/ui/lib.ts +424 -0
  429. package/src/util/findConfigCandidates.ts +262 -0
  430. package/src/util/fs.ts +26 -0
  431. package/src/util/getAppName.ts +14 -0
  432. package/src/util/instantConfig.ts +21 -0
  433. package/src/util/isHeadlessEnvironment.ts +15 -0
  434. package/src/util/loadConfig.ts +93 -0
  435. package/src/util/loadEnv.ts +11 -0
  436. package/src/util/mergeSchema.ts +374 -0
  437. package/src/util/projectDir.ts +54 -0
  438. package/src/util/renamePrompt.ts +79 -0
  439. package/src/util/sdkInstallSpec.ts +45 -0
  440. package/src/version.js +3 -0
  441. package/tsconfig.build.json +20 -0
  442. package/tsconfig.json +23 -0
  443. package/vitest.config.ts +22 -0
@@ -0,0 +1,134 @@
1
+ import { Config, Context, Effect, Layer, Option, Ref, Schema } from 'effect';
2
+ import { readAuthToken } from '../auth/index.ts';
3
+ import { loginCommand } from '../commands/login.ts';
4
+ import { getBaseUrl } from '../lib/config.ts';
5
+ import { program } from '../program.ts';
6
+
7
+ type AuthTokenSource = 'admin' | 'env' | 'opt' | 'file';
8
+
9
+ type AuthTokenState = {
10
+ authToken: string;
11
+ source: AuthTokenSource;
12
+ };
13
+
14
+ export class AuthToken extends Context.Tag('instant-cli/new/context/authToken')<
15
+ AuthToken,
16
+ {
17
+ getAuthToken: Effect.Effect<string>;
18
+ getSource: Effect.Effect<AuthTokenSource>;
19
+ setAuthToken: (
20
+ authToken: string,
21
+ source?: AuthTokenSource,
22
+ ) => Effect.Effect<void>;
23
+ }
24
+ >() {}
25
+
26
+ export class NotAuthedError extends Schema.TaggedError<NotAuthedError>(
27
+ 'NotAuthedError',
28
+ )('NotAuthedError', {
29
+ message: Schema.String,
30
+ }) {}
31
+
32
+ export const authTokenGetEffect = (allowAdminToken: boolean = true) =>
33
+ Effect.gen(function* () {
34
+ const options = program.opts() as Record<string, any>;
35
+ if (typeof options.token === 'string') {
36
+ return {
37
+ authToken: options.token,
38
+ source: 'opt' as 'env' | 'opt' | 'file',
39
+ };
40
+ }
41
+
42
+ const env = yield* Config.string('INSTANT_CLI_AUTH_TOKEN').pipe(
43
+ Config.option,
44
+ Config.map(Option.getOrNull),
45
+ );
46
+
47
+ if (env) {
48
+ return {
49
+ authToken: env,
50
+ source: 'env' as 'env' | 'opt' | 'file',
51
+ };
52
+ }
53
+
54
+ const secondaryEnv = yield* Config.string('INSTANT_APP_ADMIN_TOKEN').pipe(
55
+ Config.orElse(() => Config.string('INSTANT_ADMIN_TOKEN')),
56
+ Config.option,
57
+ Config.map(Option.getOrNull),
58
+ );
59
+ if (secondaryEnv && allowAdminToken) {
60
+ return {
61
+ authToken: secondaryEnv,
62
+ source: 'admin' as 'admin',
63
+ };
64
+ }
65
+
66
+ const apiURI = yield* getBaseUrl;
67
+ const file = yield* Effect.tryPromise(() => readAuthToken(apiURI)).pipe(
68
+ Effect.orElseSucceed(() => null),
69
+ );
70
+ if (file) {
71
+ return {
72
+ authToken: file,
73
+ source: 'file' as 'env' | 'opt' | 'file',
74
+ };
75
+ }
76
+
77
+ return yield* NotAuthedError.make({ message: 'You are not logged in' });
78
+ });
79
+
80
+ export const AuthTokenLive = ({
81
+ coerce,
82
+ allowAdminToken = true,
83
+ }: {
84
+ coerce: boolean;
85
+ allowAdminToken: boolean;
86
+ }) =>
87
+ Layer.effect(
88
+ AuthToken,
89
+ authTokenGetEffect(allowAdminToken).pipe(
90
+ Effect.flatMap((tokenResult) =>
91
+ Effect.gen(function* () {
92
+ const authStateRef = yield* Ref.make<AuthTokenState>(tokenResult);
93
+ return {
94
+ getAuthToken: Ref.get(authStateRef).pipe(
95
+ Effect.map((authState) => authState.authToken),
96
+ ),
97
+ getSource: Ref.get(authStateRef).pipe(
98
+ Effect.map((authState) => authState.source),
99
+ ),
100
+ setAuthToken: (authToken: string, source?: AuthTokenSource) =>
101
+ Ref.update(authStateRef, (authState) => ({
102
+ ...authState,
103
+ authToken,
104
+ source: source ?? authState.source,
105
+ })),
106
+ };
107
+ }),
108
+ ),
109
+ Effect.catchTag('NotAuthedError', (e) =>
110
+ Effect.gen(function* () {
111
+ if (coerce) {
112
+ const loginResult = yield* loginCommand({});
113
+ const authStateRef = yield* Ref.make<AuthTokenState>(loginResult);
114
+ return {
115
+ getAuthToken: Ref.get(authStateRef).pipe(
116
+ Effect.map((authState) => authState.authToken),
117
+ ),
118
+ getSource: Ref.get(authStateRef).pipe(
119
+ Effect.map((authState) => authState.source),
120
+ ),
121
+ setAuthToken: (authToken: string, source?: AuthTokenSource) =>
122
+ Ref.update(authStateRef, (authState) => ({
123
+ ...authState,
124
+ authToken,
125
+ source: source ?? authState.source,
126
+ })),
127
+ };
128
+ } else {
129
+ return yield* e;
130
+ }
131
+ }),
132
+ ),
133
+ ),
134
+ );
@@ -0,0 +1,301 @@
1
+ import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { Context, Data, Effect, Layer, Runtime, Schema, Option } from 'effect';
4
+ import { UI } from '../ui/index.ts';
5
+ import { handleEnv } from '../lib/handleEnv.ts';
6
+ import { getBaseUrl, InstantHttpAuthed, withCommand } from '../lib/http.ts';
7
+ import { runUIEffect } from '../lib/ui.ts';
8
+ import { AuthToken } from './authToken.ts';
9
+ import { GlobalOpts } from './globalOpts.ts';
10
+ import { PlatformApi } from './platformApi.ts';
11
+ import { readInstantConfigFile } from '../util/instantConfig.ts';
12
+ import { BadArgsError } from '../errors.ts';
13
+
14
+ export type CurrentAppInfo = {
15
+ appId: string;
16
+ adminToken?: string;
17
+ source: 'create' | 'import' | 'env' | 'flag' | 'ephemeral';
18
+ };
19
+
20
+ export class CurrentApp extends Context.Tag(
21
+ 'instant-cli/new/context/currentApp',
22
+ )<CurrentApp, CurrentAppInfo>() {}
23
+
24
+ function isUUID(uuid: string) {
25
+ const uuidRegex =
26
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
27
+ return uuidRegex.test(uuid);
28
+ }
29
+
30
+ export class CurrentAppContextError extends Data.TaggedError(
31
+ 'CurrentAppContextError',
32
+ )<{
33
+ message: string;
34
+ }> {}
35
+
36
+ export class AppNotFoundError extends Data.TaggedError('AppNotFoundError')<{
37
+ message: string;
38
+ }> {}
39
+
40
+ export const potentialEnvs: Record<string, string> = {
41
+ catchall: 'INSTANT_APP_ID',
42
+ next: 'NEXT_PUBLIC_INSTANT_APP_ID',
43
+ svelte: 'PUBLIC_INSTANT_APP_ID',
44
+ vite: 'VITE_INSTANT_APP_ID',
45
+ expo: 'EXPO_PUBLIC_INSTANT_APP_ID',
46
+ nuxt: 'NUXT_PUBLIC_INSTANT_APP_ID',
47
+ bun: 'BUN_PUBLIC_INSTANT_APP_ID',
48
+ };
49
+
50
+ const potentialAdminTokenEnvs = {
51
+ default: 'INSTANT_APP_ADMIN_TOKEN',
52
+ short: 'INSTANT_ADMIN_TOKEN',
53
+ } as const;
54
+
55
+ // TODO: add instant.config.ts support
56
+ export const CurrentAppLive = (args: {
57
+ appId?: string;
58
+ coerce?: boolean;
59
+ title?: string;
60
+ applyEnv?: boolean;
61
+ temp?: boolean;
62
+ }) =>
63
+ Layer.effect(
64
+ CurrentApp,
65
+ Effect.gen(function* () {
66
+ if (args.appId) {
67
+ if (isUUID(args.appId)) {
68
+ return {
69
+ appId: args.appId,
70
+ source: 'flag' as const,
71
+ };
72
+ } else {
73
+ // Check for instant.config.ts
74
+ const config = yield* Effect.tryPromise(() =>
75
+ readInstantConfigFile(),
76
+ );
77
+ if (!config) {
78
+ return yield* new BadArgsError({
79
+ message: `App ID provided (${args.appId}) is not valid UUID`,
80
+ });
81
+ }
82
+ const nameMatch = config?.apps?.[args.appId];
83
+ if (!nameMatch?.id) {
84
+ return yield* BadArgsError.make({
85
+ message: 'App ID not found in app inside instant.config.ts',
86
+ });
87
+ }
88
+ if (nameMatch) {
89
+ return {
90
+ appId: nameMatch.id,
91
+ source: 'flag' as const,
92
+ };
93
+ }
94
+ }
95
+ }
96
+
97
+ // Detect from ENV
98
+ const found = Object.keys(potentialEnvs)
99
+ .map((type) => {
100
+ const envName = potentialEnvs[type];
101
+ const value = process.env[envName];
102
+ return { type, envName, value };
103
+ })
104
+ .find(({ value }) => !!value);
105
+
106
+ if (found?.value && !isUUID(found.value)) {
107
+ return yield* new CurrentAppContextError({
108
+ message: `Invalid UUID: ${found.value}`,
109
+ });
110
+ } else if (found?.value) {
111
+ // try to get admin token
112
+ const adminToken = yield* getAdminToken;
113
+ return {
114
+ adminToken: Option.getOrUndefined(adminToken),
115
+ appId: found?.value,
116
+ source: 'env' as const,
117
+ };
118
+ }
119
+ return yield* new AppNotFoundError({
120
+ message: 'No app found',
121
+ });
122
+ }).pipe(
123
+ // coerce into new app if app not found
124
+ Effect.catchTag('AppNotFoundError', () =>
125
+ Effect.gen(function* () {
126
+ if (!args.coerce)
127
+ return yield* new AppNotFoundError({ message: 'No app found' });
128
+
129
+ // coerce into a temporary app
130
+ if (args.temp) {
131
+ const title = args.title ?? 'temp';
132
+ yield* Effect.log(`Creating temporary app with title: ${title}`);
133
+ const app = yield* createTemporaryApp(title);
134
+ const authToken = yield* AuthToken;
135
+ yield* authToken.setAuthToken(app.adminToken!, 'admin');
136
+ return app;
137
+ }
138
+
139
+ // coerce into a new app
140
+ const globalOpts = yield* GlobalOpts;
141
+ if (globalOpts.yes) {
142
+ if (!args.title) {
143
+ return yield* new CurrentAppContextError({
144
+ message: `If you provide --yes, you must provide a --title flag.`,
145
+ });
146
+ } else {
147
+ yield* Effect.log(`Creating app with title: ${args.title}`);
148
+ return yield* createApp(args.title);
149
+ }
150
+ }
151
+
152
+ return yield* promptImportOrCreateApp;
153
+ }),
154
+ ),
155
+
156
+ // Handle save env
157
+ Effect.tap((app) =>
158
+ Effect.gen(function* () {
159
+ if (
160
+ args.applyEnv &&
161
+ (app.source === 'import' ||
162
+ app.source === 'create' ||
163
+ app.source == 'ephemeral')
164
+ ) {
165
+ yield* handleEnv(app);
166
+ }
167
+ }),
168
+ ),
169
+ ),
170
+ );
171
+
172
+ const createTemporaryApp = Effect.fn(function* (title: string) {
173
+ const platform = yield* PlatformApi;
174
+ const response = yield* platform.use(
175
+ (p) => p.createTemporaryApp({ title }),
176
+ 'Error creating temporary app',
177
+ );
178
+ return {
179
+ appId: response.app.id,
180
+ source: 'ephemeral',
181
+ adminToken: response.app.adminToken,
182
+ } satisfies CurrentAppInfo;
183
+ });
184
+
185
+ const createApp = Effect.fn(function* (title: string, orgId?: string) {
186
+ const id = randomUUID();
187
+ const token = randomUUID();
188
+ const app = { id, title, admin_token: token, org_id: orgId };
189
+
190
+ const http = yield* InstantHttpAuthed;
191
+ yield* HttpClientRequest.post('/dash/apps').pipe(
192
+ HttpClientRequest.bodyJson(app),
193
+ Effect.flatMap(http.execute),
194
+ );
195
+ return {
196
+ appId: id,
197
+ source: 'create',
198
+ adminToken: token,
199
+ } satisfies CurrentAppInfo;
200
+ });
201
+
202
+ const promptImportOrCreateApp = Effect.gen(function* () {
203
+ const api = yield* getSimpleApi;
204
+ const result = yield* runUIEffect(
205
+ new UI.AppSelector({
206
+ startingMenuIndex: 0,
207
+ allowEphemeral: true,
208
+ allowCreate: true,
209
+ api,
210
+ }),
211
+ );
212
+
213
+ if (result.approach === 'ephemeral') {
214
+ const authToken = yield* AuthToken;
215
+ yield* authToken.setAuthToken(result.adminToken, 'admin');
216
+ }
217
+
218
+ if (result.approach === 'import') {
219
+ yield* Effect.fork(trackAppImport(result.appId));
220
+ }
221
+
222
+ return {
223
+ appId: result.appId,
224
+ source: result.approach,
225
+ adminToken: result.adminToken,
226
+ } satisfies CurrentAppInfo;
227
+ });
228
+
229
+ const getSimpleApi = Effect.gen(function* () {
230
+ const effectRuntime = yield* Effect.runtime<never>();
231
+
232
+ const http = yield* InstantHttpAuthed;
233
+ const dashData = yield* http
234
+ .get('/dash')
235
+ .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
236
+ const platform = yield* PlatformApi;
237
+
238
+ const baseUrl = yield* getBaseUrl;
239
+ const authToken = yield* AuthToken;
240
+
241
+ return {
242
+ getDash: () => dashData,
243
+ createApp: async (title, orgId) => {
244
+ return Runtime.runPromise(
245
+ effectRuntime,
246
+ createApp(title, orgId).pipe(
247
+ Effect.provideService(InstantHttpAuthed, http),
248
+ ),
249
+ );
250
+ },
251
+
252
+ createEphemeralApp: async (title) => {
253
+ return await Runtime.runPromise(
254
+ effectRuntime,
255
+ Effect.gen(function* () {
256
+ const platform = yield* PlatformApi;
257
+ const response = yield* platform.use(
258
+ (p) => p.createTemporaryApp({ title: title }),
259
+ 'Error creating temporary app',
260
+ );
261
+ return {
262
+ appId: response.app.id,
263
+ adminToken: response.app.adminToken,
264
+ };
265
+ }).pipe(Effect.provideService(PlatformApi, platform)),
266
+ );
267
+ },
268
+
269
+ async getAppsForOrg(orgId) {
270
+ const token = await Runtime.runPromise(
271
+ effectRuntime,
272
+ authToken.getAuthToken,
273
+ );
274
+ const response = await fetch(baseUrl + '/dash/orgs/' + orgId, {
275
+ headers: {
276
+ Authorization: `Bearer ${token}`,
277
+ },
278
+ });
279
+ const data = await response.json();
280
+ return { apps: data.apps };
281
+ },
282
+ } satisfies UI.AppSelectorApi;
283
+ });
284
+
285
+ const getAdminToken = Effect.gen(function* () {
286
+ const found = Object.keys(potentialAdminTokenEnvs)
287
+ .map((type) => {
288
+ const envName =
289
+ potentialAdminTokenEnvs[type as keyof typeof potentialAdminTokenEnvs];
290
+ const value = process.env[envName];
291
+ return { type, envName, value };
292
+ })
293
+ .find(({ value }) => !!value);
294
+ return Option.fromNullable(found?.value);
295
+ });
296
+
297
+ const trackAppImport = (appId: string) =>
298
+ Effect.gen(function* () {
299
+ const http = (yield* InstantHttpAuthed).pipe(withCommand('init'));
300
+ yield* http.post(`/dash/apps/${appId}/track-import`);
301
+ });
@@ -0,0 +1,22 @@
1
+ import { Context, Layer } from 'effect';
2
+ import { program } from '../program.ts';
3
+
4
+ export class GlobalOpts extends Context.Tag(
5
+ 'instant-cli/new/context/globalOpts',
6
+ )<
7
+ GlobalOpts,
8
+ {
9
+ token?: string;
10
+ yes: boolean;
11
+ env?: string;
12
+ }
13
+ >() {}
14
+
15
+ export const GlobalOptsLive = Layer.sync(GlobalOpts, () => {
16
+ const opts = program.optsWithGlobals() as Record<string, any>;
17
+ return {
18
+ yes: opts?.yes || false,
19
+ token: opts?.token,
20
+ env: opts?.env,
21
+ };
22
+ });
@@ -0,0 +1,35 @@
1
+ import { PlatformApi as InstantPlatformApi } from '@instantdb/platform';
2
+ import { Data, Effect } from 'effect';
3
+ import { getBaseUrl } from '../lib/http.ts';
4
+
5
+ export class PlatformApiError extends Data.TaggedError('PlatformApiError')<{
6
+ message: string;
7
+ cause: unknown;
8
+ }> {}
9
+
10
+ export class PlatformApi extends Effect.Service<PlatformApi>()(
11
+ 'instant-cli/new/context/platformApi',
12
+ {
13
+ effect: Effect.gen(function* () {
14
+ const origin = yield* getBaseUrl;
15
+ const apiClient = new InstantPlatformApi({
16
+ apiURI: origin,
17
+ });
18
+
19
+ return {
20
+ use: <R>(
21
+ fun: (api: typeof apiClient) => Promise<R>,
22
+ errorMessage?: string,
23
+ ) =>
24
+ Effect.tryPromise({
25
+ try: (_signal) => fun(apiClient),
26
+ catch: (e) =>
27
+ new PlatformApiError({
28
+ message: errorMessage || 'Error using platform api',
29
+ cause: e,
30
+ }),
31
+ }),
32
+ };
33
+ }),
34
+ },
35
+ ) {}
@@ -0,0 +1,219 @@
1
+ import { Context, Data, Effect, Layer } from 'effect';
2
+ import { detect } from 'package-manager-detector/detect';
3
+ import { readPackage } from 'pkg-types';
4
+ import type { PackageJson } from 'pkg-types';
5
+ import { exec } from 'node:child_process';
6
+ import { promisify } from 'node:util';
7
+ import { UI } from '../ui/index.ts';
8
+ import { findProjectDir } from '../util/projectDir.ts';
9
+ import { runUIEffect } from '../lib/ui.ts';
10
+ import chalk from 'chalk';
11
+ import { GlobalOpts } from './globalOpts.ts';
12
+ import { BadArgsError } from '../errors.ts';
13
+ import { sdkInstallSpec } from '../util/sdkInstallSpec.ts';
14
+
15
+ export class ProjectInfo extends Context.Tag(
16
+ 'instant-cli/new/context/projectInfo',
17
+ )<
18
+ ProjectInfo,
19
+ {
20
+ pkgDir: string;
21
+ projectType: 'node' | 'deno' | 'python';
22
+ instantModuleName: string;
23
+ }
24
+ >() {}
25
+
26
+ const execAsync = promisify(exec);
27
+
28
+ export const PACKAGE_ALIAS_AND_FULL_NAMES = {
29
+ react: '@instantdb/react',
30
+ 'react-native': '@instantdb/react-native',
31
+ core: '@instantdb/core',
32
+ admin: '@instantdb/admin',
33
+ solid: '@instantdb/solidjs',
34
+ svelte: '@instantdb/svelte',
35
+ vue: '@instantdb/vue',
36
+ };
37
+
38
+ export class ProjectInfoError extends Data.TaggedError('ProjectInfoError')<{
39
+ message: string;
40
+ cause?: unknown;
41
+ }> {}
42
+
43
+ const getProjectInfo = (
44
+ coerce: boolean = true,
45
+ packageName?: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,
46
+ ) =>
47
+ Effect.gen(function* () {
48
+ const projectDir = yield* Effect.tryPromise({
49
+ try: () => findProjectDir(),
50
+ catch: (e) =>
51
+ new ProjectInfoError({ message: "Couldn't get project dir" }),
52
+ });
53
+
54
+ if (!projectDir) {
55
+ return yield* new ProjectInfoError({
56
+ message:
57
+ "Couldn't find a project directory. Is there a package.json, deno.json, or pyproject.toml file?",
58
+ });
59
+ }
60
+
61
+ if (projectDir.type === 'deno' || projectDir.type === 'python') {
62
+ return {
63
+ pkgDir: projectDir.dir,
64
+ projectType: projectDir.type,
65
+ instantModuleName: '@instantdb/core',
66
+ };
67
+ }
68
+
69
+ const pkgJson = yield* Effect.tryPromise({
70
+ try: () => readPackage(),
71
+ catch: () =>
72
+ new ProjectInfoError({
73
+ message:
74
+ "We couldn't find an Instant SDK. Install one, or run `init`",
75
+ }),
76
+ });
77
+
78
+ yield* Effect.log('Checking for an Instant SDK...');
79
+ let moduleName = getInstantModuleName(pkgJson);
80
+ if (!moduleName && !coerce) {
81
+ return yield* new ProjectInfoError({
82
+ message: "We couldn't find an Instant SDK. Install one, or run `init`",
83
+ });
84
+ }
85
+
86
+ if (!moduleName && coerce) {
87
+ yield* Effect.log(
88
+ "Couldn't find an Instant SDK in your package.json, let's install one!",
89
+ );
90
+ } else {
91
+ yield* Effect.log(
92
+ `Found ${chalk.green(moduleName)} in your package.json.\n`,
93
+ );
94
+ }
95
+
96
+ // TODO: Clean up with option
97
+ const packageManager = yield* Effect.tryPromise(() => detect()).pipe(
98
+ Effect.flatMap(Effect.fromNullable),
99
+ Effect.catchTag('NoSuchElementException', () =>
100
+ Effect.succeed({
101
+ name: 'npm',
102
+ agent: 'npm',
103
+ }),
104
+ ),
105
+ Effect.option,
106
+ );
107
+
108
+ const { yes } = yield* GlobalOpts;
109
+ if (!moduleName && coerce) {
110
+ // install the packages
111
+ if (packageName) {
112
+ moduleName = PACKAGE_ALIAS_AND_FULL_NAMES[packageName];
113
+ } else {
114
+ if (yes) {
115
+ return yield* BadArgsError.make({
116
+ message:
117
+ '--yes was provided without a package specification and no Instant SDK was found',
118
+ });
119
+ }
120
+ moduleName = yield* runUIEffect(
121
+ new UI.Select({
122
+ promptText: 'Which package would you like to use?',
123
+ options: [
124
+ { label: '@instantdb/react', value: '@instantdb/react' },
125
+ {
126
+ label: '@instantdb/react-native',
127
+ value: '@instantdb/react-native',
128
+ },
129
+ { label: '@instantdb/core', value: '@instantdb/core' },
130
+ { label: '@instantdb/admin', value: '@instantdb/admin' },
131
+ { label: '@instantdb/solidjs', value: '@instantdb/solidjs' },
132
+ { label: '@instantdb/svelte', value: '@instantdb/svelte' },
133
+ { label: '@instantdb/vue', value: '@instantdb/vue' },
134
+ ],
135
+ }),
136
+ ).pipe(
137
+ Effect.flatMap(Effect.fromNullable),
138
+ Effect.mapError(
139
+ () =>
140
+ new ProjectInfoError({
141
+ message: 'Failed to select package',
142
+ }),
143
+ ),
144
+ );
145
+ }
146
+ const packagesToInstall = [moduleName];
147
+ if (moduleName === '@instantdb/react-native') {
148
+ packagesToInstall.push(
149
+ 'react-native-get-random-values',
150
+ '@react-native-async-storage/async-storage',
151
+ );
152
+ }
153
+
154
+ const pkgManager = yield* packageManager.pipe(
155
+ Effect.mapError(
156
+ (e) =>
157
+ new ProjectInfoError({
158
+ message: 'Failed to detect package manager',
159
+ cause: e,
160
+ }),
161
+ ),
162
+ );
163
+
164
+ const installCommand = getInstallCommand(
165
+ pkgManager.agent,
166
+ packagesToInstall.map((p) => sdkInstallSpec(p)).join(' '),
167
+ );
168
+ yield* Effect.log(installCommand);
169
+ yield* runUIEffect(
170
+ new UI.Spinner({
171
+ promise: execAsync(installCommand, {
172
+ cwd: projectDir.dir,
173
+ }),
174
+ errorText: 'Failed to install packages',
175
+ workingText: `Installing ${packagesToInstall.join(', ')} using ${pkgManager.agent}...`,
176
+ doneText: `Installed ${packagesToInstall.join(', ')} using ${pkgManager.agent}.`,
177
+ }),
178
+ );
179
+ return {
180
+ pkgDir: projectDir.dir,
181
+ projectType: projectDir.type,
182
+ instantModuleName: moduleName,
183
+ };
184
+ } else {
185
+ return {
186
+ pkgDir: projectDir.dir,
187
+ projectType: projectDir.type,
188
+ instantModuleName: moduleName!,
189
+ };
190
+ }
191
+ });
192
+
193
+ export const ProjectInfoLive = (
194
+ coerce: boolean = true,
195
+ packageName?: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,
196
+ ) => Layer.effect(ProjectInfo, getProjectInfo(coerce, packageName));
197
+
198
+ function getInstantModuleName(pkgJson: PackageJson) {
199
+ const deps = pkgJson.dependencies || {};
200
+ const devDeps = pkgJson.devDependencies || {};
201
+ const instantModuleName = [
202
+ '@instantdb/react',
203
+ '@instantdb/react-native',
204
+ '@instantdb/core',
205
+ '@instantdb/admin',
206
+ '@instantdb/solidjs',
207
+ '@instantdb/svelte',
208
+ '@instantdb/vue',
209
+ ].find((name) => deps[name] || devDeps[name]);
210
+ return instantModuleName;
211
+ }
212
+
213
+ function getInstallCommand(packageManager: string, moduleName: string) {
214
+ if (packageManager === 'npm') {
215
+ return `npm install ${moduleName}`;
216
+ } else {
217
+ return `${packageManager} add ${moduleName}`;
218
+ }
219
+ }