@superlayer/cli 1.0.67

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 (329) hide show
  1. package/LICENSE.md +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +67 -0
  4. package/bin/index.js +3 -0
  5. package/dist/auth/index.d.ts +4 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/auth/index.js +103 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/commands/app/delete.d.ts +7 -0
  10. package/dist/commands/app/delete.d.ts.map +1 -0
  11. package/dist/commands/app/delete.js +57 -0
  12. package/dist/commands/app/delete.js.map +1 -0
  13. package/dist/commands/app/list.d.ts +6 -0
  14. package/dist/commands/app/list.d.ts.map +1 -0
  15. package/dist/commands/app/list.js +29 -0
  16. package/dist/commands/app/list.js.map +1 -0
  17. package/dist/commands/auth/client/add.d.ts +9 -0
  18. package/dist/commands/auth/client/add.d.ts.map +1 -0
  19. package/dist/commands/auth/client/add.js +409 -0
  20. package/dist/commands/auth/client/add.js.map +1 -0
  21. package/dist/commands/auth/client/delete.d.ts +11 -0
  22. package/dist/commands/auth/client/delete.d.ts.map +1 -0
  23. package/dist/commands/auth/client/delete.js +48 -0
  24. package/dist/commands/auth/client/delete.js.map +1 -0
  25. package/dist/commands/auth/client/list.d.ts +6 -0
  26. package/dist/commands/auth/client/list.d.ts.map +1 -0
  27. package/dist/commands/auth/client/list.js +38 -0
  28. package/dist/commands/auth/client/list.js.map +1 -0
  29. package/dist/commands/auth/client/shared.d.ts +70 -0
  30. package/dist/commands/auth/client/shared.d.ts.map +1 -0
  31. package/dist/commands/auth/client/shared.js +140 -0
  32. package/dist/commands/auth/client/shared.js.map +1 -0
  33. package/dist/commands/auth/client/update.d.ts +8 -0
  34. package/dist/commands/auth/client/update.d.ts.map +1 -0
  35. package/dist/commands/auth/client/update.js +445 -0
  36. package/dist/commands/auth/client/update.js.map +1 -0
  37. package/dist/commands/auth/email/pull.d.ts +24 -0
  38. package/dist/commands/auth/email/pull.d.ts.map +1 -0
  39. package/dist/commands/auth/email/pull.js +100 -0
  40. package/dist/commands/auth/email/pull.js.map +1 -0
  41. package/dist/commands/auth/email/push.d.ts +8 -0
  42. package/dist/commands/auth/email/push.d.ts.map +1 -0
  43. package/dist/commands/auth/email/push.js +58 -0
  44. package/dist/commands/auth/email/push.js.map +1 -0
  45. package/dist/commands/auth/email/resend.d.ts +3 -0
  46. package/dist/commands/auth/email/resend.d.ts.map +1 -0
  47. package/dist/commands/auth/email/resend.js +7 -0
  48. package/dist/commands/auth/email/resend.js.map +1 -0
  49. package/dist/commands/auth/email/reset.d.ts +5 -0
  50. package/dist/commands/auth/email/reset.d.ts.map +1 -0
  51. package/dist/commands/auth/email/reset.js +25 -0
  52. package/dist/commands/auth/email/reset.js.map +1 -0
  53. package/dist/commands/auth/email/status.d.ts +57 -0
  54. package/dist/commands/auth/email/status.d.ts.map +1 -0
  55. package/dist/commands/auth/email/status.js +96 -0
  56. package/dist/commands/auth/email/status.js.map +1 -0
  57. package/dist/commands/auth/email/verify.d.ts +5 -0
  58. package/dist/commands/auth/email/verify.d.ts.map +1 -0
  59. package/dist/commands/auth/email/verify.js +12 -0
  60. package/dist/commands/auth/email/verify.js.map +1 -0
  61. package/dist/commands/auth/origin/add.d.ts +12 -0
  62. package/dist/commands/auth/origin/add.d.ts.map +1 -0
  63. package/dist/commands/auth/origin/add.js +153 -0
  64. package/dist/commands/auth/origin/add.js.map +1 -0
  65. package/dist/commands/auth/origin/delete.d.ts +8 -0
  66. package/dist/commands/auth/origin/delete.d.ts.map +1 -0
  67. package/dist/commands/auth/origin/delete.js +38 -0
  68. package/dist/commands/auth/origin/delete.js.map +1 -0
  69. package/dist/commands/auth/origin/list.d.ts +9 -0
  70. package/dist/commands/auth/origin/list.d.ts.map +1 -0
  71. package/dist/commands/auth/origin/list.js +52 -0
  72. package/dist/commands/auth/origin/list.js.map +1 -0
  73. package/dist/commands/backup/download.d.ts +10 -0
  74. package/dist/commands/backup/download.d.ts.map +1 -0
  75. package/dist/commands/backup/download.js +174 -0
  76. package/dist/commands/backup/download.js.map +1 -0
  77. package/dist/commands/backup/list.d.ts +11 -0
  78. package/dist/commands/backup/list.d.ts.map +1 -0
  79. package/dist/commands/backup/list.js +74 -0
  80. package/dist/commands/backup/list.js.map +1 -0
  81. package/dist/commands/claim.d.ts +6 -0
  82. package/dist/commands/claim.d.ts.map +1 -0
  83. package/dist/commands/claim.js +22 -0
  84. package/dist/commands/claim.js.map +1 -0
  85. package/dist/commands/explorer.d.ts +6 -0
  86. package/dist/commands/explorer.d.ts.map +1 -0
  87. package/dist/commands/explorer.js +13 -0
  88. package/dist/commands/explorer.js.map +1 -0
  89. package/dist/commands/info.d.ts +9 -0
  90. package/dist/commands/info.d.ts.map +1 -0
  91. package/dist/commands/info.js +41 -0
  92. package/dist/commands/info.js.map +1 -0
  93. package/dist/commands/init.d.ts +5 -0
  94. package/dist/commands/init.d.ts.map +1 -0
  95. package/dist/commands/init.js +41 -0
  96. package/dist/commands/init.js.map +1 -0
  97. package/dist/commands/initWithoutFiles.d.ts +6 -0
  98. package/dist/commands/initWithoutFiles.d.ts.map +1 -0
  99. package/dist/commands/initWithoutFiles.js +64 -0
  100. package/dist/commands/initWithoutFiles.js.map +1 -0
  101. package/dist/commands/login.d.ts +9 -0
  102. package/dist/commands/login.d.ts.map +1 -0
  103. package/dist/commands/login.js +44 -0
  104. package/dist/commands/login.js.map +1 -0
  105. package/dist/commands/logout.d.ts +3 -0
  106. package/dist/commands/logout.d.ts.map +1 -0
  107. package/dist/commands/logout.js +14 -0
  108. package/dist/commands/logout.js.map +1 -0
  109. package/dist/commands/pull.d.ts +5 -0
  110. package/dist/commands/pull.d.ts.map +1 -0
  111. package/dist/commands/pull.js +15 -0
  112. package/dist/commands/pull.js.map +1 -0
  113. package/dist/commands/push.d.ts +6 -0
  114. package/dist/commands/push.d.ts.map +1 -0
  115. package/dist/commands/push.js +20 -0
  116. package/dist/commands/push.js.map +1 -0
  117. package/dist/commands/query.d.ts +7 -0
  118. package/dist/commands/query.d.ts.map +1 -0
  119. package/dist/commands/query.js +52 -0
  120. package/dist/commands/query.js.map +1 -0
  121. package/dist/commands/webhooks/add.d.ts +9 -0
  122. package/dist/commands/webhooks/add.d.ts.map +1 -0
  123. package/dist/commands/webhooks/add.js +75 -0
  124. package/dist/commands/webhooks/add.js.map +1 -0
  125. package/dist/commands/webhooks/delete.d.ts +6 -0
  126. package/dist/commands/webhooks/delete.d.ts.map +1 -0
  127. package/dist/commands/webhooks/delete.js +17 -0
  128. package/dist/commands/webhooks/delete.js.map +1 -0
  129. package/dist/commands/webhooks/disable.d.ts +7 -0
  130. package/dist/commands/webhooks/disable.d.ts.map +1 -0
  131. package/dist/commands/webhooks/disable.js +18 -0
  132. package/dist/commands/webhooks/disable.js.map +1 -0
  133. package/dist/commands/webhooks/enable.d.ts +6 -0
  134. package/dist/commands/webhooks/enable.d.ts.map +1 -0
  135. package/dist/commands/webhooks/enable.js +18 -0
  136. package/dist/commands/webhooks/enable.js.map +1 -0
  137. package/dist/commands/webhooks/events/list.d.ts +7 -0
  138. package/dist/commands/webhooks/events/list.d.ts.map +1 -0
  139. package/dist/commands/webhooks/events/list.js +31 -0
  140. package/dist/commands/webhooks/events/list.js.map +1 -0
  141. package/dist/commands/webhooks/events/payload.d.ts +8 -0
  142. package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
  143. package/dist/commands/webhooks/events/payload.js +39 -0
  144. package/dist/commands/webhooks/events/payload.js.map +1 -0
  145. package/dist/commands/webhooks/events/resend.d.ts +8 -0
  146. package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
  147. package/dist/commands/webhooks/events/resend.js +43 -0
  148. package/dist/commands/webhooks/events/resend.js.map +1 -0
  149. package/dist/commands/webhooks/list.d.ts +8 -0
  150. package/dist/commands/webhooks/list.d.ts.map +1 -0
  151. package/dist/commands/webhooks/list.js +29 -0
  152. package/dist/commands/webhooks/list.js.map +1 -0
  153. package/dist/commands/webhooks/shared.d.ts +40 -0
  154. package/dist/commands/webhooks/shared.d.ts.map +1 -0
  155. package/dist/commands/webhooks/shared.js +248 -0
  156. package/dist/commands/webhooks/shared.js.map +1 -0
  157. package/dist/commands/webhooks/update.d.ts +10 -0
  158. package/dist/commands/webhooks/update.d.ts.map +1 -0
  159. package/dist/commands/webhooks/update.js +189 -0
  160. package/dist/commands/webhooks/update.js.map +1 -0
  161. package/dist/context/authToken.d.ts +29 -0
  162. package/dist/context/authToken.d.ts.map +1 -0
  163. package/dist/context/authToken.js +73 -0
  164. package/dist/context/authToken.js.map +1 -0
  165. package/dist/context/currentApp.d.ts +38 -0
  166. package/dist/context/currentApp.d.ts.map +1 -0
  167. package/dist/context/currentApp.js +222 -0
  168. package/dist/context/currentApp.js.map +1 -0
  169. package/dist/context/globalOpts.d.ts +11 -0
  170. package/dist/context/globalOpts.d.ts.map +1 -0
  171. package/dist/context/globalOpts.js +13 -0
  172. package/dist/context/globalOpts.js.map +1 -0
  173. package/dist/context/platformApi.d.ts +19 -0
  174. package/dist/context/platformApi.d.ts.map +1 -0
  175. package/dist/context/platformApi.js +24 -0
  176. package/dist/context/platformApi.js.map +1 -0
  177. package/dist/context/projectInfo.d.ts +30 -0
  178. package/dist/context/projectInfo.d.ts.map +1 -0
  179. package/dist/context/projectInfo.js +152 -0
  180. package/dist/context/projectInfo.js.map +1 -0
  181. package/dist/errors.d.ts +10 -0
  182. package/dist/errors.d.ts.map +1 -0
  183. package/dist/errors.js +6 -0
  184. package/dist/errors.js.map +1 -0
  185. package/dist/index.d.ts +159 -0
  186. package/dist/index.d.ts.map +1 -0
  187. package/dist/index.js +714 -0
  188. package/dist/index.js.map +1 -0
  189. package/dist/layer.d.ts +25 -0
  190. package/dist/layer.d.ts.map +1 -0
  191. package/dist/layer.js +119 -0
  192. package/dist/layer.js.map +1 -0
  193. package/dist/lib/args.d.ts +212 -0
  194. package/dist/lib/args.d.ts.map +1 -0
  195. package/dist/lib/args.js +313 -0
  196. package/dist/lib/args.js.map +1 -0
  197. package/dist/lib/backupDownload.d.ts +21 -0
  198. package/dist/lib/backupDownload.d.ts.map +1 -0
  199. package/dist/lib/backupDownload.js +151 -0
  200. package/dist/lib/backupDownload.js.map +1 -0
  201. package/dist/lib/backups.d.ts +12 -0
  202. package/dist/lib/backups.d.ts.map +1 -0
  203. package/dist/lib/backups.js +26 -0
  204. package/dist/lib/backups.js.map +1 -0
  205. package/dist/lib/config.d.ts +6 -0
  206. package/dist/lib/config.d.ts.map +1 -0
  207. package/dist/lib/config.js +39 -0
  208. package/dist/lib/config.js.map +1 -0
  209. package/dist/lib/createApp.d.ts +12 -0
  210. package/dist/lib/createApp.d.ts.map +1 -0
  211. package/dist/lib/createApp.js +15 -0
  212. package/dist/lib/createApp.js.map +1 -0
  213. package/dist/lib/email.d.ts +47 -0
  214. package/dist/lib/email.d.ts.map +1 -0
  215. package/dist/lib/email.js +71 -0
  216. package/dist/lib/email.js.map +1 -0
  217. package/dist/lib/handleEnv.d.ts +7 -0
  218. package/dist/lib/handleEnv.d.ts.map +1 -0
  219. package/dist/lib/handleEnv.js +99 -0
  220. package/dist/lib/handleEnv.js.map +1 -0
  221. package/dist/lib/http.d.ts +30 -0
  222. package/dist/lib/http.d.ts.map +1 -0
  223. package/dist/lib/http.js +55 -0
  224. package/dist/lib/http.js.map +1 -0
  225. package/dist/lib/login.d.ts +12 -0
  226. package/dist/lib/login.d.ts.map +1 -0
  227. package/dist/lib/login.js +38 -0
  228. package/dist/lib/login.js.map +1 -0
  229. package/dist/lib/oauth.d.ts +306 -0
  230. package/dist/lib/oauth.d.ts.map +1 -0
  231. package/dist/lib/oauth.js +195 -0
  232. package/dist/lib/oauth.js.map +1 -0
  233. package/dist/lib/platformApi.d.ts +5 -0
  234. package/dist/lib/platformApi.d.ts.map +1 -0
  235. package/dist/lib/platformApi.js +11 -0
  236. package/dist/lib/platformApi.js.map +1 -0
  237. package/dist/lib/pullPerms.d.ts +7 -0
  238. package/dist/lib/pullPerms.d.ts.map +1 -0
  239. package/dist/lib/pullPerms.js +41 -0
  240. package/dist/lib/pullPerms.js.map +1 -0
  241. package/dist/lib/pullSchema.d.ts +12 -0
  242. package/dist/lib/pullSchema.d.ts.map +1 -0
  243. package/dist/lib/pullSchema.js +62 -0
  244. package/dist/lib/pullSchema.js.map +1 -0
  245. package/dist/lib/pushPerms.d.ts +13 -0
  246. package/dist/lib/pushPerms.d.ts.map +1 -0
  247. package/dist/lib/pushPerms.js +54 -0
  248. package/dist/lib/pushPerms.js.map +1 -0
  249. package/dist/lib/pushSchema.d.ts +53 -0
  250. package/dist/lib/pushSchema.d.ts.map +1 -0
  251. package/dist/lib/pushSchema.js +165 -0
  252. package/dist/lib/pushSchema.js.map +1 -0
  253. package/dist/lib/ui.d.ts +18 -0
  254. package/dist/lib/ui.d.ts.map +1 -0
  255. package/dist/lib/ui.js +32 -0
  256. package/dist/lib/ui.js.map +1 -0
  257. package/dist/lib/webhooks.d.ts +27 -0
  258. package/dist/lib/webhooks.d.ts.map +1 -0
  259. package/dist/lib/webhooks.js +95 -0
  260. package/dist/lib/webhooks.js.map +1 -0
  261. package/dist/logging.d.ts +5 -0
  262. package/dist/logging.d.ts.map +1 -0
  263. package/dist/logging.js +25 -0
  264. package/dist/logging.js.map +1 -0
  265. package/dist/old.d.ts +17 -0
  266. package/dist/old.d.ts.map +1 -0
  267. package/dist/old.js +410 -0
  268. package/dist/old.js.map +1 -0
  269. package/dist/program.d.ts +3 -0
  270. package/dist/program.d.ts.map +1 -0
  271. package/dist/program.js +3 -0
  272. package/dist/program.js.map +1 -0
  273. package/dist/renderSchemaPlan.d.ts +19 -0
  274. package/dist/renderSchemaPlan.d.ts.map +1 -0
  275. package/dist/renderSchemaPlan.js +220 -0
  276. package/dist/renderSchemaPlan.js.map +1 -0
  277. package/dist/ui/index.d.ts +292 -0
  278. package/dist/ui/index.d.ts.map +1 -0
  279. package/dist/ui/index.js +1296 -0
  280. package/dist/ui/index.js.map +1 -0
  281. package/dist/ui/lib.d.ts +124 -0
  282. package/dist/ui/lib.d.ts.map +1 -0
  283. package/dist/ui/lib.js +333 -0
  284. package/dist/ui/lib.js.map +1 -0
  285. package/dist/util/findConfigCandidates.d.ts +13 -0
  286. package/dist/util/findConfigCandidates.d.ts.map +1 -0
  287. package/dist/util/findConfigCandidates.js +211 -0
  288. package/dist/util/findConfigCandidates.js.map +1 -0
  289. package/dist/util/fs.d.ts +4 -0
  290. package/dist/util/fs.d.ts.map +1 -0
  291. package/dist/util/fs.js +22 -0
  292. package/dist/util/fs.js.map +1 -0
  293. package/dist/util/getAppName.d.ts +5 -0
  294. package/dist/util/getAppName.d.ts.map +1 -0
  295. package/dist/util/getAppName.js +14 -0
  296. package/dist/util/getAppName.js.map +1 -0
  297. package/dist/util/instantConfig.d.ts +9 -0
  298. package/dist/util/instantConfig.d.ts.map +1 -0
  299. package/dist/util/instantConfig.js +13 -0
  300. package/dist/util/instantConfig.js.map +1 -0
  301. package/dist/util/isHeadlessEnvironment.d.ts +4 -0
  302. package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
  303. package/dist/util/isHeadlessEnvironment.js +11 -0
  304. package/dist/util/isHeadlessEnvironment.js.map +1 -0
  305. package/dist/util/loadConfig.d.ts +3 -0
  306. package/dist/util/loadConfig.d.ts.map +1 -0
  307. package/dist/util/loadConfig.js +72 -0
  308. package/dist/util/loadConfig.js.map +1 -0
  309. package/dist/util/loadEnv.d.ts +2 -0
  310. package/dist/util/loadEnv.d.ts.map +1 -0
  311. package/dist/util/loadEnv.js +10 -0
  312. package/dist/util/loadEnv.js.map +1 -0
  313. package/dist/util/mergeSchema.d.ts +10 -0
  314. package/dist/util/mergeSchema.d.ts.map +1 -0
  315. package/dist/util/mergeSchema.js +338 -0
  316. package/dist/util/mergeSchema.js.map +1 -0
  317. package/dist/util/projectDir.d.ts +7 -0
  318. package/dist/util/projectDir.d.ts.map +1 -0
  319. package/dist/util/projectDir.js +43 -0
  320. package/dist/util/projectDir.js.map +1 -0
  321. package/dist/util/renamePrompt.d.ts +15 -0
  322. package/dist/util/renamePrompt.d.ts.map +1 -0
  323. package/dist/util/renamePrompt.js +57 -0
  324. package/dist/util/renamePrompt.js.map +1 -0
  325. package/dist/version.d.ts +3 -0
  326. package/dist/version.d.ts.map +1 -0
  327. package/dist/version.js +3 -0
  328. package/dist/version.js.map +1 -0
  329. package/package.json +96 -0
