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

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,188 @@
1
+ import { createWriteStream } from 'node:fs';
2
+ import { open, rename, unlink } from 'node:fs/promises';
3
+ import { randomBytes } from 'node:crypto';
4
+ import { once } from 'node:events';
5
+ import { get as httpGet, type IncomingMessage } from 'node:http';
6
+ import { get as httpsGet } from 'node:https';
7
+ import { Readable, Writable, type Duplex } from 'node:stream';
8
+ import zlib from 'node:zlib';
9
+ import type {
10
+ AppBackup,
11
+ BackupArchiveWriter,
12
+ BackupDownloadProgress,
13
+ BackupDownloadResult,
14
+ BackupsManager,
15
+ } from '@instantdb/platform';
16
+ import version from '../version.js';
17
+
18
+ // Set a user-agent or else cloudfront might block the request
19
+ const userAgent = `instant-cli/${version}`;
20
+
21
+ export type {
22
+ BackupDownloadProgress,
23
+ BackupDownloadResult,
24
+ } from '@instantdb/platform';
25
+
26
+ // zstd landed in node:zlib in 22.15 / 23.8; on older Nodes the property is
27
+ // absent, so feature-detect instead of assuming the type declarations match
28
+ // the runtime.
29
+ const createZstdDecompress: (() => Duplex) | undefined = (
30
+ zlib as { createZstdDecompress?: () => Duplex }
31
+ ).createZstdDecompress;
32
+
33
+ function fetchStream(
34
+ url: string,
35
+ signal: AbortSignal,
36
+ ): Promise<IncomingMessage> {
37
+ return new Promise((resolve, reject) => {
38
+ const get = url.startsWith('https:') ? httpsGet : httpGet;
39
+ const req = get(
40
+ url,
41
+ { signal, headers: { 'user-agent': userAgent } },
42
+ resolve,
43
+ );
44
+ req.on('error', reject);
45
+ });
46
+ }
47
+
48
+ // .pipe doesn't forward errors, so a source failure would otherwise leave the
49
+ // destination (and the zip writer reading from it) hanging forever.
50
+ function pipe(src: Readable, dst: Duplex): Duplex {
51
+ src.on('error', (e) => dst.destroy(e));
52
+ return src.pipe(dst);
53
+ }
54
+
55
+ // S3/CloudFront answer a rejected presigned URL with a short XML body naming
56
+ // the actual cause (SignatureDoesNotMatch, AccessDenied, expired, …). Read a
57
+ // bounded prefix so the error surfaces the reason instead of a bare status.
58
+ async function readErrorBody(
59
+ res: IncomingMessage,
60
+ signal: AbortSignal,
61
+ ): Promise<string> {
62
+ // A stalled or dribbling error body must not hang the download; destroying
63
+ // res ends the read below. The request's own signal already tears res down
64
+ // on a caller abort, so this only guards the no-abort stall.
65
+ const timer = setTimeout(() => res.destroy(), 5000);
66
+ try {
67
+ const chunks: Buffer[] = [];
68
+ let total = 0;
69
+ for await (const chunk of res) {
70
+ chunks.push(chunk as Buffer);
71
+ total += (chunk as Buffer).length;
72
+ if (total >= 2048) break;
73
+ }
74
+ return Buffer.concat(chunks)
75
+ .toString('utf8')
76
+ .replace(/\s+/g, ' ')
77
+ .trim()
78
+ .slice(0, 500);
79
+ } catch (e) {
80
+ // A caller-initiated abort must propagate, not be masked as an empty body;
81
+ // only other read failures fall back to no reason.
82
+ if (signal.aborted) throw e;
83
+ return '';
84
+ } finally {
85
+ clearTimeout(timer);
86
+ res.destroy();
87
+ }
88
+ }
89
+
90
+ // Fetches a presigned URL with node:http(s), decompressing explicitly: the
91
+ // entity shards are served with `Content-Encoding: zstd` and Node doesn't
92
+ // auto-decompress that. downloadBackupToFile refuses to run without zstd
93
+ // support, so the assertion below can't fire.
94
+ async function fetchBody(
95
+ url: string,
96
+ signal: AbortSignal,
97
+ ): Promise<ReadableStream<Uint8Array>> {
98
+ const res = await fetchStream(url, signal);
99
+ if (res.statusCode !== 200) {
100
+ const body = await readErrorBody(res, signal);
101
+ throw new Error(`HTTP ${res.statusCode}${body ? ` — ${body}` : ''}`);
102
+ }
103
+ const encoding = res.headers['content-encoding'];
104
+ let stream: Readable = res;
105
+ if (encoding === 'zstd') {
106
+ stream = pipe(stream, createZstdDecompress!());
107
+ } else if (encoding === 'gzip') {
108
+ stream = pipe(stream, zlib.createGunzip());
109
+ } else if (encoding) {
110
+ res.destroy();
111
+ throw new Error(`Unsupported content encoding: ${encoding}`);
112
+ }
113
+ return Readable.toWeb(stream) as ReadableStream<Uint8Array>;
114
+ }
115
+
116
+ async function createZipWriter(
117
+ sink: WritableStream<Uint8Array>,
118
+ signal: AbortSignal,
119
+ ): Promise<BackupArchiveWriter> {
120
+ // Loaded on demand so every other CLI command skips parsing it.
121
+ const { ZipWriter } = await import('@zip.js/zip.js');
122
+ // zip64: without it any archive whose central-directory offset passes 4GB
123
+ // writes a wrapped 32-bit offset and the zip is unreadable.
124
+ return new ZipWriter(sink, { zip64: true, signal });
125
+ }
126
+
127
+ /**
128
+ * Downloads a backup into a zip file at `outPath` via the shared
129
+ * `BackupsManager.downloadArchive` pipeline, supplying the Node-specific
130
+ * pieces:
131
+ * presigned URLs are fetched with node:http(s) and decompressed explicitly,
132
+ * and the archive streams to disk with backpressure so memory stays flat
133
+ * regardless of backup size.
134
+ *
135
+ * Writes to `<outPath>.partial` and renames on success; a failed or aborted
136
+ * download removes the partial file.
137
+ */
138
+ export async function downloadBackupToFile(opts: {
139
+ manager: BackupsManager;
140
+ backup: AppBackup;
141
+ outPath: string;
142
+ signal: AbortSignal;
143
+ onProgress: (progress: BackupDownloadProgress) => void;
144
+ }): Promise<BackupDownloadResult> {
145
+ // The entity shards are served with `Content-Encoding: zstd`; fail before
146
+ // writing anything if this Node can't decompress them.
147
+ if (!createZstdDecompress) {
148
+ throw new Error(
149
+ 'Downloading backups requires Node 22.15 or newer (for zstd support).',
150
+ );
151
+ }
152
+
153
+ // Randomized so a stale partial or a concurrent download of the same
154
+ // backup can't collide; 'wx' turns any remaining collision into an error
155
+ // instead of silently truncating another run's file.
156
+ const partialPath = `${opts.outPath}.partial-${randomBytes(4).toString('hex')}`;
157
+ const fileStream = createWriteStream(partialPath, { flags: 'wx' });
158
+ const awaitFileClosed = async () => {
159
+ if (!fileStream.closed) await once(fileStream, 'close');
160
+ };
161
+ try {
162
+ const result = await opts.manager.downloadArchive({
163
+ backup: opts.backup,
164
+ fetchBody,
165
+ sink: Writable.toWeb(fileStream) as WritableStream<Uint8Array>,
166
+ createWriter: createZipWriter,
167
+ signal: opts.signal,
168
+ onProgress: opts.onProgress,
169
+ });
170
+ await awaitFileClosed();
171
+ // Flush to disk before the rename so a crash right after can't leave a
172
+ // complete-looking zip with unwritten tails.
173
+ const fh = await open(partialPath, 'r+');
174
+ try {
175
+ await fh.sync();
176
+ } finally {
177
+ await fh.close();
178
+ }
179
+ await rename(partialPath, opts.outPath);
180
+ return result;
181
+ } catch (e) {
182
+ // The pipeline already aborted the sink; wait for the fd to close, then
183
+ // discard the partial file on disk.
184
+ await awaitFileClosed().catch(() => {});
185
+ await unlink(partialPath).catch(() => {});
186
+ throw e;
187
+ }
188
+ }
@@ -0,0 +1,33 @@
1
+ import { Effect } from 'effect';
2
+ import type { BackupsManager } from '@instantdb/platform';
3
+ import { CurrentApp } from '../context/currentApp.ts';
4
+ import { PlatformApiError } from '../context/platformApi.ts';
5
+ import { getAuthedPlatformApi } from './platformApi.ts';
6
+
7
+ export const useBackupsManager = <R>(
8
+ fun: (manager: BackupsManager) => Promise<R>,
9
+ errorMessage?: string,
10
+ ) =>
11
+ Effect.gen(function* () {
12
+ const api = yield* getAuthedPlatformApi;
13
+ const { appId } = yield* CurrentApp;
14
+ return yield* Effect.tryPromise({
15
+ try: () => fun(api.backups(appId)),
16
+ catch: (e) =>
17
+ new PlatformApiError({
18
+ message: errorMessage ?? 'Error using backups api',
19
+ cause: e,
20
+ }),
21
+ });
22
+ });
23
+
24
+ /**
25
+ * Yields a `BackupsManager` instance scoped to the current app. Use when you
26
+ * need to hold on to the manager outside an Effect (e.g. to drive the
27
+ * long-running download pipeline).
28
+ */
29
+ export const buildBackupsManager = Effect.gen(function* () {
30
+ const api = yield* getAuthedPlatformApi;
31
+ const { appId } = yield* CurrentApp;
32
+ return api.backups(appId);
33
+ });
@@ -0,0 +1,73 @@
1
+ import { Config, Effect, Option, Schema } from 'effect';
2
+ import { oauthCallbackURL } from '@instantdb/platform';
3
+ import { BadArgsError } from '../errors.ts';
4
+ import { readInstantConfigFile } from '../util/instantConfig.ts';
5
+
6
+ const HttpUrl = Schema.URL.pipe(
7
+ Schema.filter(
8
+ (url) =>
9
+ url.protocol === 'http:' ||
10
+ url.protocol === 'https:' ||
11
+ 'Expected an HTTP(S) URL',
12
+ ),
13
+ );
14
+
15
+ export const getBaseUrl = Effect.gen(function* () {
16
+ const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(
17
+ Config.option,
18
+ );
19
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(
20
+ Config.withDefault(false),
21
+ );
22
+
23
+ if (Option.isSome(setEnv)) {
24
+ return setEnv.value;
25
+ }
26
+
27
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
28
+ if (instantConfig?.apiURI !== undefined) {
29
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(
30
+ Effect.mapError(() =>
31
+ BadArgsError.make({
32
+ message:
33
+ 'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',
34
+ }),
35
+ ),
36
+ );
37
+ return instantConfig.apiURI;
38
+ }
39
+
40
+ return dev ? 'http://localhost:8888' : 'https://api.instantdb.com';
41
+ });
42
+
43
+ export const getOAuthCallbackUrl = getBaseUrl.pipe(
44
+ Effect.map(oauthCallbackURL),
45
+ );
46
+
47
+ export const getDashUrl = Effect.gen(function* () {
48
+ const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(
49
+ Config.option,
50
+ );
51
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(
52
+ Config.withDefault(false),
53
+ );
54
+
55
+ if (Option.isSome(setEnv)) {
56
+ return setEnv.value;
57
+ }
58
+
59
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
60
+ if (instantConfig?.dashURI !== undefined) {
61
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(
62
+ Effect.mapError(() =>
63
+ BadArgsError.make({
64
+ message:
65
+ 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',
66
+ }),
67
+ ),
68
+ );
69
+ return instantConfig.dashURI;
70
+ }
71
+
72
+ return dev ? 'http://localhost:3000' : 'https://instantdb.com';
73
+ });
@@ -0,0 +1,28 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { Data, Effect, Schema } from 'effect';
3
+ import { InstantHttpAuthed } from './http.ts';
4
+ import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
5
+
6
+ export class CreateAppError extends Data.TaggedError('CreateAppError')<{
7
+ message: string;
8
+ }> {}
9
+
10
+ export const createApp = Effect.fn(
11
+ function* (title: string, orgId?: string) {
12
+ const http = yield* InstantHttpAuthed;
13
+ const id = randomUUID();
14
+ const token = randomUUID();
15
+ const app = { id, title, admin_token: token, org_id: orgId };
16
+
17
+ const res = yield* HttpClientRequest.post('/dash/apps').pipe(
18
+ HttpClientRequest.bodyJson(app),
19
+ Effect.flatMap(http.execute),
20
+ Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)),
21
+ );
22
+ return res;
23
+ },
24
+ Effect.catchTag(
25
+ 'HttpBodyError',
26
+ (e) => new CreateAppError({ message: 'Error constructing http body' }),
27
+ ),
28
+ );
@@ -0,0 +1,93 @@
1
+ import { HttpBody, HttpClientResponse } from '@effect/platform';
2
+ import { Effect, Schema } from 'effect';
3
+ import { CurrentApp } from '../context/currentApp.ts';
4
+ import { BadArgsError } from '../errors.ts';
5
+ import { readLocalEmailFile } from '../old.js';
6
+ import { InstantHttpAuthed } from './http.ts';
7
+
8
+ export const EmailConfig = Schema.Struct({
9
+ authEmail: Schema.Struct({
10
+ subject: Schema.String,
11
+ senderName: Schema.String,
12
+ senderEmail: Schema.NullishOr(Schema.String),
13
+ body: Schema.String,
14
+ }),
15
+ });
16
+
17
+ export class NoEmailFileFound extends Schema.TaggedError<NoEmailFileFound>(
18
+ 'NoEmailFileFound',
19
+ )('NoEmailFileFound', {
20
+ message: Schema.String,
21
+ }) {}
22
+
23
+ export const readEmailConfig = (emailPath?: string) =>
24
+ Effect.gen(function* () {
25
+ const emailFile = yield* Effect.tryPromise({
26
+ try: () => readLocalEmailFile(emailPath),
27
+ catch: (e) =>
28
+ BadArgsError.make({
29
+ message: `Error reading instant.email.ts file: ${e}`,
30
+ }),
31
+ });
32
+
33
+ if (!emailFile) {
34
+ return yield* NoEmailFileFound.make({
35
+ message:
36
+ "We couldn't find your `instant.email.ts` file. Make sure it's in the root directory. (Hint: You can use an INSTANT_EMAIL_FILE_PATH environment variable to specify it.)",
37
+ });
38
+ }
39
+
40
+ return yield* Schema.decodeUnknown(EmailConfig)(emailFile.email).pipe(
41
+ Effect.catchTag('ParseError', (e) =>
42
+ BadArgsError.make({
43
+ message: `Invalid instant.email.ts file: ${e.message}`,
44
+ }),
45
+ ),
46
+ );
47
+ });
48
+
49
+ export const sendSenderVerification = Effect.gen(function* () {
50
+ const http = yield* InstantHttpAuthed;
51
+ const { appId } = yield* CurrentApp;
52
+ yield* http.post(`/dash/apps/${appId}/sender-verification/send-magic-code`);
53
+ });
54
+
55
+ export const submitVerification = Effect.fn(function* (code: string) {
56
+ const http = yield* InstantHttpAuthed;
57
+ const { appId } = yield* CurrentApp;
58
+ yield* http.post(
59
+ `/dash/apps/${appId}/sender-verification/verify-magic-code`,
60
+ {
61
+ body: HttpBody.unsafeJson({ code }),
62
+ },
63
+ );
64
+ });
65
+
66
+ const VerificationSchema = Schema.Struct({
67
+ instant: Schema.Struct({
68
+ 'verified?': Schema.Boolean.pipe(Schema.NullishOr),
69
+ }),
70
+ verification: Schema.Struct({
71
+ Confirmed: Schema.Boolean,
72
+ ID: Schema.Number,
73
+ EmailAddress: Schema.String,
74
+ DKIMHost: Schema.String,
75
+ ReturnPathDomain: Schema.String,
76
+ DKIMPendingTextValue: Schema.String,
77
+ ReturnPathDomainCNAMEValue: Schema.String,
78
+ DKIMTextValue: Schema.String,
79
+ DKIMPendingHost: Schema.String,
80
+ }).pipe(Schema.NullishOr),
81
+ });
82
+
83
+ export const getVerification = Effect.gen(function* () {
84
+ const http = yield* InstantHttpAuthed;
85
+ const { appId } = yield* CurrentApp;
86
+
87
+ const response = yield* http
88
+ .get(`/dash/apps/${appId}/sender-verification`)
89
+ .pipe(
90
+ Effect.flatMap(HttpClientResponse.schemaBodyJson(VerificationSchema)),
91
+ );
92
+ return response;
93
+ });
@@ -0,0 +1,122 @@
1
+ import { Effect } from 'effect';
2
+ import { potentialEnvs } from '../context/currentApp.ts';
3
+ import type { CurrentAppInfo } from '../context/currentApp.ts';
4
+ import { ProjectInfo, ProjectInfoError } from '../context/projectInfo.ts';
5
+ import { readPackage } from 'pkg-types';
6
+ import { GlobalOpts } from '../context/globalOpts.ts';
7
+ import { FileSystem, Path } from '@effect/platform';
8
+ import chalk from 'chalk';
9
+ import { getDashUrl } from './http.ts';
10
+ import { promptOk } from './ui.ts';
11
+ import { link } from '../logging.ts';
12
+ import boxen from 'boxen';
13
+
14
+ export const handleEnv = Effect.fn(function* (app: CurrentAppInfo) {
15
+ const opts = yield* GlobalOpts;
16
+ const { pkgDir } = yield* ProjectInfo;
17
+ const envType = yield* detectEnvType;
18
+ const envName = potentialEnvs[envType];
19
+ const envFile = opts.env ?? '.env';
20
+ const fs = yield* FileSystem.FileSystem;
21
+ const path = yield* Path.Path;
22
+ const hasEnvFile = yield* fs.exists(path.join(pkgDir, envFile));
23
+ const dashOrigin = yield* getDashUrl;
24
+ if (hasEnvFile) {
25
+ return printDotEnvInfo(envType, app.appId, dashOrigin);
26
+ }
27
+ const saveExtraInfo =
28
+ envFile !== '.env' ? chalk.green(' (will create `' + envFile + '`)') : '';
29
+ const promptText = [
30
+ `Looks like you don't have a ${chalk.green(`\`${envFile}\``)} file yet.`,
31
+ `If we set ${chalk.green(envName)} & ${chalk.green('INSTANT_APP_ADMIN_TOKEN')}, we can remember the app that you chose for all`,
32
+ 'future commands.',
33
+ 'Want us to create this env file for you?' + saveExtraInfo,
34
+ ].join('\n');
35
+
36
+ const ok = yield* promptOk(
37
+ {
38
+ inline: true,
39
+ promptText,
40
+ modifyOutput: (a) =>
41
+ boxen(a, {
42
+ dimBorder: true,
43
+ padding: { left: 1, right: 1 },
44
+ }),
45
+ },
46
+ true,
47
+ );
48
+ if (!ok) {
49
+ yield* Effect.log(
50
+ `No .env file created. You can always set ${chalk.green('`' + envName + '`')} later. \n`,
51
+ );
52
+ return;
53
+ }
54
+ const content =
55
+ [
56
+ [envName, app.appId],
57
+ ['INSTANT_APP_ADMIN_TOKEN', app.adminToken],
58
+ ]
59
+ .map(([k, v]) => `${k}=${v}`)
60
+ .join('\n') + '\n';
61
+
62
+ yield* fs.writeFileString(path.join(pkgDir, envFile), content);
63
+
64
+ if (envFile !== '.env') {
65
+ yield* Effect.log(`Created ${chalk.green(envFile)}!`);
66
+ } else {
67
+ yield* Effect.log(`Created ${chalk.green('.env')} file!`);
68
+ }
69
+ });
70
+
71
+ const detectEnvType = Effect.gen(function* () {
72
+ const pkgJson = yield* Effect.tryPromise({
73
+ try: () => readPackage(),
74
+ catch: () =>
75
+ new ProjectInfoError({ message: "Couldn't read package.json" }),
76
+ });
77
+ if (pkgJson.dependencies?.next) {
78
+ return 'next';
79
+ }
80
+ if (pkgJson.devDependencies?.svelte) {
81
+ return 'svelte';
82
+ }
83
+ if (pkgJson.devDependencies?.vite) {
84
+ return 'vite';
85
+ }
86
+ if (pkgJson.dependencies?.expo) {
87
+ return 'expo';
88
+ }
89
+ if (pkgJson.dependencies?.nuxt) {
90
+ return 'nuxt';
91
+ }
92
+ if (pkgJson.dependencies?.['@types/bun']) {
93
+ return 'bun';
94
+ }
95
+ return 'catchall';
96
+ }).pipe(Effect.catchTag('ProjectInfoError', () => Effect.succeed('catchall')));
97
+
98
+ function printDotEnvInfo(
99
+ envType: keyof typeof potentialEnvs,
100
+ appId: string,
101
+ dashOrigin: string,
102
+ ) {
103
+ console.log(`\nPicked app ${chalk.green(appId)}!\n`);
104
+ console.log(
105
+ `To use this app automatically from now on, update your ${chalk.green('`.env`')} file:`,
106
+ );
107
+ const picked = potentialEnvs[envType];
108
+ const rest = { ...potentialEnvs };
109
+ delete rest[envType];
110
+ console.log(` ${chalk.green(picked)}=${appId}`);
111
+ const otherEnvs = Object.values(rest);
112
+ otherEnvs.sort();
113
+ const otherEnvStr = otherEnvs.map((x) => ' ' + chalk.green(x)).join('\n');
114
+ console.log(`Alternative names: \n${otherEnvStr} \n`);
115
+ console.log(
116
+ `${link(appDashUrl(appId, dashOrigin))}: ${appDashUrl(appId, dashOrigin)}\n`,
117
+ );
118
+ }
119
+
120
+ function appDashUrl(id: string, instantOrigin: string) {
121
+ return `${instantOrigin}/dash?s=main&t=home&app=${id}`;
122
+ }
@@ -0,0 +1,128 @@
1
+ import { HttpClient, HttpClientRequest } from '@effect/platform';
2
+ import { version } from '@instantdb/version';
3
+ import { Context, Data, Effect, Layer, Schema } from 'effect';
4
+ import { AuthToken } from '../context/authToken.ts';
5
+ import { TimeoutException } from 'effect/Cause';
6
+ import { RequestError } from '@effect/platform/HttpClientError';
7
+ import { getBaseUrl } from './config.ts';
8
+
9
+ export { getBaseUrl, getDashUrl } from './config.ts';
10
+
11
+ export class InstantHttp extends Context.Tag(
12
+ 'instant-cli/new/lib/http/InstantHttp',
13
+ )<
14
+ InstantHttp,
15
+ HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>
16
+ >() {}
17
+
18
+ export class InstantHttpAuthed extends Context.Tag(
19
+ 'instant-cli/new/lib/http/InstantHttpAuthed',
20
+ )<
21
+ InstantHttpAuthed,
22
+ HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>
23
+ >() {}
24
+
25
+ export class InstantHttpError extends Data.TaggedError('InstantHttpError')<
26
+ {
27
+ methodAndUrl: string;
28
+ } & typeof InstantTypicalHttpErrorResponse.Type
29
+ > {}
30
+
31
+ // Pipe on an http client to set the command header
32
+ export const withCommand = (command: string) => {
33
+ return (
34
+ client: HttpClient.HttpClient.With<
35
+ InstantHttpError | TimeoutException | RequestError
36
+ >,
37
+ ) =>
38
+ client.pipe(
39
+ HttpClient.mapRequest((r) =>
40
+ r.pipe(HttpClientRequest.setHeader(`X-Instant-Command`, command)),
41
+ ),
42
+ );
43
+ };
44
+
45
+ class InstantTypicalHttpErrorResponse extends Schema.Struct({
46
+ message: Schema.String,
47
+ type: Schema.String.pipe(Schema.optional),
48
+ hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(
49
+ Schema.optional,
50
+ ),
51
+ }) {}
52
+
53
+ export const InstantHttpLive = Layer.effect(
54
+ InstantHttp,
55
+ Effect.gen(function* () {
56
+ const client = yield* HttpClient.HttpClient;
57
+ const baseUrl = yield* getBaseUrl;
58
+ return client.pipe(
59
+ HttpClient.mapRequest((r) =>
60
+ r.pipe(
61
+ HttpClientRequest.prependUrl(baseUrl),
62
+ HttpClientRequest.setHeader('X-Instant-Source', 'instant-cli'),
63
+ HttpClientRequest.setHeader('X-Instant-Version', version),
64
+ ),
65
+ ),
66
+ HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))),
67
+ HttpClient.filterStatusOk, // makes non 2xx http codes error
68
+ // parses the non 2xx errors into known instant error shape
69
+ HttpClient.transformResponse((r) =>
70
+ r.pipe(
71
+ Effect.catchTag('ResponseError', (requestError) =>
72
+ Effect.gen(function* () {
73
+ const jsonBody = yield* requestError.response.json.pipe(
74
+ Effect.andThen(
75
+ Schema.decodeUnknown(InstantTypicalHttpErrorResponse),
76
+ ),
77
+ Effect.mapError(
78
+ (e) =>
79
+ new InstantHttpError({
80
+ message:
81
+ 'Error making request to ' + requestError.methodAndUrl,
82
+ type: e._tag,
83
+ methodAndUrl: requestError.methodAndUrl,
84
+ }),
85
+ ),
86
+ );
87
+
88
+ // The hint.message is usually better error message
89
+ let message = jsonBody.message;
90
+ if (
91
+ jsonBody.hint?.message &&
92
+ typeof jsonBody.hint.message === 'string'
93
+ ) {
94
+ message = jsonBody.hint.message;
95
+ }
96
+
97
+ return yield* new InstantHttpError({
98
+ message: message,
99
+ methodAndUrl: requestError.methodAndUrl,
100
+ hint: jsonBody.hint,
101
+ type: jsonBody.type || 'Unknown type',
102
+ });
103
+ }),
104
+ ),
105
+ ),
106
+ ),
107
+ );
108
+ }),
109
+ );
110
+
111
+ export const InstantHttpAuthedLive = Layer.effect(
112
+ InstantHttpAuthed,
113
+ Effect.gen(function* () {
114
+ const http = yield* InstantHttp;
115
+ const authToken = yield* AuthToken;
116
+ return http.pipe(
117
+ HttpClient.mapRequestEffect((r) =>
118
+ authToken.getAuthToken.pipe(
119
+ Effect.map((token) =>
120
+ r.pipe(
121
+ HttpClientRequest.setHeader('Authorization', `Bearer ${token}`),
122
+ ),
123
+ ),
124
+ ),
125
+ ),
126
+ );
127
+ }),
128
+ );