@sidekickdb/cli 0.0.0 → 2.0.1

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 (445) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/LICENSE.md +202 -0
  3. package/NOTICE +27 -0
  4. package/README.md +67 -2
  5. package/__tests__/appCommands.test.ts +229 -0
  6. package/__tests__/args.test.ts +358 -0
  7. package/__tests__/auth.test.ts +128 -0
  8. package/__tests__/authClientAddApple.test.ts +377 -0
  9. package/__tests__/authClientAddClerk.test.ts +223 -0
  10. package/__tests__/authClientAddGithub.test.ts +245 -0
  11. package/__tests__/authClientAddGoogle.test.ts +374 -0
  12. package/__tests__/authClientAddLinkedin.test.ts +263 -0
  13. package/__tests__/authClientList.test.ts +90 -0
  14. package/__tests__/authClientUpdate.test.ts +584 -0
  15. package/__tests__/authOriginManagement.test.ts +308 -0
  16. package/__tests__/backupDownload.test.ts +206 -0
  17. package/__tests__/backups.test.ts +222 -0
  18. package/__tests__/config.test.ts +164 -0
  19. package/__tests__/configAliases.test.ts +232 -0
  20. package/__tests__/e2e/cli.e2e.test.ts +1269 -0
  21. package/__tests__/e2e/helpers.ts +186 -0
  22. package/__tests__/effectHelpers.ts +45 -0
  23. package/__tests__/legacyPackageCompat.test.ts +104 -0
  24. package/__tests__/mergeSchema.test.ts +197 -0
  25. package/__tests__/multiSelect.test.ts +236 -0
  26. package/__tests__/oauthMock.ts +76 -0
  27. package/__tests__/promptOk.test.ts +44 -0
  28. package/__tests__/redirectUriPrompt.test.ts +40 -0
  29. package/__tests__/select.test.ts +224 -0
  30. package/__tests__/webhooks.test.ts +729 -0
  31. package/bin/index.js +3 -0
  32. package/dist/auth/index.d.ts +4 -0
  33. package/dist/auth/index.d.ts.map +1 -0
  34. package/dist/auth/index.js +103 -0
  35. package/dist/auth/index.js.map +1 -0
  36. package/dist/commands/app/delete.d.ts +7 -0
  37. package/dist/commands/app/delete.d.ts.map +1 -0
  38. package/dist/commands/app/delete.js +57 -0
  39. package/dist/commands/app/delete.js.map +1 -0
  40. package/dist/commands/app/list.d.ts +6 -0
  41. package/dist/commands/app/list.d.ts.map +1 -0
  42. package/dist/commands/app/list.js +29 -0
  43. package/dist/commands/app/list.js.map +1 -0
  44. package/dist/commands/auth/client/add.d.ts +9 -0
  45. package/dist/commands/auth/client/add.d.ts.map +1 -0
  46. package/dist/commands/auth/client/add.js +409 -0
  47. package/dist/commands/auth/client/add.js.map +1 -0
  48. package/dist/commands/auth/client/delete.d.ts +11 -0
  49. package/dist/commands/auth/client/delete.d.ts.map +1 -0
  50. package/dist/commands/auth/client/delete.js +48 -0
  51. package/dist/commands/auth/client/delete.js.map +1 -0
  52. package/dist/commands/auth/client/list.d.ts +6 -0
  53. package/dist/commands/auth/client/list.d.ts.map +1 -0
  54. package/dist/commands/auth/client/list.js +38 -0
  55. package/dist/commands/auth/client/list.js.map +1 -0
  56. package/dist/commands/auth/client/shared.d.ts +70 -0
  57. package/dist/commands/auth/client/shared.d.ts.map +1 -0
  58. package/dist/commands/auth/client/shared.js +140 -0
  59. package/dist/commands/auth/client/shared.js.map +1 -0
  60. package/dist/commands/auth/client/update.d.ts +8 -0
  61. package/dist/commands/auth/client/update.d.ts.map +1 -0
  62. package/dist/commands/auth/client/update.js +445 -0
  63. package/dist/commands/auth/client/update.js.map +1 -0
  64. package/dist/commands/auth/email/pull.d.ts +24 -0
  65. package/dist/commands/auth/email/pull.d.ts.map +1 -0
  66. package/dist/commands/auth/email/pull.js +100 -0
  67. package/dist/commands/auth/email/pull.js.map +1 -0
  68. package/dist/commands/auth/email/push.d.ts +8 -0
  69. package/dist/commands/auth/email/push.d.ts.map +1 -0
  70. package/dist/commands/auth/email/push.js +58 -0
  71. package/dist/commands/auth/email/push.js.map +1 -0
  72. package/dist/commands/auth/email/resend.d.ts +3 -0
  73. package/dist/commands/auth/email/resend.d.ts.map +1 -0
  74. package/dist/commands/auth/email/resend.js +7 -0
  75. package/dist/commands/auth/email/resend.js.map +1 -0
  76. package/dist/commands/auth/email/reset.d.ts +5 -0
  77. package/dist/commands/auth/email/reset.d.ts.map +1 -0
  78. package/dist/commands/auth/email/reset.js +25 -0
  79. package/dist/commands/auth/email/reset.js.map +1 -0
  80. package/dist/commands/auth/email/status.d.ts +57 -0
  81. package/dist/commands/auth/email/status.d.ts.map +1 -0
  82. package/dist/commands/auth/email/status.js +96 -0
  83. package/dist/commands/auth/email/status.js.map +1 -0
  84. package/dist/commands/auth/email/verify.d.ts +5 -0
  85. package/dist/commands/auth/email/verify.d.ts.map +1 -0
  86. package/dist/commands/auth/email/verify.js +12 -0
  87. package/dist/commands/auth/email/verify.js.map +1 -0
  88. package/dist/commands/auth/origin/add.d.ts +12 -0
  89. package/dist/commands/auth/origin/add.d.ts.map +1 -0
  90. package/dist/commands/auth/origin/add.js +153 -0
  91. package/dist/commands/auth/origin/add.js.map +1 -0
  92. package/dist/commands/auth/origin/delete.d.ts +8 -0
  93. package/dist/commands/auth/origin/delete.d.ts.map +1 -0
  94. package/dist/commands/auth/origin/delete.js +38 -0
  95. package/dist/commands/auth/origin/delete.js.map +1 -0
  96. package/dist/commands/auth/origin/list.d.ts +9 -0
  97. package/dist/commands/auth/origin/list.d.ts.map +1 -0
  98. package/dist/commands/auth/origin/list.js +52 -0
  99. package/dist/commands/auth/origin/list.js.map +1 -0
  100. package/dist/commands/backup/download.d.ts +10 -0
  101. package/dist/commands/backup/download.d.ts.map +1 -0
  102. package/dist/commands/backup/download.js +174 -0
  103. package/dist/commands/backup/download.js.map +1 -0
  104. package/dist/commands/backup/list.d.ts +11 -0
  105. package/dist/commands/backup/list.d.ts.map +1 -0
  106. package/dist/commands/backup/list.js +74 -0
  107. package/dist/commands/backup/list.js.map +1 -0
  108. package/dist/commands/claim.d.ts +6 -0
  109. package/dist/commands/claim.d.ts.map +1 -0
  110. package/dist/commands/claim.js +22 -0
  111. package/dist/commands/claim.js.map +1 -0
  112. package/dist/commands/explorer.d.ts +6 -0
  113. package/dist/commands/explorer.d.ts.map +1 -0
  114. package/dist/commands/explorer.js +13 -0
  115. package/dist/commands/explorer.js.map +1 -0
  116. package/dist/commands/info.d.ts +9 -0
  117. package/dist/commands/info.d.ts.map +1 -0
  118. package/dist/commands/info.js +41 -0
  119. package/dist/commands/info.js.map +1 -0
  120. package/dist/commands/init.d.ts +5 -0
  121. package/dist/commands/init.d.ts.map +1 -0
  122. package/dist/commands/init.js +41 -0
  123. package/dist/commands/init.js.map +1 -0
  124. package/dist/commands/initWithoutFiles.d.ts +6 -0
  125. package/dist/commands/initWithoutFiles.d.ts.map +1 -0
  126. package/dist/commands/initWithoutFiles.js +64 -0
  127. package/dist/commands/initWithoutFiles.js.map +1 -0
  128. package/dist/commands/login.d.ts +9 -0
  129. package/dist/commands/login.d.ts.map +1 -0
  130. package/dist/commands/login.js +44 -0
  131. package/dist/commands/login.js.map +1 -0
  132. package/dist/commands/logout.d.ts +3 -0
  133. package/dist/commands/logout.d.ts.map +1 -0
  134. package/dist/commands/logout.js +14 -0
  135. package/dist/commands/logout.js.map +1 -0
  136. package/dist/commands/pull.d.ts +5 -0
  137. package/dist/commands/pull.d.ts.map +1 -0
  138. package/dist/commands/pull.js +15 -0
  139. package/dist/commands/pull.js.map +1 -0
  140. package/dist/commands/push.d.ts +6 -0
  141. package/dist/commands/push.d.ts.map +1 -0
  142. package/dist/commands/push.js +20 -0
  143. package/dist/commands/push.js.map +1 -0
  144. package/dist/commands/query.d.ts +7 -0
  145. package/dist/commands/query.d.ts.map +1 -0
  146. package/dist/commands/query.js +52 -0
  147. package/dist/commands/query.js.map +1 -0
  148. package/dist/commands/webhooks/add.d.ts +9 -0
  149. package/dist/commands/webhooks/add.d.ts.map +1 -0
  150. package/dist/commands/webhooks/add.js +75 -0
  151. package/dist/commands/webhooks/add.js.map +1 -0
  152. package/dist/commands/webhooks/delete.d.ts +6 -0
  153. package/dist/commands/webhooks/delete.d.ts.map +1 -0
  154. package/dist/commands/webhooks/delete.js +17 -0
  155. package/dist/commands/webhooks/delete.js.map +1 -0
  156. package/dist/commands/webhooks/disable.d.ts +7 -0
  157. package/dist/commands/webhooks/disable.d.ts.map +1 -0
  158. package/dist/commands/webhooks/disable.js +18 -0
  159. package/dist/commands/webhooks/disable.js.map +1 -0
  160. package/dist/commands/webhooks/enable.d.ts +6 -0
  161. package/dist/commands/webhooks/enable.d.ts.map +1 -0
  162. package/dist/commands/webhooks/enable.js +18 -0
  163. package/dist/commands/webhooks/enable.js.map +1 -0
  164. package/dist/commands/webhooks/events/list.d.ts +7 -0
  165. package/dist/commands/webhooks/events/list.d.ts.map +1 -0
  166. package/dist/commands/webhooks/events/list.js +31 -0
  167. package/dist/commands/webhooks/events/list.js.map +1 -0
  168. package/dist/commands/webhooks/events/payload.d.ts +8 -0
  169. package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
  170. package/dist/commands/webhooks/events/payload.js +39 -0
  171. package/dist/commands/webhooks/events/payload.js.map +1 -0
  172. package/dist/commands/webhooks/events/resend.d.ts +8 -0
  173. package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
  174. package/dist/commands/webhooks/events/resend.js +43 -0
  175. package/dist/commands/webhooks/events/resend.js.map +1 -0
  176. package/dist/commands/webhooks/list.d.ts +8 -0
  177. package/dist/commands/webhooks/list.d.ts.map +1 -0
  178. package/dist/commands/webhooks/list.js +29 -0
  179. package/dist/commands/webhooks/list.js.map +1 -0
  180. package/dist/commands/webhooks/shared.d.ts +40 -0
  181. package/dist/commands/webhooks/shared.d.ts.map +1 -0
  182. package/dist/commands/webhooks/shared.js +248 -0
  183. package/dist/commands/webhooks/shared.js.map +1 -0
  184. package/dist/commands/webhooks/update.d.ts +10 -0
  185. package/dist/commands/webhooks/update.d.ts.map +1 -0
  186. package/dist/commands/webhooks/update.js +189 -0
  187. package/dist/commands/webhooks/update.js.map +1 -0
  188. package/dist/context/authToken.d.ts +29 -0
  189. package/dist/context/authToken.d.ts.map +1 -0
  190. package/dist/context/authToken.js +73 -0
  191. package/dist/context/authToken.js.map +1 -0
  192. package/dist/context/currentApp.d.ts +38 -0
  193. package/dist/context/currentApp.d.ts.map +1 -0
  194. package/dist/context/currentApp.js +222 -0
  195. package/dist/context/currentApp.js.map +1 -0
  196. package/dist/context/globalOpts.d.ts +11 -0
  197. package/dist/context/globalOpts.d.ts.map +1 -0
  198. package/dist/context/globalOpts.js +13 -0
  199. package/dist/context/globalOpts.js.map +1 -0
  200. package/dist/context/platformApi.d.ts +19 -0
  201. package/dist/context/platformApi.d.ts.map +1 -0
  202. package/dist/context/platformApi.js +24 -0
  203. package/dist/context/platformApi.js.map +1 -0
  204. package/dist/context/projectInfo.d.ts +32 -0
  205. package/dist/context/projectInfo.d.ts.map +1 -0
  206. package/dist/context/projectInfo.js +160 -0
  207. package/dist/context/projectInfo.js.map +1 -0
  208. package/dist/errors.d.ts +10 -0
  209. package/dist/errors.d.ts.map +1 -0
  210. package/dist/errors.js +6 -0
  211. package/dist/errors.js.map +1 -0
  212. package/dist/index.d.ts +159 -0
  213. package/dist/index.d.ts.map +1 -0
  214. package/dist/index.js +721 -0
  215. package/dist/index.js.map +1 -0
  216. package/dist/layer.d.ts +25 -0
  217. package/dist/layer.d.ts.map +1 -0
  218. package/dist/layer.js +119 -0
  219. package/dist/layer.js.map +1 -0
  220. package/dist/lib/args.d.ts +212 -0
  221. package/dist/lib/args.d.ts.map +1 -0
  222. package/dist/lib/args.js +313 -0
  223. package/dist/lib/args.js.map +1 -0
  224. package/dist/lib/backupDownload.d.ts +21 -0
  225. package/dist/lib/backupDownload.d.ts.map +1 -0
  226. package/dist/lib/backupDownload.js +151 -0
  227. package/dist/lib/backupDownload.js.map +1 -0
  228. package/dist/lib/backups.d.ts +12 -0
  229. package/dist/lib/backups.d.ts.map +1 -0
  230. package/dist/lib/backups.js +26 -0
  231. package/dist/lib/backups.js.map +1 -0
  232. package/dist/lib/config.d.ts +13 -0
  233. package/dist/lib/config.d.ts.map +1 -0
  234. package/dist/lib/config.js +62 -0
  235. package/dist/lib/config.js.map +1 -0
  236. package/dist/lib/createApp.d.ts +12 -0
  237. package/dist/lib/createApp.d.ts.map +1 -0
  238. package/dist/lib/createApp.js +15 -0
  239. package/dist/lib/createApp.js.map +1 -0
  240. package/dist/lib/email.d.ts +47 -0
  241. package/dist/lib/email.d.ts.map +1 -0
  242. package/dist/lib/email.js +71 -0
  243. package/dist/lib/email.js.map +1 -0
  244. package/dist/lib/handleEnv.d.ts +7 -0
  245. package/dist/lib/handleEnv.d.ts.map +1 -0
  246. package/dist/lib/handleEnv.js +103 -0
  247. package/dist/lib/handleEnv.js.map +1 -0
  248. package/dist/lib/http.d.ts +30 -0
  249. package/dist/lib/http.d.ts.map +1 -0
  250. package/dist/lib/http.js +55 -0
  251. package/dist/lib/http.js.map +1 -0
  252. package/dist/lib/login.d.ts +12 -0
  253. package/dist/lib/login.d.ts.map +1 -0
  254. package/dist/lib/login.js +38 -0
  255. package/dist/lib/login.js.map +1 -0
  256. package/dist/lib/oauth.d.ts +306 -0
  257. package/dist/lib/oauth.d.ts.map +1 -0
  258. package/dist/lib/oauth.js +195 -0
  259. package/dist/lib/oauth.js.map +1 -0
  260. package/dist/lib/platformApi.d.ts +5 -0
  261. package/dist/lib/platformApi.d.ts.map +1 -0
  262. package/dist/lib/platformApi.js +11 -0
  263. package/dist/lib/platformApi.js.map +1 -0
  264. package/dist/lib/pullPerms.d.ts +7 -0
  265. package/dist/lib/pullPerms.d.ts.map +1 -0
  266. package/dist/lib/pullPerms.js +41 -0
  267. package/dist/lib/pullPerms.js.map +1 -0
  268. package/dist/lib/pullSchema.d.ts +12 -0
  269. package/dist/lib/pullSchema.d.ts.map +1 -0
  270. package/dist/lib/pullSchema.js +62 -0
  271. package/dist/lib/pullSchema.js.map +1 -0
  272. package/dist/lib/pushPerms.d.ts +13 -0
  273. package/dist/lib/pushPerms.d.ts.map +1 -0
  274. package/dist/lib/pushPerms.js +54 -0
  275. package/dist/lib/pushPerms.js.map +1 -0
  276. package/dist/lib/pushSchema.d.ts +53 -0
  277. package/dist/lib/pushSchema.d.ts.map +1 -0
  278. package/dist/lib/pushSchema.js +165 -0
  279. package/dist/lib/pushSchema.js.map +1 -0
  280. package/dist/lib/ui.d.ts +18 -0
  281. package/dist/lib/ui.d.ts.map +1 -0
  282. package/dist/lib/ui.js +32 -0
  283. package/dist/lib/ui.js.map +1 -0
  284. package/dist/lib/webhooks.d.ts +27 -0
  285. package/dist/lib/webhooks.d.ts.map +1 -0
  286. package/dist/lib/webhooks.js +95 -0
  287. package/dist/lib/webhooks.js.map +1 -0
  288. package/dist/logging.d.ts +5 -0
  289. package/dist/logging.d.ts.map +1 -0
  290. package/dist/logging.js +25 -0
  291. package/dist/logging.js.map +1 -0
  292. package/dist/old.d.ts +18 -0
  293. package/dist/old.d.ts.map +1 -0
  294. package/dist/old.js +423 -0
  295. package/dist/old.js.map +1 -0
  296. package/dist/program.d.ts +3 -0
  297. package/dist/program.d.ts.map +1 -0
  298. package/dist/program.js +3 -0
  299. package/dist/program.js.map +1 -0
  300. package/dist/renderSchemaPlan.d.ts +19 -0
  301. package/dist/renderSchemaPlan.d.ts.map +1 -0
  302. package/dist/renderSchemaPlan.js +220 -0
  303. package/dist/renderSchemaPlan.js.map +1 -0
  304. package/dist/ui/index.d.ts +292 -0
  305. package/dist/ui/index.d.ts.map +1 -0
  306. package/dist/ui/index.js +1296 -0
  307. package/dist/ui/index.js.map +1 -0
  308. package/dist/ui/lib.d.ts +124 -0
  309. package/dist/ui/lib.d.ts.map +1 -0
  310. package/dist/ui/lib.js +333 -0
  311. package/dist/ui/lib.js.map +1 -0
  312. package/dist/util/envAliases.d.ts +25 -0
  313. package/dist/util/envAliases.d.ts.map +1 -0
  314. package/dist/util/envAliases.js +47 -0
  315. package/dist/util/envAliases.js.map +1 -0
  316. package/dist/util/findConfigCandidates.d.ts +33 -0
  317. package/dist/util/findConfigCandidates.d.ts.map +1 -0
  318. package/dist/util/findConfigCandidates.js +230 -0
  319. package/dist/util/findConfigCandidates.js.map +1 -0
  320. package/dist/util/fs.d.ts +4 -0
  321. package/dist/util/fs.d.ts.map +1 -0
  322. package/dist/util/fs.js +22 -0
  323. package/dist/util/fs.js.map +1 -0
  324. package/dist/util/getAppName.d.ts +5 -0
  325. package/dist/util/getAppName.d.ts.map +1 -0
  326. package/dist/util/getAppName.js +14 -0
  327. package/dist/util/getAppName.js.map +1 -0
  328. package/dist/util/instantConfig.d.ts +9 -0
  329. package/dist/util/instantConfig.d.ts.map +1 -0
  330. package/dist/util/instantConfig.js +13 -0
  331. package/dist/util/instantConfig.js.map +1 -0
  332. package/dist/util/isHeadlessEnvironment.d.ts +4 -0
  333. package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
  334. package/dist/util/isHeadlessEnvironment.js +11 -0
  335. package/dist/util/isHeadlessEnvironment.js.map +1 -0
  336. package/dist/util/loadConfig.d.ts +3 -0
  337. package/dist/util/loadConfig.d.ts.map +1 -0
  338. package/dist/util/loadConfig.js +80 -0
  339. package/dist/util/loadConfig.js.map +1 -0
  340. package/dist/util/loadEnv.d.ts +2 -0
  341. package/dist/util/loadEnv.d.ts.map +1 -0
  342. package/dist/util/loadEnv.js +16 -0
  343. package/dist/util/loadEnv.js.map +1 -0
  344. package/dist/util/mergeSchema.d.ts +10 -0
  345. package/dist/util/mergeSchema.d.ts.map +1 -0
  346. package/dist/util/mergeSchema.js +338 -0
  347. package/dist/util/mergeSchema.js.map +1 -0
  348. package/dist/util/projectDir.d.ts +7 -0
  349. package/dist/util/projectDir.d.ts.map +1 -0
  350. package/dist/util/projectDir.js +43 -0
  351. package/dist/util/projectDir.js.map +1 -0
  352. package/dist/util/renamePrompt.d.ts +15 -0
  353. package/dist/util/renamePrompt.d.ts.map +1 -0
  354. package/dist/util/renamePrompt.js +57 -0
  355. package/dist/util/renamePrompt.js.map +1 -0
  356. package/dist/version.d.ts +3 -0
  357. package/dist/version.d.ts.map +1 -0
  358. package/dist/version.js +3 -0
  359. package/dist/version.js.map +1 -0
  360. package/package.json +83 -3
  361. package/src/auth/index.ts +125 -0
  362. package/src/commands/app/delete.ts +82 -0
  363. package/src/commands/app/list.ts +44 -0
  364. package/src/commands/auth/client/add.ts +744 -0
  365. package/src/commands/auth/client/delete.ts +60 -0
  366. package/src/commands/auth/client/list.ts +60 -0
  367. package/src/commands/auth/client/shared.ts +190 -0
  368. package/src/commands/auth/client/update.ts +830 -0
  369. package/src/commands/auth/email/pull.ts +143 -0
  370. package/src/commands/auth/email/push.ts +94 -0
  371. package/src/commands/auth/email/resend.ts +8 -0
  372. package/src/commands/auth/email/reset.ts +37 -0
  373. package/src/commands/auth/email/status.ts +154 -0
  374. package/src/commands/auth/email/verify.ts +22 -0
  375. package/src/commands/auth/origin/add.ts +237 -0
  376. package/src/commands/auth/origin/delete.ts +50 -0
  377. package/src/commands/auth/origin/list.ts +66 -0
  378. package/src/commands/backup/download.ts +231 -0
  379. package/src/commands/backup/list.ts +94 -0
  380. package/src/commands/claim.ts +31 -0
  381. package/src/commands/explorer.ts +21 -0
  382. package/src/commands/info.ts +57 -0
  383. package/src/commands/init.ts +60 -0
  384. package/src/commands/initWithoutFiles.ts +107 -0
  385. package/src/commands/login.ts +62 -0
  386. package/src/commands/logout.ts +22 -0
  387. package/src/commands/pull.ts +22 -0
  388. package/src/commands/push.ts +25 -0
  389. package/src/commands/query.ts +61 -0
  390. package/src/commands/webhooks/add.ts +111 -0
  391. package/src/commands/webhooks/delete.ts +23 -0
  392. package/src/commands/webhooks/disable.ts +24 -0
  393. package/src/commands/webhooks/enable.ts +24 -0
  394. package/src/commands/webhooks/events/list.ts +38 -0
  395. package/src/commands/webhooks/events/payload.ts +56 -0
  396. package/src/commands/webhooks/events/resend.ts +66 -0
  397. package/src/commands/webhooks/list.ts +41 -0
  398. package/src/commands/webhooks/shared.ts +339 -0
  399. package/src/commands/webhooks/update.ts +276 -0
  400. package/src/context/authToken.ts +134 -0
  401. package/src/context/currentApp.ts +301 -0
  402. package/src/context/globalOpts.ts +22 -0
  403. package/src/context/platformApi.ts +35 -0
  404. package/src/context/projectInfo.ts +227 -0
  405. package/src/errors.ts +7 -0
  406. package/src/index.ts +1222 -0
  407. package/src/layer.ts +211 -0
  408. package/src/lib/args.ts +453 -0
  409. package/src/lib/backupDownload.ts +188 -0
  410. package/src/lib/backups.ts +33 -0
  411. package/src/lib/config.ts +107 -0
  412. package/src/lib/createApp.ts +28 -0
  413. package/src/lib/email.ts +93 -0
  414. package/src/lib/handleEnv.ts +126 -0
  415. package/src/lib/http.ts +128 -0
  416. package/src/lib/login.ts +48 -0
  417. package/src/lib/oauth.ts +310 -0
  418. package/src/lib/platformApi.ts +11 -0
  419. package/src/lib/pullPerms.ts +50 -0
  420. package/src/lib/pullSchema.ts +95 -0
  421. package/src/lib/pushPerms.ts +80 -0
  422. package/src/lib/pushSchema.ts +248 -0
  423. package/src/lib/ui.ts +48 -0
  424. package/src/lib/webhooks.ts +118 -0
  425. package/src/logging.ts +41 -0
  426. package/src/old.js +502 -0
  427. package/src/program.ts +3 -0
  428. package/src/renderSchemaPlan.ts +324 -0
  429. package/src/ui/index.ts +1615 -0
  430. package/src/ui/lib.ts +424 -0
  431. package/src/util/envAliases.ts +53 -0
  432. package/src/util/findConfigCandidates.ts +288 -0
  433. package/src/util/fs.ts +26 -0
  434. package/src/util/getAppName.ts +14 -0
  435. package/src/util/instantConfig.ts +21 -0
  436. package/src/util/isHeadlessEnvironment.ts +15 -0
  437. package/src/util/loadConfig.ts +101 -0
  438. package/src/util/loadEnv.ts +19 -0
  439. package/src/util/mergeSchema.ts +374 -0
  440. package/src/util/projectDir.ts +54 -0
  441. package/src/util/renamePrompt.ts +79 -0
  442. package/src/version.js +3 -0
  443. package/tsconfig.build.json +20 -0
  444. package/tsconfig.json +23 -0
  445. package/vitest.config.ts +22 -0