@@ -0,0 +1,39 @@
1
+ import { Config, Effect, Option, Schema } from 'effect';
2
+ import { oauthCallbackURL } from '@superlayer/platform';
3
+ import { BadArgsError } from "../errors.js";
4
+ import { readInstantConfigFile } from "../util/instantConfig.js";
5
+ const HttpUrl = Schema.URL.pipe(Schema.filter((url) => url.protocol === 'http:' ||
6
+ url.protocol === 'https:' ||
7
+ 'Expected an HTTP(S) URL'));
8
+ export const getBaseUrl = Effect.gen(function* () {
9
+ const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(Config.option);
10
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.withDefault(false));
11
+ if (Option.isSome(setEnv)) {
12
+ return setEnv.value;
13
+ }
14
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
15
+ if (instantConfig?.apiURI !== undefined) {
16
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(Effect.mapError(() => BadArgsError.make({
17
+ message: 'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',
18
+ })));
19
+ return instantConfig.apiURI;
20
+ }
21
+ return dev ? 'http://localhost:18888' : 'https://api.interfacedb.com';
22
+ });
23
+ export const getOAuthCallbackUrl = getBaseUrl.pipe(Effect.map(oauthCallbackURL));
24
+ export const getDashUrl = Effect.gen(function* () {
25
+ const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(Config.option);
26
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.withDefault(false));
27
+ if (Option.isSome(setEnv)) {
28
+ return setEnv.value;
29
+ }
30
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
31
+ if (instantConfig?.dashURI !== undefined) {
32
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(Effect.mapError(() => BadArgsError.make({
33
+ message: 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',
34
+ })));
35
+ return instantConfig.dashURI;
36
+ }
37
+ return dev ? 'http://localhost:3140' : 'https://interfacedb.com';
38
+ });
39
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAC7B,MAAM,CAAC,MAAM,CACX,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,QAAQ,KAAK,OAAO;IACxB,GAAG,CAAC,QAAQ,KAAK,QAAQ;IACzB,yBAAyB,CAC5B,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAC7D,MAAM,CAAC,MAAM,CACd,CAAC;IACF,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,IAAI,CACvD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAC1B,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,CA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,qBAAqB,CAAC,CAAC;IACtE,IAAI,aAAa,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QACzC,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,CAC9D,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CACnB,YAAY,CAAC,IAAI,CAAC;YAChB,OAAO,EACL,qEAAqE;SACxE,CAAC,CACH,CACF,CAAC;QACF,OAAO,aAAa,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,OAAO,GAAG,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,yBAAyB,CAAC;AACnE,CAAC,CAAC,CAAC","sourcesContent":["import { Config, Effect, Option, Schema } from 'effect';\nimport { oauthCallbackURL } from '@superlayer/platform';\nimport { BadArgsError } from '../errors.ts';\nimport { readInstantConfigFile } from '../util/instantConfig.ts';\n\nconst HttpUrl = Schema.URL.pipe(\n Schema.filter(\n (url) =>\n url.protocol === 'http:' ||\n url.protocol === 'https:' ||\n 'Expected an HTTP(S) URL',\n ),\n);\n\nexport const getBaseUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(\n Config.option,\n );\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n\n if (Option.isSome(setEnv)) {\n return setEnv.value;\n }\n\n const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);\n if (instantConfig?.apiURI !== undefined) {\n yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(\n Effect.mapError(() =>\n BadArgsError.make({\n message:\n 'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',\n }),\n ),\n );\n return instantConfig.apiURI;\n }\n\n return dev ? 'http://localhost:18888' : 'https://api.interfacedb.com';\n});\n\nexport const getOAuthCallbackUrl = getBaseUrl.pipe(\n Effect.map(oauthCallbackURL),\n);\n\nexport const getDashUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(\n Config.option,\n );\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n\n if (Option.isSome(setEnv)) {\n return setEnv.value;\n }\n\n const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);\n if (instantConfig?.dashURI !== undefined) {\n yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(\n Effect.mapError(() =>\n BadArgsError.make({\n message:\n 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',\n }),\n ),\n );\n return instantConfig.dashURI;\n }\n\n return dev ? 'http://localhost:3140' : 'https://interfacedb.com';\n});\n"]}
@@ -0,0 +1,12 @@
1
+ import { Effect } from 'effect';
2
+ import { InstantHttpAuthed } from './http.ts';
3
+ declare const CreateAppError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
4
+ readonly _tag: "CreateAppError";
5
+ } & Readonly<A>;
6
+ export declare class CreateAppError extends CreateAppError_base<{
7
+ message: string;
8
+ }> {
9
+ }
10
+ export declare const createApp: (title: string, orgId?: string | undefined) => Effect.Effect<any, import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError | CreateAppError, InstantHttpAuthed>;
11
+ export {};
12
+ //# sourceMappingURL=createApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createApp.d.ts","sourceRoot":"","sources":["../../src/lib/createApp.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;;;;AAG9C,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;CAAG;AAEL,eAAO,MAAM,SAAS,sVAkBrB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { Data, Effect, Schema } from 'effect';
3
+ import { InstantHttpAuthed } from "./http.js";
4
+ import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
5
+ export class CreateAppError extends Data.TaggedError('CreateAppError') {
6
+ }
7
+ export const createApp = Effect.fn(function* (title, orgId) {
8
+ const http = yield* InstantHttpAuthed;
9
+ const id = randomUUID();
10
+ const token = randomUUID();
11
+ const app = { id, title, admin_token: token, org_id: orgId };
12
+ const res = yield* HttpClientRequest.post('/dash/apps').pipe(HttpClientRequest.bodyJson(app), Effect.flatMap(http.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
13
+ return res;
14
+ }, Effect.catchTag('HttpBodyError', (e) => new CreateAppError({ message: 'Error constructing http body' })));
15
+ //# sourceMappingURL=createApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createApp.js","sourceRoot":"","sources":["../../src/lib/createApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,OAAO,cAAe,SAAQ,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAEnE;CAAG;AAEL,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAChC,QAAQ,CAAC,EAAE,KAAa,EAAE,KAAc;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC;IACtC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAE7D,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAC1D,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC/B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAC5B,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAC9D,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,EACD,MAAM,CAAC,QAAQ,CACb,eAAe,EACf,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CACvE,CACF,CAAC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { Data, Effect, Schema } from 'effect';\nimport { InstantHttpAuthed } from './http.ts';\nimport { HttpClientRequest, HttpClientResponse } from '@effect/platform';\n\nexport class CreateAppError extends Data.TaggedError('CreateAppError')<{\n message: string;\n}> {}\n\nexport const createApp = Effect.fn(\n function* (title: string, orgId?: string) {\n const http = yield* InstantHttpAuthed;\n const id = randomUUID();\n const token = randomUUID();\n const app = { id, title, admin_token: token, org_id: orgId };\n\n const res = yield* HttpClientRequest.post('/dash/apps').pipe(\n HttpClientRequest.bodyJson(app),\n Effect.flatMap(http.execute),\n Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)),\n );\n return res;\n },\n Effect.catchTag(\n 'HttpBodyError',\n (e) => new CreateAppError({ message: 'Error constructing http body' }),\n ),\n);\n"]}
@@ -0,0 +1,47 @@
1
+ import { Effect, Schema } from 'effect';
2
+ import { CurrentApp } from '../context/currentApp.ts';
3
+ import { BadArgsError } from '../errors.ts';
4
+ import { InstantHttpAuthed } from './http.ts';
5
+ export declare const EmailConfig: Schema.Struct<{
6
+ authEmail: Schema.Struct<{
7
+ subject: typeof Schema.String;
8
+ senderName: typeof Schema.String;
9
+ senderEmail: Schema.NullishOr<typeof Schema.String>;
10
+ body: typeof Schema.String;
11
+ }>;
12
+ }>;
13
+ declare const NoEmailFileFound_base: Schema.TaggedErrorClass<NoEmailFileFound, "NoEmailFileFound", {
14
+ readonly _tag: Schema.tag<"NoEmailFileFound">;
15
+ } & {
16
+ message: typeof Schema.String;
17
+ }>;
18
+ export declare class NoEmailFileFound extends NoEmailFileFound_base {
19
+ }
20
+ export declare const readEmailConfig: (emailPath?: string) => Effect.Effect<{
21
+ readonly authEmail: {
22
+ readonly body: string;
23
+ readonly subject: string;
24
+ readonly senderName: string;
25
+ readonly senderEmail: string | null | undefined;
26
+ };
27
+ }, BadArgsError | NoEmailFileFound, never>;
28
+ export declare const sendSenderVerification: Effect.Effect<void, import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError, InstantHttpAuthed | CurrentApp>;
29
+ export declare const submitVerification: (code: string) => Effect.Effect<void, import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError, InstantHttpAuthed | CurrentApp>;
30
+ export declare const getVerification: Effect.Effect<{
31
+ readonly instant: {
32
+ readonly 'verified?': boolean | null | undefined;
33
+ };
34
+ readonly verification: {
35
+ readonly Confirmed: boolean;
36
+ readonly ID: number;
37
+ readonly EmailAddress: string;
38
+ readonly DKIMHost: string;
39
+ readonly ReturnPathDomain: string;
40
+ readonly DKIMPendingTextValue: string;
41
+ readonly ReturnPathDomainCNAMEValue: string;
42
+ readonly DKIMTextValue: string;
43
+ readonly DKIMPendingHost: string;
44
+ } | null | undefined;
45
+ }, import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError, InstantHttpAuthed | CurrentApp>;
46
+ export {};
47
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,eAAO,MAAM,WAAW;;;;;;;EAOtB,CAAC;;;;;;AAEH,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;AAEL,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM;;;;;;;0CAwB9C,CAAC;AAEL,eAAO,MAAM,sBAAsB,+LAIjC,CAAC;AAEH,eAAO,MAAM,kBAAkB,iNAS7B,CAAC;AAmBH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;iRAU1B,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { HttpBody, HttpClientResponse } from '@effect/platform';
2
+ import { Effect, Schema } from 'effect';
3
+ import { CurrentApp } from "../context/currentApp.js";
4
+ import { BadArgsError } from "../errors.js";
5
+ import { readLocalEmailFile } from '../old.js';
6
+ import { InstantHttpAuthed } from "./http.js";
7
+ export const EmailConfig = Schema.Struct({
8
+ authEmail: Schema.Struct({
9
+ subject: Schema.String,
10
+ senderName: Schema.String,
11
+ senderEmail: Schema.NullishOr(Schema.String),
12
+ body: Schema.String,
13
+ }),
14
+ });
15
+ export class NoEmailFileFound extends Schema.TaggedError('NoEmailFileFound')('NoEmailFileFound', {
16
+ message: Schema.String,
17
+ }) {
18
+ }
19
+ export const readEmailConfig = (emailPath) => Effect.gen(function* () {
20
+ const emailFile = yield* Effect.tryPromise({
21
+ try: () => readLocalEmailFile(emailPath),
22
+ catch: (e) => BadArgsError.make({
23
+ message: `Error reading instant.email.ts file: ${e}`,
24
+ }),
25
+ });
26
+ if (!emailFile) {
27
+ return yield* NoEmailFileFound.make({
28
+ message: "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.)",
29
+ });
30
+ }
31
+ return yield* Schema.decodeUnknown(EmailConfig)(emailFile.email).pipe(Effect.catchTag('ParseError', (e) => BadArgsError.make({
32
+ message: `Invalid instant.email.ts file: ${e.message}`,
33
+ })));
34
+ });
35
+ export const sendSenderVerification = Effect.gen(function* () {
36
+ const http = yield* InstantHttpAuthed;
37
+ const { appId } = yield* CurrentApp;
38
+ yield* http.post(`/dash/apps/${appId}/sender-verification/send-magic-code`);
39
+ });
40
+ export const submitVerification = Effect.fn(function* (code) {
41
+ const http = yield* InstantHttpAuthed;
42
+ const { appId } = yield* CurrentApp;
43
+ yield* http.post(`/dash/apps/${appId}/sender-verification/verify-magic-code`, {
44
+ body: HttpBody.unsafeJson({ code }),
45
+ });
46
+ });
47
+ const VerificationSchema = Schema.Struct({
48
+ instant: Schema.Struct({
49
+ 'verified?': Schema.Boolean.pipe(Schema.NullishOr),
50
+ }),
51
+ verification: Schema.Struct({
52
+ Confirmed: Schema.Boolean,
53
+ ID: Schema.Number,
54
+ EmailAddress: Schema.String,
55
+ DKIMHost: Schema.String,
56
+ ReturnPathDomain: Schema.String,
57
+ DKIMPendingTextValue: Schema.String,
58
+ ReturnPathDomainCNAMEValue: Schema.String,
59
+ DKIMTextValue: Schema.String,
60
+ DKIMPendingHost: Schema.String,
61
+ }).pipe(Schema.NullishOr),
62
+ });
63
+ export const getVerification = Effect.gen(function* () {
64
+ const http = yield* InstantHttpAuthed;
65
+ const { appId } = yield* CurrentApp;
66
+ const response = yield* http
67
+ .get(`/dash/apps/${appId}/sender-verification`)
68
+ .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(VerificationSchema)));
69
+ return response;
70
+ });
71
+ //# sourceMappingURL=email.js.map
@@ -0,0 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M,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;KACnD,CAAC;IACF,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC,OAAO;QACzB,EAAE,EAAE,MAAM,CAAC,MAAM;QACjB,YAAY,EAAE,MAAM,CAAC,MAAM;QAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM;QACvB,gBAAgB,EAAE,MAAM,CAAC,MAAM;QAC/B,oBAAoB,EAAE,MAAM,CAAC,MAAM;QACnC,0BAA0B,EAAE,MAAM,CAAC,MAAM;QACzC,aAAa,EAAE,MAAM,CAAC,MAAM;QAC5B,eAAe,EAAE,MAAM,CAAC,MAAM;KAC/B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACjD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC;IACtC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;IAEpC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,IAAI;SACzB,GAAG,CAAC,cAAc,KAAK,sBAAsB,CAAC;SAC9C,IAAI,CACH,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,CACtE,CAAC;IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["import { HttpBody, HttpClientResponse } from '@effect/platform';\nimport { Effect, Schema } from 'effect';\nimport { CurrentApp } from '../context/currentApp.ts';\nimport { BadArgsError } from '../errors.ts';\nimport { readLocalEmailFile } from '../old.js';\nimport { InstantHttpAuthed } from './http.ts';\n\nexport const EmailConfig = Schema.Struct({\n authEmail: Schema.Struct({\n subject: Schema.String,\n senderName: Schema.String,\n senderEmail: Schema.NullishOr(Schema.String),\n body: Schema.String,\n }),\n});\n\nexport class NoEmailFileFound extends Schema.TaggedError<NoEmailFileFound>(\n 'NoEmailFileFound',\n)('NoEmailFileFound', {\n message: Schema.String,\n}) {}\n\nexport const readEmailConfig = (emailPath?: string) =>\n Effect.gen(function* () {\n const emailFile = yield* Effect.tryPromise({\n try: () => readLocalEmailFile(emailPath),\n catch: (e) =>\n BadArgsError.make({\n message: `Error reading instant.email.ts file: ${e}`,\n }),\n });\n\n if (!emailFile) {\n return yield* NoEmailFileFound.make({\n message:\n \"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.)\",\n });\n }\n\n return yield* Schema.decodeUnknown(EmailConfig)(emailFile.email).pipe(\n Effect.catchTag('ParseError', (e) =>\n BadArgsError.make({\n message: `Invalid instant.email.ts file: ${e.message}`,\n }),\n ),\n );\n });\n\nexport const sendSenderVerification = Effect.gen(function* () {\n const http = yield* InstantHttpAuthed;\n const { appId } = yield* CurrentApp;\n yield* http.post(`/dash/apps/${appId}/sender-verification/send-magic-code`);\n});\n\nexport const submitVerification = Effect.fn(function* (code: string) {\n const http = yield* InstantHttpAuthed;\n const { appId } = yield* CurrentApp;\n yield* http.post(\n `/dash/apps/${appId}/sender-verification/verify-magic-code`,\n {\n body: HttpBody.unsafeJson({ code }),\n },\n );\n});\n\nconst VerificationSchema = Schema.Struct({\n instant: Schema.Struct({\n 'verified?': Schema.Boolean.pipe(Schema.NullishOr),\n }),\n verification: Schema.Struct({\n Confirmed: Schema.Boolean,\n ID: Schema.Number,\n EmailAddress: Schema.String,\n DKIMHost: Schema.String,\n ReturnPathDomain: Schema.String,\n DKIMPendingTextValue: Schema.String,\n ReturnPathDomainCNAMEValue: Schema.String,\n DKIMTextValue: Schema.String,\n DKIMPendingHost: Schema.String,\n }).pipe(Schema.NullishOr),\n});\n\nexport const getVerification = Effect.gen(function* () {\n const http = yield* InstantHttpAuthed;\n const { appId } = yield* CurrentApp;\n\n const response = yield* http\n .get(`/dash/apps/${appId}/sender-verification`)\n .pipe(\n Effect.flatMap(HttpClientResponse.schemaBodyJson(VerificationSchema)),\n );\n return response;\n});\n"]}
@@ -0,0 +1,7 @@
1
+ import { Effect } from 'effect';
2
+ import type { CurrentAppInfo } from '../context/currentApp.ts';
3
+ import { ProjectInfo } from '../context/projectInfo.ts';
4
+ import { GlobalOpts } from '../context/globalOpts.ts';
5
+ import { FileSystem, Path } from '@effect/platform';
6
+ export declare const handleEnv: (app: CurrentAppInfo) => Effect.Effect<void, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | import("@effect/platform/Error").PlatformError, GlobalOpts | ProjectInfo | FileSystem.FileSystem | Path.Path>;
7
+ //# sourceMappingURL=handleEnv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleEnv.d.ts","sourceRoot":"","sources":["../../src/lib/handleEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAoB,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAOpD,eAAO,MAAM,SAAS,uRAuDpB,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { Effect } from 'effect';
2
+ import { potentialEnvs } from "../context/currentApp.js";
3
+ import { ProjectInfo, ProjectInfoError } from "../context/projectInfo.js";
4
+ import { readPackage } from 'pkg-types';
5
+ import { GlobalOpts } from "../context/globalOpts.js";
6
+ import { FileSystem, Path } from '@effect/platform';
7
+ import chalk from 'chalk';
8
+ import { getDashUrl } from "./http.js";
9
+ import { promptOk } from "./ui.js";
10
+ import { link } from "../logging.js";
11
+ import boxen from 'boxen';
12
+ export const handleEnv = Effect.fn(function* (app) {
13
+ const opts = yield* GlobalOpts;
14
+ const { pkgDir } = yield* ProjectInfo;
15
+ const envType = yield* detectEnvType;
16
+ const envName = potentialEnvs[envType];
17
+ const envFile = opts.env ?? '.env';
18
+ const fs = yield* FileSystem.FileSystem;
19
+ const path = yield* Path.Path;
20
+ const hasEnvFile = yield* fs.exists(path.join(pkgDir, envFile));
21
+ const dashOrigin = yield* getDashUrl;
22
+ if (hasEnvFile) {
23
+ return printDotEnvInfo(envType, app.appId, dashOrigin);
24
+ }
25
+ const saveExtraInfo = envFile !== '.env' ? chalk.green(' (will create `' + envFile + '`)') : '';
26
+ const promptText = [
27
+ `Looks like you don't have a ${chalk.green(`\`${envFile}\``)} file yet.`,
28
+ `If we set ${chalk.green(envName)} & ${chalk.green('INSTANT_APP_ADMIN_TOKEN')}, we can remember the app that you chose for all`,
29
+ 'future commands.',
30
+ 'Want us to create this env file for you?' + saveExtraInfo,
31
+ ].join('\n');
32
+ const ok = yield* promptOk({
33
+ inline: true,
34
+ promptText,
35
+ modifyOutput: (a) => boxen(a, {
36
+ dimBorder: true,
37
+ padding: { left: 1, right: 1 },
38
+ }),
39
+ }, true);
40
+ if (!ok) {
41
+ yield* Effect.log(`No .env file created. You can always set ${chalk.green('`' + envName + '`')} later. \n`);
42
+ return;
43
+ }
44
+ const content = [
45
+ [envName, app.appId],
46
+ ['INSTANT_APP_ADMIN_TOKEN', app.adminToken],
47
+ ]
48
+ .map(([k, v]) => `${k}=${v}`)
49
+ .join('\n') + '\n';
50
+ yield* fs.writeFileString(path.join(pkgDir, envFile), content);
51
+ if (envFile !== '.env') {
52
+ yield* Effect.log(`Created ${chalk.green(envFile)}!`);
53
+ }
54
+ else {
55
+ yield* Effect.log(`Created ${chalk.green('.env')} file!`);
56
+ }
57
+ });
58
+ const detectEnvType = Effect.gen(function* () {
59
+ const pkgJson = yield* Effect.tryPromise({
60
+ try: () => readPackage(),
61
+ catch: () => new ProjectInfoError({ message: "Couldn't read package.json" }),
62
+ });
63
+ if (pkgJson.dependencies?.next) {
64
+ return 'next';
65
+ }
66
+ if (pkgJson.devDependencies?.svelte) {
67
+ return 'svelte';
68
+ }
69
+ if (pkgJson.devDependencies?.vite) {
70
+ return 'vite';
71
+ }
72
+ if (pkgJson.dependencies?.expo) {
73
+ return 'expo';
74
+ }
75
+ if (pkgJson.dependencies?.nuxt) {
76
+ return 'nuxt';
77
+ }
78
+ if (pkgJson.dependencies?.['@types/bun']) {
79
+ return 'bun';
80
+ }
81
+ return 'catchall';
82
+ }).pipe(Effect.catchTag('ProjectInfoError', () => Effect.succeed('catchall')));
83
+ function printDotEnvInfo(envType, appId, dashOrigin) {
84
+ console.log(`\nPicked app ${chalk.green(appId)}!\n`);
85
+ console.log(`To use this app automatically from now on, update your ${chalk.green('`.env`')} file:`);
86
+ const picked = potentialEnvs[envType];
87
+ const rest = { ...potentialEnvs };
88
+ delete rest[envType];
89
+ console.log(` ${chalk.green(picked)}=${appId}`);
90
+ const otherEnvs = Object.values(rest);
91
+ otherEnvs.sort();
92
+ const otherEnvStr = otherEnvs.map((x) => ' ' + chalk.green(x)).join('\n');
93
+ console.log(`Alternative names: \n${otherEnvStr} \n`);
94
+ console.log(`${link(appDashUrl(appId, dashOrigin))}: ${appDashUrl(appId, dashOrigin)}\n`);
95
+ }
96
+ function appDashUrl(id, instantOrigin) {
97
+ return `${instantOrigin}/dash?s=main&t=home&app=${id}`;
98
+ }
99
+ //# sourceMappingURL=handleEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleEnv.js","sourceRoot":"","sources":["../../src/lib/handleEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE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["import { Effect } from 'effect';\nimport { potentialEnvs } from '../context/currentApp.ts';\nimport type { CurrentAppInfo } from '../context/currentApp.ts';\nimport { ProjectInfo, ProjectInfoError } from '../context/projectInfo.ts';\nimport { readPackage } from 'pkg-types';\nimport { GlobalOpts } from '../context/globalOpts.ts';\nimport { FileSystem, Path } from '@effect/platform';\nimport chalk from 'chalk';\nimport { getDashUrl } from './http.ts';\nimport { promptOk } from './ui.ts';\nimport { link } from '../logging.ts';\nimport boxen from 'boxen';\n\nexport const handleEnv = Effect.fn(function* (app: CurrentAppInfo) {\n const opts = yield* GlobalOpts;\n const { pkgDir } = yield* ProjectInfo;\n const envType = yield* detectEnvType;\n const envName = potentialEnvs[envType];\n const envFile = opts.env ?? '.env';\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const hasEnvFile = yield* fs.exists(path.join(pkgDir, envFile));\n const dashOrigin = yield* getDashUrl;\n if (hasEnvFile) {\n return printDotEnvInfo(envType, app.appId, dashOrigin);\n }\n const saveExtraInfo =\n envFile !== '.env' ? chalk.green(' (will create `' + envFile + '`)') : '';\n const promptText = [\n `Looks like you don't have a ${chalk.green(`\\`${envFile}\\``)} file yet.`,\n `If we set ${chalk.green(envName)} & ${chalk.green('INSTANT_APP_ADMIN_TOKEN')}, we can remember the app that you chose for all`,\n 'future commands.',\n 'Want us to create this env file for you?' + saveExtraInfo,\n ].join('\\n');\n\n const ok = yield* promptOk(\n {\n inline: true,\n promptText,\n modifyOutput: (a) =>\n boxen(a, {\n dimBorder: true,\n padding: { left: 1, right: 1 },\n }),\n },\n true,\n );\n if (!ok) {\n yield* Effect.log(\n `No .env file created. You can always set ${chalk.green('`' + envName + '`')} later. \\n`,\n );\n return;\n }\n const content =\n [\n [envName, app.appId],\n ['INSTANT_APP_ADMIN_TOKEN', app.adminToken],\n ]\n .map(([k, v]) => `${k}=${v}`)\n .join('\\n') + '\\n';\n\n yield* fs.writeFileString(path.join(pkgDir, envFile), content);\n\n if (envFile !== '.env') {\n yield* Effect.log(`Created ${chalk.green(envFile)}!`);\n } else {\n yield* Effect.log(`Created ${chalk.green('.env')} file!`);\n }\n});\n\nconst detectEnvType = Effect.gen(function* () {\n const pkgJson = yield* Effect.tryPromise({\n try: () => readPackage(),\n catch: () =>\n new ProjectInfoError({ message: \"Couldn't read package.json\" }),\n });\n if (pkgJson.dependencies?.next) {\n return 'next';\n }\n if (pkgJson.devDependencies?.svelte) {\n return 'svelte';\n }\n if (pkgJson.devDependencies?.vite) {\n return 'vite';\n }\n if (pkgJson.dependencies?.expo) {\n return 'expo';\n }\n if (pkgJson.dependencies?.nuxt) {\n return 'nuxt';\n }\n if (pkgJson.dependencies?.['@types/bun']) {\n return 'bun';\n }\n return 'catchall';\n}).pipe(Effect.catchTag('ProjectInfoError', () => Effect.succeed('catchall')));\n\nfunction printDotEnvInfo(\n envType: keyof typeof potentialEnvs,\n appId: string,\n dashOrigin: string,\n) {\n console.log(`\\nPicked app ${chalk.green(appId)}!\\n`);\n console.log(\n `To use this app automatically from now on, update your ${chalk.green('`.env`')} file:`,\n );\n const picked = potentialEnvs[envType];\n const rest = { ...potentialEnvs };\n delete rest[envType];\n console.log(` ${chalk.green(picked)}=${appId}`);\n const otherEnvs = Object.values(rest);\n otherEnvs.sort();\n const otherEnvStr = otherEnvs.map((x) => ' ' + chalk.green(x)).join('\\n');\n console.log(`Alternative names: \\n${otherEnvStr} \\n`);\n console.log(\n `${link(appDashUrl(appId, dashOrigin))}: ${appDashUrl(appId, dashOrigin)}\\n`,\n );\n}\n\nfunction appDashUrl(id: string, instantOrigin: string) {\n return `${instantOrigin}/dash?s=main&t=home&app=${id}`;\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { HttpClient } from '@effect/platform';
2
+ import { Context, Layer, Schema } from 'effect';
3
+ import { AuthToken } from '../context/authToken.ts';
4
+ import { TimeoutException } from 'effect/Cause';
5
+ import { RequestError } from '@effect/platform/HttpClientError';
6
+ export { getBaseUrl, getDashUrl } from './config.ts';
7
+ declare const InstantHttp_base: Context.TagClass<InstantHttp, "@superlayer/cli/new/lib/http/InstantHttp", HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError, never>>;
8
+ export declare class InstantHttp extends InstantHttp_base {
9
+ }
10
+ declare const InstantHttpAuthed_base: Context.TagClass<InstantHttpAuthed, "@superlayer/cli/new/lib/http/InstantHttpAuthed", HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError, never>>;
11
+ export declare class InstantHttpAuthed extends InstantHttpAuthed_base {
12
+ }
13
+ declare const InstantHttpError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
14
+ readonly _tag: "InstantHttpError";
15
+ } & Readonly<A>;
16
+ export declare class InstantHttpError extends InstantHttpError_base<{
17
+ methodAndUrl: string;
18
+ } & typeof InstantTypicalHttpErrorResponse.Type> {
19
+ }
20
+ export declare const withCommand: (command: string) => (client: HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>) => HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError, never>;
21
+ declare const InstantTypicalHttpErrorResponse_base: Schema.Struct<{
22
+ message: typeof Schema.String;
23
+ type: Schema.optional<typeof Schema.String>;
24
+ hint: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Any>>;
25
+ }>;
26
+ declare class InstantTypicalHttpErrorResponse extends InstantTypicalHttpErrorResponse_base {
27
+ }
28
+ export declare const InstantHttpLive: Layer.Layer<InstantHttp, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, HttpClient.HttpClient>;
29
+ export declare const InstantHttpAuthedLive: Layer.Layer<InstantHttpAuthed, never, InstantHttp | AuthToken>;
30
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAgB,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;;AAErD,qBAAa,WAAY,SAAQ,gBAK9B;CAAG;;AAEN,qBAAa,iBAAkB,SAAQ,sBAKpC;CAAG;;;;AAEN,qBAAa,gBAAiB,SAAQ,sBACpC;IACE,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,+BAA+B,CAAC,IAAI,CAChD;CAAG;AAGJ,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,MAEvC,QAAQ,UAAU,CAAC,UAAU,CAAC,IAAI,CAChC,gBAAgB,GAAG,gBAAgB,GAAG,YAAY,CACnD,0FAOJ,CAAC;;;;;;AAEF,cAAM,+BAAgC,SAAQ,oCAM5C;CAAG;AAEL,eAAO,MAAM,eAAe,2KAwD3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,gEAiBjC,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { HttpClient, HttpClientRequest } from '@effect/platform';
2
+ import { version } from '@superlayer/version';
3
+ import { Context, Data, Effect, Layer, Schema } from 'effect';
4
+ import { AuthToken } from "../context/authToken.js";
5
+ import { TimeoutException } from 'effect/Cause';
6
+ import { RequestError } from '@effect/platform/HttpClientError';
7
+ import { getBaseUrl } from "./config.js";
8
+ export { getBaseUrl, getDashUrl } from "./config.js";
9
+ export class InstantHttp extends Context.Tag('@superlayer/cli/new/lib/http/InstantHttp')() {
10
+ }
11
+ export class InstantHttpAuthed extends Context.Tag('@superlayer/cli/new/lib/http/InstantHttpAuthed')() {
12
+ }
13
+ export class InstantHttpError extends Data.TaggedError('InstantHttpError') {
14
+ }
15
+ // Pipe on an http client to set the command header
16
+ export const withCommand = (command) => {
17
+ return (client) => client.pipe(HttpClient.mapRequest((r) => r.pipe(HttpClientRequest.setHeader(`X-Instant-Command`, command))));
18
+ };
19
+ class InstantTypicalHttpErrorResponse extends Schema.Struct({
20
+ message: Schema.String,
21
+ type: Schema.String.pipe(Schema.optional),
22
+ hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(Schema.optional),
23
+ }) {
24
+ }
25
+ export const InstantHttpLive = Layer.effect(InstantHttp, Effect.gen(function* () {
26
+ const client = yield* HttpClient.HttpClient;
27
+ const baseUrl = yield* getBaseUrl;
28
+ return client.pipe(HttpClient.mapRequest((r) => r.pipe(HttpClientRequest.prependUrl(baseUrl), HttpClientRequest.setHeader('X-Instant-Source', '@superlayer/cli'), HttpClientRequest.setHeader('X-Instant-Version', version))), HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))), HttpClient.filterStatusOk, // makes non 2xx http codes error
29
+ // parses the non 2xx errors into known instant error shape
30
+ HttpClient.transformResponse((r) => r.pipe(Effect.catchTag('ResponseError', (requestError) => Effect.gen(function* () {
31
+ const jsonBody = yield* requestError.response.json.pipe(Effect.andThen(Schema.decodeUnknown(InstantTypicalHttpErrorResponse)), Effect.mapError((e) => new InstantHttpError({
32
+ message: 'Error making request to ' + requestError.methodAndUrl,
33
+ type: e._tag,
34
+ methodAndUrl: requestError.methodAndUrl,
35
+ })));
36
+ // The hint.message is usually better error message
37
+ let message = jsonBody.message;
38
+ if (jsonBody.hint?.message &&
39
+ typeof jsonBody.hint.message === 'string') {
40
+ message = jsonBody.hint.message;
41
+ }
42
+ return yield* new InstantHttpError({
43
+ message: message,
44
+ methodAndUrl: requestError.methodAndUrl,
45
+ hint: jsonBody.hint,
46
+ type: jsonBody.type || 'Unknown type',
47
+ });
48
+ })))));
49
+ }));
50
+ export const InstantHttpAuthedLive = Layer.effect(InstantHttpAuthed, Effect.gen(function* () {
51
+ const http = yield* InstantHttp;
52
+ const authToken = yield* AuthToken;
53
+ return http.pipe(HttpClient.mapRequestEffect((r) => authToken.getAuthToken.pipe(Effect.map((token) => r.pipe(HttpClientRequest.setHeader('Authorization', `Bearer ${token}`))))));
54
+ }));
55
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,GAAG,CAC1C,0CAA0C,CAC3C,EAGE;CAAG;AAEN,MAAM,OAAO,iBAAkB,SAAQ,OAAO,CAAC,GAAG,CAChD,gDAAgD,CACjD,EAGE;CAAG;AAEN,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAIxE;CAAG;AAEJ,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE;IAC7C,OAAO,CACL,MAEC,EACD,EAAE,CACF,MAAM,CAAC,IAAI,CACT,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAC1B,CAAC,CAAC,IAAI,CAAC,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C,CAAC,SAAS,CAAC;IACnC,OAAO,IAAI,CAAC,IAAI,CACd,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAAE,CAChC,SAAS,CAAC,YAAY,CAAC,IAAI,CACzB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACnB,CAAC,CAAC,IAAI,CACJ,iBAAiB,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAChE,CACF,CACF,CACF,CACF,CAAC;AACJ,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { HttpClient, HttpClientRequest } from '@effect/platform';\nimport { version } from '@superlayer/version';\nimport { Context, Data, Effect, Layer, Schema } from 'effect';\nimport { AuthToken } from '../context/authToken.ts';\nimport { TimeoutException } from 'effect/Cause';\nimport { RequestError } from '@effect/platform/HttpClientError';\nimport { getBaseUrl } from './config.ts';\n\nexport { getBaseUrl, getDashUrl } from './config.ts';\n\nexport class InstantHttp extends Context.Tag(\n '@superlayer/cli/new/lib/http/InstantHttp',\n)<\n InstantHttp,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpAuthed extends Context.Tag(\n '@superlayer/cli/new/lib/http/InstantHttpAuthed',\n)<\n InstantHttpAuthed,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpError extends Data.TaggedError('InstantHttpError')<\n {\n methodAndUrl: string;\n } & typeof InstantTypicalHttpErrorResponse.Type\n> {}\n\n// Pipe on an http client to set the command header\nexport const withCommand = (command: string) => {\n return (\n client: HttpClient.HttpClient.With<\n InstantHttpError | TimeoutException | RequestError\n >,\n ) =>\n client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(HttpClientRequest.setHeader(`X-Instant-Command`, command)),\n ),\n );\n};\n\nclass InstantTypicalHttpErrorResponse extends Schema.Struct({\n message: Schema.String,\n type: Schema.String.pipe(Schema.optional),\n hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(\n Schema.optional,\n ),\n}) {}\n\nexport const InstantHttpLive = Layer.effect(\n InstantHttp,\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient;\n const baseUrl = yield* getBaseUrl;\n return client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(\n HttpClientRequest.prependUrl(baseUrl),\n HttpClientRequest.setHeader('X-Instant-Source', '@superlayer/cli'),\n HttpClientRequest.setHeader('X-Instant-Version', version),\n ),\n ),\n HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))),\n HttpClient.filterStatusOk, // makes non 2xx http codes error\n // parses the non 2xx errors into known instant error shape\n HttpClient.transformResponse((r) =>\n r.pipe(\n Effect.catchTag('ResponseError', (requestError) =>\n Effect.gen(function* () {\n const jsonBody = yield* requestError.response.json.pipe(\n Effect.andThen(\n Schema.decodeUnknown(InstantTypicalHttpErrorResponse),\n ),\n Effect.mapError(\n (e) =>\n new InstantHttpError({\n message:\n 'Error making request to ' + requestError.methodAndUrl,\n type: e._tag,\n methodAndUrl: requestError.methodAndUrl,\n }),\n ),\n );\n\n // The hint.message is usually better error message\n let message = jsonBody.message;\n if (\n jsonBody.hint?.message &&\n typeof jsonBody.hint.message === 'string'\n ) {\n message = jsonBody.hint.message;\n }\n\n return yield* new InstantHttpError({\n message: message,\n methodAndUrl: requestError.methodAndUrl,\n hint: jsonBody.hint,\n type: jsonBody.type || 'Unknown type',\n });\n }),\n ),\n ),\n ),\n );\n }),\n);\n\nexport const InstantHttpAuthedLive = Layer.effect(\n InstantHttpAuthed,\n Effect.gen(function* () {\n const http = yield* InstantHttp;\n const authToken = yield* AuthToken;\n return http.pipe(\n HttpClient.mapRequestEffect((r) =>\n authToken.getAuthToken.pipe(\n Effect.map((token) =>\n r.pipe(\n HttpClientRequest.setHeader('Authorization', `Bearer ${token}`),\n ),\n ),\n ),\n ),\n );\n }),\n);\n"]}
@@ -0,0 +1,12 @@
1
+ import { Effect } from 'effect';
2
+ import { InstantHttp } from './http.ts';
3
+ export declare const getLoginTicketAndSecret: Effect.Effect<{
4
+ readonly secret: string;
5
+ readonly ticket: string;
6
+ }, import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError, InstantHttp>;
7
+ export declare const waitForAuthToken: (secret: string) => Effect.Effect<{
8
+ readonly token: string;
9
+ readonly email: string;
10
+ }, import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError, InstantHttp>;
11
+ export declare const saveConfigAuthToken: (token: string) => Effect.Effect<void, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, never>;
12
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/lib/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,WAAW,EAAe,MAAM,WAAW,CAAC;AAerD,eAAO,MAAM,uBAAuB;;;8PAOlC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;8PAiB3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,yKAG9B,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { Effect, Schedule, Schema } from 'effect';
2
+ import { InstantHttp, withCommand } from "./http.js";
3
+ import { HttpClientRequest, HttpClientResponse } from '@effect/platform';
4
+ import { writeAuthToken } from "../auth/index.js";
5
+ import { getBaseUrl } from "./config.js";
6
+ const LoginInfo = Schema.Struct({
7
+ secret: Schema.String,
8
+ ticket: Schema.String,
9
+ });
10
+ const TokenResult = Schema.Struct({
11
+ token: Schema.String,
12
+ email: Schema.String,
13
+ });
14
+ export const getLoginTicketAndSecret = Effect.gen(function* () {
15
+ const http = yield* InstantHttp;
16
+ const res = yield* http
17
+ .pipe(withCommand('login'))
18
+ .post('/dash/cli/auth/register')
19
+ .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(LoginInfo)));
20
+ return res;
21
+ });
22
+ export const waitForAuthToken = Effect.fn(function* (secret) {
23
+ const http = (yield* InstantHttp).pipe(withCommand('login'));
24
+ const res = yield* HttpClientRequest.post('/dash/cli/auth/check').pipe(HttpClientRequest.bodyUnsafeJson({
25
+ secret,
26
+ }), http.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenResult)), Effect.retry({
27
+ while: (e) => e._tag === 'InstantHttpError' &&
28
+ e.hint?.errors?.at(0)?.issue === 'waiting-for-user',
29
+ schedule: Schedule.fixed('1 seconds'),
30
+ times: 120,
31
+ }));
32
+ return res;
33
+ });
34
+ export const saveConfigAuthToken = Effect.fn(function* (token) {
35
+ const apiURI = yield* getBaseUrl;
36
+ yield* Effect.tryPromise(() => writeAuthToken(apiURI, token));
37
+ });
38
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/lib/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM;CACtB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,M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O,GAAG,CAAC;AACb,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAa;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC;IACjC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC","sourcesContent":["import { Effect, Schedule, Schema } from 'effect';\nimport { InstantHttp, withCommand } from './http.ts';\nimport { HttpClientRequest, HttpClientResponse } from '@effect/platform';\nimport { writeAuthToken } from '../auth/index.ts';\nimport { getBaseUrl } from './config.ts';\n\nconst LoginInfo = Schema.Struct({\n secret: Schema.String,\n ticket: Schema.String,\n});\n\nconst TokenResult = Schema.Struct({\n token: Schema.String,\n email: Schema.String,\n});\n\nexport const getLoginTicketAndSecret = Effect.gen(function* () {\n const http = yield* InstantHttp;\n const res = yield* http\n .pipe(withCommand('login'))\n .post('/dash/cli/auth/register')\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(LoginInfo)));\n return res;\n});\n\nexport const waitForAuthToken = Effect.fn(function* (secret: string) {\n const http = (yield* InstantHttp).pipe(withCommand('login'));\n const res = yield* HttpClientRequest.post('/dash/cli/auth/check').pipe(\n HttpClientRequest.bodyUnsafeJson({\n secret,\n }),\n http.execute,\n Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenResult)),\n Effect.retry({\n while: (e) =>\n e._tag === 'InstantHttpError' &&\n e.hint?.errors?.at(0)?.issue === 'waiting-for-user',\n schedule: Schedule.fixed('1 seconds'),\n times: 120,\n }),\n );\n return res;\n});\n\nexport const saveConfigAuthToken = Effect.fn(function* (token: string) {\n const apiURI = yield* getBaseUrl;\n yield* Effect.tryPromise(() => writeAuthToken(apiURI, token));\n});\n"]}