package/src/index.ts ADDED
@@ -0,0 +1,1222 @@
1
+ import { loadEnv } from './util/loadEnv.ts';
2
+
3
+ loadEnv();
4
+
5
+ import minimist from 'minimist';
6
+ import { Command, Option } from '@commander-js/extra-typings';
7
+ import chalk from 'chalk';
8
+ import { Effect, Layer } from 'effect';
9
+ import version from './version.js';
10
+ import { initCommand } from './commands/init.ts';
11
+ import { initWithoutFilesCommand } from './commands/initWithoutFiles.ts';
12
+ import { loginCommand } from './commands/login.ts';
13
+ import { logoutCommand } from './commands/logout.ts';
14
+ import {
15
+ AuthLayerLive,
16
+ BaseLayerLive,
17
+ runCommandEffect,
18
+ WithAppLayer,
19
+ } from './layer.ts';
20
+ import { infoCommand } from './commands/info.ts';
21
+ import { pullCommand } from './commands/pull.ts';
22
+ import type { SchemaPermsOrBoth } from './commands/pull.ts';
23
+ import { claimCommand } from './commands/claim.ts';
24
+ import { pushCommand } from './commands/push.ts';
25
+ import { explorerCmd } from './commands/explorer.ts';
26
+ import { queryCmd } from './commands/query.ts';
27
+ import { program } from './program.ts';
28
+ import { PACKAGE_ALIAS_AND_FULL_NAMES } from './context/projectInfo.ts';
29
+ import { authClientAddCmd } from './commands/auth/client/add.ts';
30
+ import { authClientListCmd } from './commands/auth/client/list.ts';
31
+ import { authClientDeleteCmd } from './commands/auth/client/delete.ts';
32
+ import { authClientUpdateCmd } from './commands/auth/client/update.ts';
33
+ import { authOriginListCmd } from './commands/auth/origin/list.ts';
34
+ import { authOriginDeleteCmd } from './commands/auth/origin/delete.ts';
35
+ import { authOriginAddCmd } from './commands/auth/origin/add.ts';
36
+ import { authEmailPushCmd } from './commands/auth/email/push.ts';
37
+ import { authEmailPullCmd } from './commands/auth/email/pull.ts';
38
+ import { authEmailResetCmd } from './commands/auth/email/reset.ts';
39
+ import { link } from './logging.ts';
40
+ import { appListCommand } from './commands/app/list.ts';
41
+ import { appDeleteCommand } from './commands/app/delete.ts';
42
+ import { webhooksListCmd } from './commands/webhooks/list.ts';
43
+ import { webhooksAddCmd } from './commands/webhooks/add.ts';
44
+ import { webhooksUpdateCmd } from './commands/webhooks/update.ts';
45
+ import { webhooksDeleteCmd } from './commands/webhooks/delete.ts';
46
+ import { webhooksEnableCmd } from './commands/webhooks/enable.ts';
47
+ import { webhooksDisableCmd } from './commands/webhooks/disable.ts';
48
+ import { webhooksEventsListCmd } from './commands/webhooks/events/list.ts';
49
+ import { webhooksEventsPayloadCmd } from './commands/webhooks/events/payload.ts';
50
+ import { webhooksEventsResendCmd } from './commands/webhooks/events/resend.ts';
51
+ import { emailStatusCmd } from './commands/auth/email/status.ts';
52
+ import { verifyCmd } from './commands/auth/email/verify.ts';
53
+ import { resendEmailCmd } from './commands/auth/email/resend.ts';
54
+ import { backupListCmd } from './commands/backup/list.ts';
55
+ import { backupDownloadCmd } from './commands/backup/download.ts';
56
+
57
+ export type OptsFromCommand<C> =
58
+ C extends Command<any, infer R, any> ? R : never;
59
+
60
+ program
61
+ .name('sidekick-cli')
62
+ .addOption(globalOption('-t --token <token>', 'Auth token override'))
63
+ .addOption(globalOption('-y --yes', "Answer 'yes' to all prompts"))
64
+ .addOption(globalOption('--env <file>', 'Use a specific .env file'))
65
+ .addOption(
66
+ globalOption('-v --version', 'Print the version number', () => {
67
+ console.log(version);
68
+ process.exit(0);
69
+ }),
70
+ )
71
+ .addHelpOption(globalOption('-h --help', 'Print the help text for a command'))
72
+ .usage(`<command> ${chalk.dim('[options] [args]')}`)
73
+ .addHelpText(
74
+ 'after',
75
+ `
76
+ Names:
77
+ Every INSTANT_* environment variable can also be set as SIDEKICK_*, for
78
+ example SIDEKICK_CLI_API_URI or NEXT_PUBLIC_SIDEKICK_APP_ID, and the
79
+ instant.config, instant.schema, instant.perms and instant.email files can be
80
+ named sidekick.* instead. The SIDEKICK name wins when both exist.
81
+ `,
82
+ );
83
+
84
+ // Command List
85
+ export const initDef = program
86
+ .command('init')
87
+ .description('Set up a new project.')
88
+ .option(
89
+ '-a --app <app-id>',
90
+ 'If you have an existing app ID, we can pull schema and perms from there.',
91
+ )
92
+ .option(
93
+ '-p --package <react|react-native|core|admin|solid|svelte>',
94
+ 'Which package to automatically install if there is not one installed already.',
95
+ )
96
+ .option('--title <title>', 'Title for the created app')
97
+ .option(
98
+ '--temp',
99
+ 'Create a temporary app which will automatically delete itself after >24 hours.',
100
+ )
101
+ .action((options) => {
102
+ return runCommandEffect(
103
+ initCommand(options).pipe(
104
+ Effect.provide(
105
+ WithAppLayer({
106
+ coerce: true,
107
+ coerceAuth: true,
108
+ title: options.title,
109
+ appId: options.app,
110
+ packageName: options.package as any,
111
+ applyEnv: true,
112
+ temp: options.temp,
113
+ }),
114
+ ),
115
+ ),
116
+ );
117
+ });
118
+
119
+ const auth = program
120
+ .command('auth')
121
+ .description('Manage authentication for your app');
122
+ const app = program
123
+ .command('app')
124
+ .description('Manage individual SidekickDB apps');
125
+
126
+ export const appListDef = app
127
+ .command('list')
128
+ .description('List apps on your SidekickDB account')
129
+ .option('--json', 'Output apps as JSON')
130
+ .action(async (opts) => {
131
+ return runCommandEffect(
132
+ appListCommand(opts).pipe(
133
+ Effect.provide(
134
+ AuthLayerLive({
135
+ coerce: false,
136
+ allowAdminToken: false,
137
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
138
+ ),
139
+ ),
140
+ );
141
+ });
142
+
143
+ export const appDeleteDef = app
144
+ .command('delete')
145
+ .description('Delete an app from your SidekickDB account')
146
+ .option(
147
+ '-a --app <app-id>',
148
+ 'App ID to delete. Defaults to *_INSTANT_APP_ID in .env',
149
+ )
150
+ .action(async (opts) => {
151
+ return runCommandEffect(
152
+ appDeleteCommand(opts).pipe(
153
+ Effect.provide(
154
+ AuthLayerLive({
155
+ coerce: false,
156
+ allowAdminToken: false,
157
+ }),
158
+ ),
159
+ ),
160
+ );
161
+ });
162
+
163
+ const authClient = auth.command('client');
164
+ export const authClientAddDef = authClient
165
+ .command('add')
166
+ .allowExcessArguments(true)
167
+ .allowUnknownOption(true)
168
+ .option(
169
+ '--type <google|github|apple|linkedin>',
170
+ 'Type of oauth client to add',
171
+ )
172
+ .option(
173
+ '--name <client name>',
174
+ 'Custom name to identify the OAuth client (ex: google-web)',
175
+ )
176
+ .option(
177
+ '-a --app <app-id>',
178
+ 'App ID to modify. Defaults to *_INSTANT_APP_ID in .env',
179
+ )
180
+ .addHelpText(
181
+ 'after',
182
+ `
183
+ Provider Specific Options:
184
+ Google:
185
+ --app-type web|ios|android|button-for-web
186
+ --dev-credentials (optional, web only)
187
+ --client-id (required unless using dev credentials)
188
+ --client-secret (web only, unless using dev credentials)
189
+ --custom-redirect-uri (optional, web only)
190
+ GitHub:
191
+ --client-id
192
+ --client-secret
193
+ --custom-redirect-uri (optional)
194
+ Apple:
195
+ --services-id (Services ID from ${link('https://developer.apple.com', 'developer.apple.com')})
196
+ --team-id (optional, required for web redirect flow)
197
+ --key-id (optional, required for web redirect flow)
198
+ --private-key-file (optional, path to .p8 PEM; required for web redirect flow)
199
+ --custom-redirect-uri (optional, web redirect flow only)
200
+ LinkedIn:
201
+ --client-id
202
+ --client-secret
203
+ --custom-redirect-uri (optional)
204
+ Clerk:
205
+ --publishable-key (Publishable Key from ${link('https://dashboard.clerk.com', 'dashboard.clerk.com')})
206
+ Firebase:
207
+ --project-id (Project ID from ${link('https://console.firebase.google.com', 'console.firebase.google.com')})
208
+ `,
209
+ )
210
+ .action((opts) => {
211
+ opts = {
212
+ ...opts,
213
+ ...minimist(process.argv),
214
+ };
215
+ return runCommandEffect(
216
+ authClientAddCmd(opts).pipe(
217
+ Effect.provide(
218
+ WithAppLayer({
219
+ coerce: false,
220
+ coerceAuth: false,
221
+ appId: opts.app,
222
+ allowAdminToken: true,
223
+ }),
224
+ ),
225
+ ),
226
+ );
227
+ });
228
+ export const authClientListDef = authClient
229
+ .command('list')
230
+ .option(
231
+ '-a --app <app-id>',
232
+ 'App ID to list clients for. Defaults to *_INSTANT_APP_ID in .env',
233
+ )
234
+ .option('--json', 'Enable JSON output')
235
+ .allowUnknownOption(true)
236
+ .action((opts) => {
237
+ return runCommandEffect(
238
+ authClientListCmd(opts).pipe(
239
+ Effect.provide(
240
+ WithAppLayer({
241
+ coerce: false,
242
+ coerceAuth: false,
243
+ appId: opts.app,
244
+ allowAdminToken: true,
245
+ // Silence "searching for instant sdk.. logs for json output"
246
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
247
+ ),
248
+ ),
249
+ );
250
+ });
251
+
252
+ export const authClientDeleteDef = authClient
253
+ .command('delete')
254
+ .option('--id <client-id>', 'Client ID to delete')
255
+ .option('--name <client-name>', 'Client name to delete')
256
+ .option(
257
+ '-a --app <app-id>',
258
+ 'App ID to delete a client from. Defaults to *_INSTANT_APP_ID in .env',
259
+ )
260
+ .action((opts) => {
261
+ return runCommandEffect(
262
+ authClientDeleteCmd(opts).pipe(
263
+ Effect.provide(
264
+ WithAppLayer({
265
+ coerce: false,
266
+ appId: opts.app,
267
+ allowAdminToken: true,
268
+ }),
269
+ ),
270
+ ),
271
+ );
272
+ });
273
+
274
+ export const authClientUpdateDef = authClient
275
+ .command('update')
276
+ .description('Update an OAuth client')
277
+ .allowExcessArguments(true)
278
+ .allowUnknownOption(true)
279
+ .option('--id <client-id>', 'Client ID to update')
280
+ .option('--name <client-name>', 'Client name to update')
281
+ .option(
282
+ '-a --app <app-id>',
283
+ 'App ID to update a client in. Defaults to *_INSTANT_APP_ID in .env',
284
+ )
285
+ .addHelpText(
286
+ 'after',
287
+ `
288
+ Provider Specific Options:
289
+ Google:
290
+ --dev-credentials (web only)
291
+ --client-id
292
+ --client-secret (web only)
293
+ --custom-redirect-uri (optional, web only)
294
+ GitHub:
295
+ --client-id
296
+ --client-secret
297
+ --custom-redirect-uri (optional)
298
+ Apple:
299
+ --services-id
300
+ --team-id (web redirect flow)
301
+ --key-id (web redirect flow)
302
+ --private-key-file (web redirect flow)
303
+ --custom-redirect-uri (optional, web redirect flow only)
304
+ LinkedIn:
305
+ --client-id
306
+ --client-secret
307
+ --custom-redirect-uri (optional)
308
+ Clerk:
309
+ --publishable-key
310
+ Firebase:
311
+ --project-id
312
+ `,
313
+ )
314
+ .action((opts) => {
315
+ opts = {
316
+ ...opts,
317
+ ...minimist(process.argv),
318
+ };
319
+
320
+ return runCommandEffect(
321
+ authClientUpdateCmd(opts).pipe(
322
+ Effect.provide(
323
+ WithAppLayer({
324
+ coerce: false,
325
+ appId: opts.app,
326
+ allowAdminToken: true,
327
+ }),
328
+ ),
329
+ ),
330
+ );
331
+ });
332
+
333
+ const authOrigin = auth.command('origin');
334
+ export const authOriginListDef = authOrigin
335
+ .command('list')
336
+ .option(
337
+ '-a --app <app-id>',
338
+ 'App ID to list origins for. Defaults to *_INSTANT_APP_ID in .env',
339
+ )
340
+ .option('--json', 'Enable JSON output')
341
+ .action((opts) => {
342
+ return runCommandEffect(
343
+ authOriginListCmd(opts).pipe(
344
+ Effect.provide(
345
+ WithAppLayer({
346
+ coerce: false,
347
+ coerceAuth: false,
348
+ appId: opts.app,
349
+ allowAdminToken: true,
350
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
351
+ ),
352
+ ),
353
+ );
354
+ });
355
+
356
+ export const authOriginAddDef = authOrigin
357
+ .command('add')
358
+ .option(
359
+ '--type <website|vercel|netlify|custom-scheme>',
360
+ 'Type of origin to add.',
361
+ )
362
+ .option('--url <url>', 'Website URL (for website type, e.g. example.com)')
363
+ .option(
364
+ '--project <name>',
365
+ 'Vercel project name (for vercel type, e.g. my-project)',
366
+ )
367
+ .option('--site <name>', 'Netlify site name (for netlify type, e.g. my-site)')
368
+ .option(
369
+ '--scheme <scheme>',
370
+ 'App scheme (for custom-scheme type, e.g. myapp://)',
371
+ )
372
+ .option(
373
+ '-a --app <app-id>',
374
+ 'App ID to add an origin to. Defaults to *_INSTANT_APP_ID in .env',
375
+ )
376
+ .addHelpText(
377
+ 'after',
378
+ `
379
+ Origin Types:
380
+ website A standard website origin (e.g. example.com)
381
+ vercel Vercel preview deployments (project name)
382
+ netlify Netlify preview deployments (site name)
383
+ custom-scheme Native app scheme (e.g. your-app-scheme://)
384
+ `,
385
+ )
386
+ .action((opts) => {
387
+ return runCommandEffect(
388
+ authOriginAddCmd(opts).pipe(
389
+ Effect.provide(
390
+ WithAppLayer({
391
+ coerce: false,
392
+ coerceAuth: false,
393
+ appId: opts.app,
394
+ allowAdminToken: true,
395
+ }),
396
+ ),
397
+ ),
398
+ );
399
+ });
400
+
401
+ export const authOriginDeleteDef = authOrigin
402
+ .command('delete')
403
+ .option('--id <origin-id>', 'Origin ID to delete')
404
+ .option(
405
+ '-a --app <app-id>',
406
+ 'App ID to delete an origin from. Defaults to *_INSTANT_APP_ID in .env',
407
+ )
408
+ .action((opts) => {
409
+ return runCommandEffect(
410
+ authOriginDeleteCmd(opts).pipe(
411
+ Effect.provide(
412
+ WithAppLayer({
413
+ coerce: false,
414
+ appId: opts.app,
415
+ allowAdminToken: true,
416
+ }),
417
+ ),
418
+ ),
419
+ );
420
+ });
421
+
422
+ const webhooks = program
423
+ .command('webhook')
424
+ .description('Manage webhooks for an app');
425
+
426
+ export const webhooksListDef = webhooks
427
+ .command('list')
428
+ .description('List webhooks for an app')
429
+ .option(
430
+ '-a --app <app-id>',
431
+ 'App ID to list webhooks for. Defaults to *_INSTANT_APP_ID in .env',
432
+ )
433
+ .option('--json', 'Enable JSON output')
434
+ .action((opts) => {
435
+ return runCommandEffect(
436
+ webhooksListCmd(opts).pipe(
437
+ Effect.provide(
438
+ WithAppLayer({
439
+ coerce: false,
440
+ coerceAuth: false,
441
+ appId: opts.app,
442
+ allowAdminToken: false,
443
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
444
+ ),
445
+ ),
446
+ );
447
+ });
448
+
449
+ export const webhooksAddDef = webhooks
450
+ .command('add')
451
+ .description('Add a webhook to an app')
452
+ .option('--url <url>', 'HTTPS endpoint to deliver events to')
453
+ .option(
454
+ '--namespaces <e1,e2>',
455
+ 'Comma-separated list of namespaces to listen on',
456
+ )
457
+ .option(
458
+ '--actions <a1,a2>',
459
+ 'Comma-separated list of actions (create, update, delete)',
460
+ )
461
+ .option(
462
+ '-a --app <app-id>',
463
+ 'App ID to add a webhook to. Defaults to *_INSTANT_APP_ID in .env',
464
+ )
465
+ .action((opts) => {
466
+ return runCommandEffect(
467
+ webhooksAddCmd(opts).pipe(
468
+ Effect.provide(
469
+ WithAppLayer({
470
+ coerce: false,
471
+ coerceAuth: false,
472
+ appId: opts.app,
473
+ allowAdminToken: false,
474
+ }),
475
+ ),
476
+ ),
477
+ );
478
+ });
479
+
480
+ export const webhooksUpdateDef = webhooks
481
+ .command('update')
482
+ .description('Update a webhook')
483
+ .option('--id <webhook-id>', 'Webhook ID to update')
484
+ .option('--url <url>', 'New HTTPS endpoint')
485
+ .option('--namespaces <e1,e2>', 'New comma-separated namespaces')
486
+ .option(
487
+ '--actions <a1,a2>',
488
+ 'New comma-separated actions (create, update, delete)',
489
+ )
490
+ .option(
491
+ '-a --app <app-id>',
492
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
493
+ )
494
+ .action((opts) => {
495
+ return runCommandEffect(
496
+ webhooksUpdateCmd(opts).pipe(
497
+ Effect.provide(
498
+ WithAppLayer({
499
+ coerce: false,
500
+ coerceAuth: false,
501
+ appId: opts.app,
502
+ allowAdminToken: false,
503
+ }),
504
+ ),
505
+ ),
506
+ );
507
+ });
508
+
509
+ export const webhooksDeleteDef = webhooks
510
+ .command('delete')
511
+ .description('Delete a webhook')
512
+ .option('--id <webhook-id>', 'Webhook ID to delete')
513
+ .option(
514
+ '-a --app <app-id>',
515
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
516
+ )
517
+ .action((opts) => {
518
+ return runCommandEffect(
519
+ webhooksDeleteCmd(opts).pipe(
520
+ Effect.provide(
521
+ WithAppLayer({
522
+ coerce: false,
523
+ coerceAuth: false,
524
+ appId: opts.app,
525
+ allowAdminToken: false,
526
+ }),
527
+ ),
528
+ ),
529
+ );
530
+ });
531
+
532
+ export const webhooksEnableDef = webhooks
533
+ .command('enable')
534
+ .description('Re-enable a disabled webhook')
535
+ .option('--id <webhook-id>', 'Webhook ID to enable')
536
+ .option(
537
+ '-a --app <app-id>',
538
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
539
+ )
540
+ .action((opts) => {
541
+ return runCommandEffect(
542
+ webhooksEnableCmd(opts).pipe(
543
+ Effect.provide(
544
+ WithAppLayer({
545
+ coerce: false,
546
+ coerceAuth: false,
547
+ appId: opts.app,
548
+ allowAdminToken: false,
549
+ }),
550
+ ),
551
+ ),
552
+ );
553
+ });
554
+
555
+ export const webhooksDisableDef = webhooks
556
+ .command('disable')
557
+ .description('Disable an active webhook')
558
+ .option('--id <webhook-id>', 'Webhook ID to disable')
559
+ .option('--reason <reason>', 'Human-readable reason stored on the webhook')
560
+ .option(
561
+ '-a --app <app-id>',
562
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
563
+ )
564
+ .action((opts) => {
565
+ return runCommandEffect(
566
+ webhooksDisableCmd(opts).pipe(
567
+ Effect.provide(
568
+ WithAppLayer({
569
+ coerce: false,
570
+ coerceAuth: false,
571
+ appId: opts.app,
572
+ allowAdminToken: false,
573
+ }),
574
+ ),
575
+ ),
576
+ );
577
+ });
578
+
579
+ const webhooksEvents = webhooks
580
+ .command('event')
581
+ .description('Inspect and resend webhook events');
582
+
583
+ export const webhooksEventsListDef = webhooksEvents
584
+ .command('list')
585
+ .description('List recent events for a webhook (up to 100, newest first)')
586
+ .option('--webhook-id <webhook-id>', 'Webhook ID to inspect')
587
+ .option('--json', 'Enable JSON output')
588
+ .option(
589
+ '-a --app <app-id>',
590
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
591
+ )
592
+ .action((opts) => {
593
+ return runCommandEffect(
594
+ webhooksEventsListCmd(opts).pipe(
595
+ Effect.provide(
596
+ WithAppLayer({
597
+ coerce: false,
598
+ coerceAuth: false,
599
+ appId: opts.app,
600
+ allowAdminToken: false,
601
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
602
+ ),
603
+ ),
604
+ );
605
+ });
606
+
607
+ export const webhooksEventsResendDef = webhooksEvents
608
+ .command('resend')
609
+ .description('Re-queue a webhook event for delivery')
610
+ .option('--webhook-id <webhook-id>', 'Webhook ID the event belongs to')
611
+ .option('--isn <isn>', 'Event ISN to resend')
612
+ .option(
613
+ '-a --app <app-id>',
614
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
615
+ )
616
+ .action((opts) => {
617
+ return runCommandEffect(
618
+ webhooksEventsResendCmd(opts).pipe(
619
+ Effect.provide(
620
+ WithAppLayer({
621
+ coerce: false,
622
+ coerceAuth: false,
623
+ appId: opts.app,
624
+ allowAdminToken: false,
625
+ }),
626
+ ),
627
+ ),
628
+ );
629
+ });
630
+
631
+ export const webhooksEventsPayloadDef = webhooksEvents
632
+ .command('payload')
633
+ .description('Print the JSON payload for a webhook event')
634
+ .option('--webhook-id <webhook-id>', 'Webhook ID the event belongs to')
635
+ .option('--isn <isn>', 'Event ISN to fetch')
636
+ .option(
637
+ '-a --app <app-id>',
638
+ 'App ID the webhook belongs to. Defaults to *_INSTANT_APP_ID in .env',
639
+ )
640
+ .action((opts) => {
641
+ return runCommandEffect(
642
+ webhooksEventsPayloadCmd(opts).pipe(
643
+ Effect.provide(
644
+ WithAppLayer({
645
+ coerce: false,
646
+ coerceAuth: false,
647
+ appId: opts.app,
648
+ allowAdminToken: false,
649
+ }),
650
+ ),
651
+ ),
652
+ );
653
+ });
654
+
655
+ const backup = program
656
+ .command('backup')
657
+ .description('View and download backups of your app');
658
+
659
+ export const backupListDef = backup
660
+ .command('list')
661
+ .description('List downloadable backups for an app')
662
+ .option(
663
+ '-a --app <app-id>',
664
+ 'App ID to list backups for. Defaults to *_INSTANT_APP_ID in .env',
665
+ )
666
+ .option('--json', 'Output backups as JSON')
667
+ .action((opts) => {
668
+ return runCommandEffect(
669
+ backupListCmd(opts).pipe(
670
+ Effect.provide(
671
+ WithAppLayer({
672
+ coerce: false,
673
+ coerceAuth: false,
674
+ appId: opts.app,
675
+ allowAdminToken: true,
676
+ }).pipe(Layer.annotateLogs('silent', !!opts.json)),
677
+ ),
678
+ ),
679
+ );
680
+ });
681
+
682
+ export const backupDownloadDef = backup
683
+ .command('download')
684
+ .description('Download a backup as a zip file')
685
+ .argument(
686
+ '[backup-id]',
687
+ 'Backup ID to download. Defaults to an interactive picker',
688
+ )
689
+ .option(
690
+ '-a --app <app-id>',
691
+ 'App ID to download a backup of. Defaults to *_INSTANT_APP_ID in .env',
692
+ )
693
+ .option('--latest', 'Download the most recent backup')
694
+ .option(
695
+ '-o --out <path>',
696
+ 'Output zip path. Defaults to instant-backup-<timestamp>.zip',
697
+ )
698
+ .action((backupId, opts) => {
699
+ return runCommandEffect(
700
+ backupDownloadCmd(backupId, opts).pipe(
701
+ Effect.provide(
702
+ WithAppLayer({
703
+ coerce: false,
704
+ coerceAuth: false,
705
+ appId: opts.app,
706
+ allowAdminToken: true,
707
+ }),
708
+ ),
709
+ ),
710
+ );
711
+ });
712
+
713
+ const authEmail = auth
714
+ .command('email')
715
+ .description('Manage custom magic code email templates');
716
+
717
+ export const authEmailStatusDef = authEmail
718
+ .command('status')
719
+ .description('Get status for the custom magic code email template')
720
+ .option(
721
+ '-a --app <app-id>',
722
+ 'App ID to push email settings to. Defaults to *_INSTANT_APP_ID in .env',
723
+ )
724
+ .option('--json', 'Output email status as JSON')
725
+ .action((opts) => {
726
+ runCommandEffect(
727
+ emailStatusCmd(opts).pipe(
728
+ Effect.provide(
729
+ WithAppLayer({
730
+ appId: opts.app,
731
+ coerce: false,
732
+ allowAdminToken: true,
733
+ }),
734
+ ),
735
+ ),
736
+ );
737
+ });
738
+
739
+ export const authEmailPushDef = authEmail
740
+ .command('push')
741
+ .description('Push the custom magic code email template.')
742
+ .option(
743
+ '-a --app <app-id>',
744
+ 'App ID to push email settings to. Defaults to *_INSTANT_APP_ID in .env',
745
+ )
746
+ .option(
747
+ '-f --file <path>',
748
+ 'Path to instant.email.ts. Defaults to INSTANT_EMAIL_FILE_PATH or auto-discovery.',
749
+ )
750
+ .action((opts) =>
751
+ runCommandEffect(
752
+ authEmailPushCmd({ file: opts.file }).pipe(
753
+ Effect.provide(
754
+ WithAppLayer({
755
+ coerce: false,
756
+ coerceAuth: false,
757
+ appId: opts.app,
758
+ allowAdminToken: true,
759
+ }),
760
+ ),
761
+ ),
762
+ ),
763
+ );
764
+
765
+ export const authEmailPullDef = authEmail
766
+ .command('pull')
767
+ .description('Pull the custom magic code email template.')
768
+ .option(
769
+ '-a --app <app-id>',
770
+ 'App ID to pull email settings from. Defaults to *_INSTANT_APP_ID in .env',
771
+ )
772
+ .option(
773
+ '-f --file <path>',
774
+ 'Path to instant.email.ts. Defaults to INSTANT_EMAIL_FILE_PATH or auto-discovery.',
775
+ )
776
+ .action((opts) =>
777
+ runCommandEffect(
778
+ authEmailPullCmd({ file: opts.file }).pipe(
779
+ Effect.provide(
780
+ WithAppLayer({
781
+ coerce: false,
782
+ coerceAuth: false,
783
+ appId: opts.app,
784
+ allowAdminToken: true,
785
+ }),
786
+ ),
787
+ ),
788
+ ),
789
+ );
790
+
791
+ export const authEmailResetDef = authEmail
792
+ .command('reset')
793
+ .description('Delete the custom magic code email template.')
794
+ .option(
795
+ '-a --app <app-id>',
796
+ 'App ID to reset email settings for. Defaults to *_INSTANT_APP_ID in .env',
797
+ )
798
+ .action((opts) =>
799
+ runCommandEffect(
800
+ authEmailResetCmd().pipe(
801
+ Effect.provide(
802
+ WithAppLayer({
803
+ coerce: false,
804
+ coerceAuth: false,
805
+ appId: opts.app,
806
+ allowAdminToken: true,
807
+ }),
808
+ ),
809
+ ),
810
+ ),
811
+ );
812
+
813
+ export const authEmailResendDef = authEmail
814
+ .command('resend')
815
+ .description('Resend the verification email')
816
+ .option(
817
+ '-a --app <app-id>',
818
+ 'App ID to reset email settings for. Defaults to *_INSTANT_APP_ID in .env',
819
+ )
820
+ .action(() => {
821
+ runCommandEffect(
822
+ resendEmailCmd.pipe(
823
+ Effect.provide(
824
+ WithAppLayer({
825
+ coerce: false,
826
+ coerceAuth: false,
827
+ allowAdminToken: true,
828
+ }),
829
+ ),
830
+ ),
831
+ );
832
+ });
833
+
834
+ export const authEmailVerifyDef = authEmail
835
+ .command('verify')
836
+ .description('Verify a custom email sender with a magic code')
837
+ .argument('<code>', 'The magic code to verify')
838
+ .option(
839
+ '-a --app <app-id>',
840
+ 'App ID to reset email settings for. Defaults to *_INSTANT_APP_ID in .env',
841
+ )
842
+ .action((code, opts) => {
843
+ runCommandEffect(
844
+ verifyCmd(code, opts).pipe(
845
+ Effect.provide(
846
+ WithAppLayer({
847
+ coerce: false,
848
+ coerceAuth: false,
849
+ appId: opts.app,
850
+ allowAdminToken: true,
851
+ }),
852
+ ),
853
+ ),
854
+ );
855
+ });
856
+
857
+ export const initWithoutFilesDef = program
858
+ .command('init-without-files')
859
+ .description('Generate a new app id and admin token pair without any files.')
860
+ .option('--title <title>', 'Title for the created app.')
861
+ .option(
862
+ '--org-id <org-id>',
863
+ 'Organization id for app. Cannot be used with --temp flag.',
864
+ )
865
+ .option(
866
+ '--temp',
867
+ 'Create a temporary app which will automatically delete itself after >24 hours.',
868
+ )
869
+ .action((opts) => {
870
+ return runCommandEffect(
871
+ initWithoutFilesCommand(opts).pipe(Effect.provide(BaseLayerLive)),
872
+ );
873
+ });
874
+
875
+ export const loginDef = program
876
+ .command('login')
877
+ .description('Log into your account')
878
+ .option('-p --print', 'Prints the auth token into the console.')
879
+ .option(
880
+ '--headless',
881
+ 'Print the login URL instead of trying to open the browser',
882
+ )
883
+ .action(async (opts) => {
884
+ await runCommandEffect(
885
+ loginCommand(opts).pipe(Effect.provide(BaseLayerLive)),
886
+ );
887
+ });
888
+
889
+ program
890
+ .command('logout')
891
+ .description('Log out of your SidekickDB account')
892
+ .action(async () => {
893
+ return runCommandEffect(
894
+ logoutCommand().pipe(Effect.provide(BaseLayerLive)),
895
+ );
896
+ });
897
+
898
+ export const infoDef = program
899
+ .command('info')
900
+ .description('Display CLI version, login status, and app info')
901
+ .action(async () => {
902
+ const authLayer = AuthLayerLive({
903
+ coerce: false,
904
+ allowAdminToken: false,
905
+ });
906
+
907
+ return runCommandEffect(
908
+ infoCommand().pipe(
909
+ Effect.provide(
910
+ Layer.mergeAll(
911
+ BaseLayerLive,
912
+ authLayer.pipe(Layer.catchAll(() => Layer.empty)),
913
+ WithAppLayer({ coerce: false, allowAdminToken: true }).pipe(
914
+ Layer.annotateLogs('silent', true),
915
+ Layer.catchAll(() => Layer.empty),
916
+ ),
917
+ ),
918
+ ),
919
+ ),
920
+ );
921
+ });
922
+
923
+ export const explorerDef = program
924
+ .command('explorer')
925
+ .description('Opens the Explorer in your browser')
926
+ .option(
927
+ '-a --app <app-id>',
928
+ 'App ID to open the explorer to. Defaults to *_INSTANT_APP_ID in .env',
929
+ )
930
+ .action(async (opts) => {
931
+ return runCommandEffect(
932
+ explorerCmd(opts).pipe(
933
+ Effect.provide(
934
+ WithAppLayer({
935
+ coerce: true,
936
+ coerceAuth: true,
937
+ appId: opts.app,
938
+ }),
939
+ ),
940
+ ),
941
+ );
942
+ });
943
+
944
+ export const queryDef = program
945
+ .command('query')
946
+ .argument('<query>', 'InstaQL query as JSON/JSON5')
947
+ .option(
948
+ '-a --app <app-id>',
949
+ 'App ID to query. Defaults to *_INSTANT_APP_ID in .env',
950
+ )
951
+ .option('--admin', 'Run the query as admin (bypasses permissions)')
952
+ .option('--as-email <email>', 'Run the query as a specific user by email')
953
+ .option('--as-guest', 'Run the query as an unauthenticated guest')
954
+ .option(
955
+ '--as-token <refresh-token>',
956
+ 'Run the query as a user identified by refresh token',
957
+ )
958
+ .description('Run an InstaQL query against your app.')
959
+ .action(async function (queryArg, opts) {
960
+ return runCommandEffect(queryCmd(queryArg, opts));
961
+ });
962
+
963
+ export const pullDef = program
964
+ .command('pull')
965
+ .argument(
966
+ '[schema|perms|all]',
967
+ 'Which configuration to pull. Defaults to `all`',
968
+ )
969
+ .option(
970
+ '-a --app <app-id>',
971
+ 'App ID to pull to. Defaults to *_INSTANT_APP_ID in .env',
972
+ )
973
+ .option(
974
+ '-p --package <react|react-native|core|admin|solid|svelte>',
975
+ 'Which package to automatically install if there is not one installed already.',
976
+ )
977
+ .option(
978
+ '--experimental-type-preservation',
979
+ "[Experimental] Preserve manual type changes like `status: i.json<'online' | 'offline'>()` when doing `sidekick-cli pull schema`",
980
+ )
981
+ .description('Pull schema and perm files from production.')
982
+ .addHelpText(
983
+ 'after',
984
+ `
985
+ Environment Variables:
986
+ INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)
987
+ INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)
988
+ `,
989
+ )
990
+ .action(async function (arg, inputOpts) {
991
+ return runCommandEffect(
992
+ pullCommand(arg as SchemaPermsOrBoth, inputOpts).pipe(
993
+ Effect.provide(
994
+ WithAppLayer({
995
+ coerce: true,
996
+ packageName: inputOpts.package as
997
+ | 'react'
998
+ | 'react-native'
999
+ | 'core'
1000
+ | 'admin'
1001
+ | undefined,
1002
+ appId: inputOpts.app,
1003
+ }),
1004
+ ),
1005
+ ),
1006
+ );
1007
+ });
1008
+
1009
+ export const pushDef = program
1010
+ .command('push')
1011
+ .argument(
1012
+ '[schema|perms|all]',
1013
+ 'Which configuration to push. Defaults to `all`',
1014
+ )
1015
+ .option(
1016
+ '-a --app <app-id>',
1017
+ 'App ID to push to. Defaults to *_INSTANT_APP_ID in .env',
1018
+ )
1019
+ .option(
1020
+ '--skip-check-types',
1021
+ "Don't check types on the server when pushing schema",
1022
+ )
1023
+ .option(
1024
+ '--rename [renames...]',
1025
+ 'List of full attribute names separated by a ":"\n Example:`push --rename posts.author:posts.creator stores.owner:stores.manager`',
1026
+ )
1027
+ .option(
1028
+ '-p --package <react|react-native|core|admin|solid|svelte>',
1029
+ 'Which package to automatically install if there is not one installed already.',
1030
+ )
1031
+ .description('Push schema and perm files to production.')
1032
+ .addHelpText(
1033
+ 'after',
1034
+ `
1035
+ Environment Variables:
1036
+ INSTANT_SCHEMA_FILE_PATH Override schema file location (default: instant.schema.ts)
1037
+ INSTANT_PERMS_FILE_PATH Override perms file location (default: instant.perms.ts)
1038
+ `,
1039
+ )
1040
+ .action(async function (arg, inputOpts) {
1041
+ return runCommandEffect(
1042
+ pushCommand(arg, inputOpts).pipe(
1043
+ Effect.provide(
1044
+ WithAppLayer({
1045
+ coerce: false,
1046
+ appId: inputOpts.app,
1047
+ coerceLibraryInstall: true,
1048
+ coerceAuth: false,
1049
+ allowAdminToken: true,
1050
+ applyEnv: true,
1051
+ packageName:
1052
+ inputOpts.package as keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,
1053
+ }),
1054
+ ),
1055
+ ),
1056
+ );
1057
+ });
1058
+
1059
+ export const claimDef = program
1060
+ .command('claim')
1061
+ .description('Transfer a temporary app into your SidekickDB account')
1062
+ .option(
1063
+ '-a --app <app-id>',
1064
+ 'App to claim. Defaults to *_INSTANT_APP_ID in .env',
1065
+ )
1066
+ .action(async function (opts) {
1067
+ return runCommandEffect(
1068
+ claimCommand.pipe(
1069
+ Effect.provide(
1070
+ WithAppLayer({
1071
+ coerce: false,
1072
+ allowAdminToken: false,
1073
+ appId: opts.app,
1074
+ applyEnv: false,
1075
+ }),
1076
+ ),
1077
+ ),
1078
+ );
1079
+ });
1080
+ //// Program setup /////
1081
+
1082
+ function globalOption(
1083
+ flags: string,
1084
+ description?: string,
1085
+ argParser?: (value: string, prev?: unknown) => unknown,
1086
+ ) {
1087
+ const opt = new Option(flags, description);
1088
+ if (argParser) {
1089
+ opt.argParser(argParser);
1090
+ }
1091
+ // @ts-ignore
1092
+ // __global does not exist on `Option`,
1093
+ // but we use it in `getLocalAndGlobalOptions`, to produce
1094
+ // our own custom list of local and global options.
1095
+ // For more info, see the original PR:
1096
+ // https://github.com/instantdb/instant/pull/505
1097
+ opt.__global = true;
1098
+ return opt;
1099
+ }
1100
+
1101
+ function getLocalAndGlobalOptions(cmd: any, helper: any) {
1102
+ const mixOfLocalAndGlobal = helper.visibleOptions(cmd);
1103
+ const localOptionsFromMix = mixOfLocalAndGlobal.filter(
1104
+ (option: any) => !option.__global,
1105
+ );
1106
+ const globalOptionsFromMix = mixOfLocalAndGlobal.filter(
1107
+ (option: any) => option.__global,
1108
+ );
1109
+ const globalOptions = helper.visibleGlobalOptions(cmd);
1110
+
1111
+ return [localOptionsFromMix, globalOptionsFromMix.concat(globalOptions)];
1112
+ }
1113
+
1114
+ function formatHelp(
1115
+ this: { showGlobalOptions: boolean },
1116
+ cmd: any,
1117
+ helper: any,
1118
+ ) {
1119
+ const termWidth = helper.padWidth(cmd, helper);
1120
+ const helpWidth = helper.helpWidth || 80;
1121
+ const itemIndentWidth = 2;
1122
+ const itemSeparatorWidth = 2; // between term and description
1123
+ function formatItem(term: string, description: string | undefined) {
1124
+ if (description) {
1125
+ const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
1126
+ return helper.boxWrap(
1127
+ fullText,
1128
+ helpWidth - itemIndentWidth,
1129
+ termWidth + itemSeparatorWidth,
1130
+ );
1131
+ }
1132
+ return term;
1133
+ }
1134
+ function formatList(textArray: string[]) {
1135
+ return textArray.join('\n').replace(/^/gm, ' '.repeat(itemIndentWidth));
1136
+ }
1137
+
1138
+ // Usage
1139
+ let output = [`${helper.commandUsage(cmd)}`, ''];
1140
+
1141
+ // Description
1142
+ const commandDescription = helper.commandDescription(cmd);
1143
+ if (commandDescription.length > 0) {
1144
+ output = output.concat([
1145
+ helper.boxWrap(commandDescription, helpWidth, 0),
1146
+ '',
1147
+ ]);
1148
+ }
1149
+
1150
+ // Arguments
1151
+ const argumentList = helper.visibleArguments(cmd).map((argument: any) => {
1152
+ return formatItem(
1153
+ helper.argumentTerm(argument),
1154
+ helper.argumentDescription(argument),
1155
+ );
1156
+ });
1157
+ if (argumentList.length > 0) {
1158
+ output = output.concat([
1159
+ chalk.dim.bold('Arguments'),
1160
+ formatList(argumentList),
1161
+ '',
1162
+ ]);
1163
+ }
1164
+ const [visibleOptions, visibleGlobalOptions] = getLocalAndGlobalOptions(
1165
+ cmd,
1166
+ helper,
1167
+ );
1168
+
1169
+ // Options
1170
+ const optionList = visibleOptions.map((option: any) => {
1171
+ return formatItem(
1172
+ helper.optionTerm(option),
1173
+ helper.optionDescription(option),
1174
+ );
1175
+ });
1176
+ if (optionList.length > 0) {
1177
+ output = output.concat([
1178
+ chalk.dim.bold('Options'),
1179
+ formatList(optionList),
1180
+ '',
1181
+ ]);
1182
+ }
1183
+ // Commands
1184
+ const commandList = helper.visibleCommands(cmd).map((cmd: any) => {
1185
+ return formatItem(
1186
+ helper.subcommandTerm(cmd),
1187
+ helper.subcommandDescription(cmd),
1188
+ );
1189
+ });
1190
+ if (commandList.length > 0) {
1191
+ output = output.concat([
1192
+ chalk.dim.bold('Commands'),
1193
+ formatList(commandList),
1194
+ '',
1195
+ ]);
1196
+ }
1197
+
1198
+ if (this.showGlobalOptions) {
1199
+ const globalOptionList = visibleGlobalOptions.map((option: any) => {
1200
+ return formatItem(
1201
+ helper.optionTerm(option),
1202
+ helper.optionDescription(option),
1203
+ );
1204
+ });
1205
+ if (globalOptionList.length > 0) {
1206
+ output = output.concat([
1207
+ chalk.dim.bold('Global Options'),
1208
+ formatList(globalOptionList),
1209
+ '',
1210
+ ]);
1211
+ }
1212
+ }
1213
+
1214
+ return output.join('\n');
1215
+ }
1216
+
1217
+ program.configureHelp({
1218
+ showGlobalOptions: true,
1219
+ formatHelp,
1220
+ });
1221
+
1222
+ program.parse(process.argv);