everything-dev 0.3.2 → 1.3.2

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 (308) hide show
  1. package/README.md +64 -0
  2. package/cli.js +10 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/api-contract.cjs +172 -0
  5. package/dist/api-contract.cjs.map +1 -0
  6. package/dist/api-contract.mjs +171 -0
  7. package/dist/api-contract.mjs.map +1 -0
  8. package/dist/api.cjs +124 -0
  9. package/dist/api.cjs.map +1 -0
  10. package/dist/api.d.cts +36 -0
  11. package/dist/api.d.cts.map +1 -0
  12. package/dist/api.d.mts +36 -0
  13. package/dist/api.d.mts.map +1 -0
  14. package/dist/api.mjs +119 -0
  15. package/dist/api.mjs.map +1 -0
  16. package/dist/app.cjs +156 -0
  17. package/dist/app.cjs.map +1 -0
  18. package/dist/app.mjs +153 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/cli/catalog.cjs +30 -0
  21. package/dist/cli/catalog.cjs.map +1 -0
  22. package/dist/cli/catalog.mjs +29 -0
  23. package/dist/cli/catalog.mjs.map +1 -0
  24. package/dist/cli/help.cjs +16 -0
  25. package/dist/cli/help.cjs.map +1 -0
  26. package/dist/cli/help.mjs +16 -0
  27. package/dist/cli/help.mjs.map +1 -0
  28. package/dist/cli/init.cjs +317 -0
  29. package/dist/cli/init.cjs.map +1 -0
  30. package/dist/cli/init.d.cts +36 -0
  31. package/dist/cli/init.d.cts.map +1 -0
  32. package/dist/cli/init.d.mts +36 -0
  33. package/dist/cli/init.d.mts.map +1 -0
  34. package/dist/cli/init.mjs +309 -0
  35. package/dist/cli/init.mjs.map +1 -0
  36. package/dist/cli/parse.cjs +96 -0
  37. package/dist/cli/parse.cjs.map +1 -0
  38. package/dist/cli/parse.mjs +95 -0
  39. package/dist/cli/parse.mjs.map +1 -0
  40. package/dist/cli/prompts.cjs +42 -0
  41. package/dist/cli/prompts.cjs.map +1 -0
  42. package/dist/cli/prompts.mjs +41 -0
  43. package/dist/cli/prompts.mjs.map +1 -0
  44. package/dist/cli.cjs +167 -0
  45. package/dist/cli.cjs.map +1 -0
  46. package/dist/cli.d.cts +1 -0
  47. package/dist/cli.d.mts +1 -0
  48. package/dist/cli.mjs +166 -0
  49. package/dist/cli.mjs.map +1 -0
  50. package/dist/components/dev-view.cjs +307 -0
  51. package/dist/components/dev-view.cjs.map +1 -0
  52. package/dist/components/dev-view.mjs +306 -0
  53. package/dist/components/dev-view.mjs.map +1 -0
  54. package/dist/components/streaming-view.cjs +146 -0
  55. package/dist/components/streaming-view.cjs.map +1 -0
  56. package/dist/components/streaming-view.mjs +144 -0
  57. package/dist/components/streaming-view.mjs.map +1 -0
  58. package/dist/config.cjs +280 -0
  59. package/dist/config.cjs.map +1 -0
  60. package/dist/config.d.cts +35 -0
  61. package/dist/config.d.cts.map +1 -0
  62. package/dist/config.d.mts +35 -0
  63. package/dist/config.d.mts.map +1 -0
  64. package/dist/config.mjs +266 -0
  65. package/dist/config.mjs.map +1 -0
  66. package/dist/contract.cjs +209 -0
  67. package/dist/contract.cjs.map +1 -0
  68. package/dist/contract.d.cts +490 -0
  69. package/dist/contract.d.cts.map +1 -0
  70. package/dist/contract.d.mts +490 -0
  71. package/dist/contract.d.mts.map +1 -0
  72. package/dist/contract.meta.cjs +104 -0
  73. package/dist/contract.meta.cjs.map +1 -0
  74. package/dist/contract.meta.d.cts +141 -0
  75. package/dist/contract.meta.d.cts.map +1 -0
  76. package/dist/contract.meta.d.mts +141 -0
  77. package/dist/contract.meta.d.mts.map +1 -0
  78. package/dist/contract.meta.mjs +102 -0
  79. package/dist/contract.meta.mjs.map +1 -0
  80. package/dist/contract.mjs +186 -0
  81. package/dist/contract.mjs.map +1 -0
  82. package/dist/dev-logs.cjs +53 -0
  83. package/dist/dev-logs.cjs.map +1 -0
  84. package/dist/dev-logs.mjs +51 -0
  85. package/dist/dev-logs.mjs.map +1 -0
  86. package/dist/dev-session.cjs +195 -0
  87. package/dist/dev-session.cjs.map +1 -0
  88. package/dist/dev-session.mjs +194 -0
  89. package/dist/dev-session.mjs.map +1 -0
  90. package/dist/fastkv.cjs +89 -0
  91. package/dist/fastkv.cjs.map +1 -0
  92. package/dist/fastkv.d.cts +11 -0
  93. package/dist/fastkv.d.cts.map +1 -0
  94. package/dist/fastkv.d.mts +11 -0
  95. package/dist/fastkv.d.mts.map +1 -0
  96. package/dist/fastkv.mjs +82 -0
  97. package/dist/fastkv.mjs.map +1 -0
  98. package/dist/federation.server.cjs +27 -0
  99. package/dist/federation.server.cjs.map +1 -0
  100. package/dist/federation.server.mjs +27 -0
  101. package/dist/federation.server.mjs.map +1 -0
  102. package/dist/host.cjs +367 -0
  103. package/dist/host.cjs.map +1 -0
  104. package/dist/host.d.cts +22 -0
  105. package/dist/host.d.cts.map +1 -0
  106. package/dist/host.d.mts +22 -0
  107. package/dist/host.d.mts.map +1 -0
  108. package/dist/host.mjs +364 -0
  109. package/dist/host.mjs.map +1 -0
  110. package/dist/index.cjs +122 -0
  111. package/dist/index.d.cts +7 -0
  112. package/dist/index.d.mts +7 -0
  113. package/dist/index.mjs +9 -0
  114. package/dist/integrity.cjs +39 -0
  115. package/dist/integrity.cjs.map +1 -0
  116. package/dist/integrity.d.cts +7 -0
  117. package/dist/integrity.d.cts.map +1 -0
  118. package/dist/integrity.d.mts +7 -0
  119. package/dist/integrity.d.mts.map +1 -0
  120. package/dist/integrity.mjs +35 -0
  121. package/dist/integrity.mjs.map +1 -0
  122. package/dist/mf.cjs +77 -0
  123. package/dist/mf.cjs.map +1 -0
  124. package/dist/mf.d.cts +19 -0
  125. package/dist/mf.d.cts.map +1 -0
  126. package/dist/mf.d.mts +19 -0
  127. package/dist/mf.d.mts.map +1 -0
  128. package/dist/mf.mjs +71 -0
  129. package/dist/mf.mjs.map +1 -0
  130. package/dist/near-cli.cjs +196 -0
  131. package/dist/near-cli.cjs.map +1 -0
  132. package/dist/near-cli.mjs +193 -0
  133. package/dist/near-cli.mjs.map +1 -0
  134. package/dist/network.cjs +9 -0
  135. package/dist/network.cjs.map +1 -0
  136. package/dist/network.mjs +8 -0
  137. package/dist/network.mjs.map +1 -0
  138. package/dist/orchestrator.cjs +441 -0
  139. package/dist/orchestrator.cjs.map +1 -0
  140. package/dist/orchestrator.d.cts +40 -0
  141. package/dist/orchestrator.d.cts.map +1 -0
  142. package/dist/orchestrator.d.mts +40 -0
  143. package/dist/orchestrator.d.mts.map +1 -0
  144. package/dist/orchestrator.mjs +436 -0
  145. package/dist/orchestrator.mjs.map +1 -0
  146. package/dist/plugin.cjs +825 -0
  147. package/dist/plugin.cjs.map +1 -0
  148. package/dist/plugin.d.cts +347 -0
  149. package/dist/plugin.d.cts.map +1 -0
  150. package/dist/plugin.d.mts +348 -0
  151. package/dist/plugin.d.mts.map +1 -0
  152. package/dist/plugin.mjs +822 -0
  153. package/dist/plugin.mjs.map +1 -0
  154. package/dist/process-registry.cjs +120 -0
  155. package/dist/process-registry.cjs.map +1 -0
  156. package/dist/process-registry.d.cts +25 -0
  157. package/dist/process-registry.d.cts.map +1 -0
  158. package/dist/process-registry.d.mts +25 -0
  159. package/dist/process-registry.d.mts.map +1 -0
  160. package/dist/process-registry.mjs +119 -0
  161. package/dist/process-registry.mjs.map +1 -0
  162. package/dist/sdk.cjs +61 -0
  163. package/dist/sdk.d.cts +5 -0
  164. package/dist/sdk.d.mts +5 -0
  165. package/dist/sdk.mjs +6 -0
  166. package/dist/shared.cjs +143 -0
  167. package/dist/shared.cjs.map +1 -0
  168. package/dist/shared.d.cts +33 -0
  169. package/dist/shared.d.cts.map +1 -0
  170. package/dist/shared.d.mts +33 -0
  171. package/dist/shared.d.mts.map +1 -0
  172. package/dist/shared.mjs +140 -0
  173. package/dist/shared.mjs.map +1 -0
  174. package/dist/types.cjs +160 -0
  175. package/dist/types.cjs.map +1 -0
  176. package/dist/types.d.cts +269 -0
  177. package/dist/types.d.cts.map +1 -0
  178. package/dist/types.d.mts +269 -0
  179. package/dist/types.d.mts.map +1 -0
  180. package/dist/types.mjs +144 -0
  181. package/dist/types.mjs.map +1 -0
  182. package/dist/ui/head.cjs +67 -0
  183. package/dist/ui/head.cjs.map +1 -0
  184. package/dist/ui/head.d.cts +19 -0
  185. package/dist/ui/head.d.cts.map +1 -0
  186. package/dist/ui/head.d.mts +19 -0
  187. package/dist/ui/head.d.mts.map +1 -0
  188. package/dist/ui/head.mjs +61 -0
  189. package/dist/ui/head.mjs.map +1 -0
  190. package/dist/ui/index.cjs +32 -0
  191. package/dist/ui/index.d.cts +7 -0
  192. package/dist/ui/index.d.mts +7 -0
  193. package/dist/ui/index.mjs +6 -0
  194. package/dist/ui/metadata.cjs +106 -0
  195. package/dist/ui/metadata.cjs.map +1 -0
  196. package/dist/ui/metadata.d.cts +35 -0
  197. package/dist/ui/metadata.d.cts.map +1 -0
  198. package/dist/ui/metadata.d.mts +35 -0
  199. package/dist/ui/metadata.d.mts.map +1 -0
  200. package/dist/ui/metadata.mjs +100 -0
  201. package/dist/ui/metadata.mjs.map +1 -0
  202. package/dist/ui/router.cjs +56 -0
  203. package/dist/ui/router.cjs.map +1 -0
  204. package/dist/ui/router.d.cts +11 -0
  205. package/dist/ui/router.d.cts.map +1 -0
  206. package/dist/ui/router.d.mts +11 -0
  207. package/dist/ui/router.d.mts.map +1 -0
  208. package/dist/ui/router.mjs +51 -0
  209. package/dist/ui/router.mjs.map +1 -0
  210. package/dist/ui/runtime.cjs +65 -0
  211. package/dist/ui/runtime.cjs.map +1 -0
  212. package/dist/ui/runtime.d.cts +29 -0
  213. package/dist/ui/runtime.d.cts.map +1 -0
  214. package/dist/ui/runtime.d.mts +29 -0
  215. package/dist/ui/runtime.d.mts.map +1 -0
  216. package/dist/ui/runtime.mjs +53 -0
  217. package/dist/ui/runtime.mjs.map +1 -0
  218. package/dist/ui/types.cjs +0 -0
  219. package/dist/ui/types.d.cts +52 -0
  220. package/dist/ui/types.d.cts.map +1 -0
  221. package/dist/ui/types.d.mts +52 -0
  222. package/dist/ui/types.d.mts.map +1 -0
  223. package/dist/ui/types.mjs +1 -0
  224. package/dist/utils/banner.cjs +24 -0
  225. package/dist/utils/banner.cjs.map +1 -0
  226. package/dist/utils/banner.mjs +23 -0
  227. package/dist/utils/banner.mjs.map +1 -0
  228. package/dist/utils/linkify.cjs +15 -0
  229. package/dist/utils/linkify.cjs.map +1 -0
  230. package/dist/utils/linkify.mjs +14 -0
  231. package/dist/utils/linkify.mjs.map +1 -0
  232. package/dist/utils/run.cjs +40 -0
  233. package/dist/utils/run.cjs.map +1 -0
  234. package/dist/utils/run.mjs +39 -0
  235. package/dist/utils/run.mjs.map +1 -0
  236. package/dist/utils/theme.cjs +44 -0
  237. package/dist/utils/theme.cjs.map +1 -0
  238. package/dist/utils/theme.mjs +37 -0
  239. package/dist/utils/theme.mjs.map +1 -0
  240. package/package.json +269 -80
  241. package/src/api-contract.ts +309 -0
  242. package/src/api.ts +181 -0
  243. package/src/app.ts +346 -0
  244. package/src/cli/catalog.ts +49 -0
  245. package/src/cli/help.ts +13 -0
  246. package/src/cli/init.ts +415 -0
  247. package/src/cli/parse.ts +130 -0
  248. package/src/cli/prompts.ts +64 -0
  249. package/src/cli.ts +203 -1507
  250. package/src/components/dev-view.tsx +104 -41
  251. package/src/components/streaming-view.ts +89 -22
  252. package/src/config.ts +462 -532
  253. package/src/contract.meta.ts +96 -0
  254. package/src/contract.ts +164 -561
  255. package/src/dev-logs.ts +85 -0
  256. package/src/dev-session.ts +318 -0
  257. package/src/fastkv.ts +153 -0
  258. package/src/federation.server.ts +43 -0
  259. package/src/host.ts +526 -0
  260. package/src/index.ts +6 -3
  261. package/src/integrity.ts +54 -0
  262. package/src/mf.ts +105 -0
  263. package/src/near-cli.ts +284 -0
  264. package/src/network.ts +3 -0
  265. package/src/orchestrator.ts +648 -0
  266. package/src/plugin.ts +1116 -2303
  267. package/src/process-registry.ts +154 -0
  268. package/src/scripts/sync-api-contract.ts +24 -0
  269. package/src/sdk.ts +14 -0
  270. package/src/shared.ts +206 -0
  271. package/src/types.ts +152 -206
  272. package/src/ui/head.ts +34 -27
  273. package/src/ui/index.ts +3 -3
  274. package/src/ui/metadata.ts +95 -0
  275. package/src/ui/router.ts +22 -6
  276. package/src/ui/runtime.ts +55 -6
  277. package/src/ui/types.ts +24 -11
  278. package/src/utils/banner.ts +10 -6
  279. package/src/utils/run.ts +26 -27
  280. package/src/utils/theme.ts +3 -66
  281. package/src/components/monitor-view.tsx +0 -475
  282. package/src/components/status-view.tsx +0 -173
  283. package/src/lib/env.ts +0 -109
  284. package/src/lib/near-cli.ts +0 -289
  285. package/src/lib/nova.ts +0 -266
  286. package/src/lib/orchestrator.ts +0 -276
  287. package/src/lib/process-registry.ts +0 -166
  288. package/src/lib/process.ts +0 -549
  289. package/src/lib/resource-monitor/assertions.ts +0 -234
  290. package/src/lib/resource-monitor/command.ts +0 -283
  291. package/src/lib/resource-monitor/diff.ts +0 -157
  292. package/src/lib/resource-monitor/errors.ts +0 -127
  293. package/src/lib/resource-monitor/index.ts +0 -305
  294. package/src/lib/resource-monitor/platform/darwin.ts +0 -306
  295. package/src/lib/resource-monitor/platform/index.ts +0 -35
  296. package/src/lib/resource-monitor/platform/linux.ts +0 -332
  297. package/src/lib/resource-monitor/platform/windows.ts +0 -298
  298. package/src/lib/resource-monitor/snapshot.ts +0 -217
  299. package/src/lib/resource-monitor/types.ts +0 -74
  300. package/src/lib/session-recorder/errors.ts +0 -102
  301. package/src/lib/session-recorder/flows/login.ts +0 -210
  302. package/src/lib/session-recorder/index.ts +0 -361
  303. package/src/lib/session-recorder/playwright.ts +0 -257
  304. package/src/lib/session-recorder/report.ts +0 -353
  305. package/src/lib/session-recorder/server.ts +0 -267
  306. package/src/lib/session-recorder/types.ts +0 -115
  307. package/src/lib/sync.ts +0 -1
  308. package/src/ui/files.ts +0 -134
package/src/lib/env.ts DELETED
@@ -1,109 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { readFile } from "node:fs/promises";
3
- import path from "node:path";
4
- import { Effect } from "every-plugin/effect";
5
- import { getProjectRoot } from "../config";
6
-
7
- export interface BosEnv {
8
- ZE_SERVER_TOKEN?: string;
9
- ZE_USER_EMAIL?: string;
10
- NEAR_PRIVATE_KEY?: string;
11
- GATEWAY_PRIVATE_KEY?: string;
12
- NOVA_SECRETS_CID?: string;
13
- }
14
-
15
- function parseEnvFile(content: string): Record<string, string> {
16
- const result: Record<string, string> = {};
17
- const lines = content.split("\n");
18
-
19
- for (const line of lines) {
20
- const trimmed = line.trim();
21
- if (!trimmed || trimmed.startsWith("#")) continue;
22
-
23
- const eqIndex = trimmed.indexOf("=");
24
- if (eqIndex === -1) continue;
25
-
26
- const key = trimmed.slice(0, eqIndex).trim();
27
- let value = trimmed.slice(eqIndex + 1).trim();
28
-
29
- if (
30
- (value.startsWith('"') && value.endsWith('"')) ||
31
- (value.startsWith("'") && value.endsWith("'"))
32
- ) {
33
- value = value.slice(1, -1);
34
- }
35
-
36
- result[key] = value;
37
- }
38
-
39
- return result;
40
- }
41
-
42
- export const loadBosEnv = Effect.gen(function* () {
43
- let configDir: string;
44
- try {
45
- configDir = getProjectRoot();
46
- } catch {
47
- configDir = process.cwd();
48
- }
49
- const envBosPath = path.join(configDir, ".env.bos");
50
- const envPath = path.join(configDir, ".env");
51
-
52
- let envVars: BosEnv = {};
53
-
54
- const envFilePath = existsSync(envBosPath)
55
- ? envBosPath
56
- : existsSync(envPath)
57
- ? envPath
58
- : null;
59
-
60
- if (envFilePath) {
61
- const content = yield* Effect.tryPromise({
62
- try: () => readFile(envFilePath, "utf-8"),
63
- catch: () => new Error(`Failed to read ${envFilePath}`),
64
- });
65
-
66
- const parsed = parseEnvFile(content);
67
- envVars = {
68
- ZE_SERVER_TOKEN: parsed.ZE_SERVER_TOKEN,
69
- ZE_USER_EMAIL: parsed.ZE_USER_EMAIL,
70
- NEAR_PRIVATE_KEY: parsed.NEAR_PRIVATE_KEY,
71
- GATEWAY_PRIVATE_KEY: parsed.GATEWAY_PRIVATE_KEY,
72
- NOVA_SECRETS_CID: parsed.NOVA_SECRETS_CID,
73
- };
74
- }
75
-
76
- envVars.ZE_SERVER_TOKEN =
77
- envVars.ZE_SERVER_TOKEN || process.env.ZE_SERVER_TOKEN;
78
- envVars.ZE_USER_EMAIL = envVars.ZE_USER_EMAIL || process.env.ZE_USER_EMAIL;
79
- envVars.NEAR_PRIVATE_KEY =
80
- envVars.NEAR_PRIVATE_KEY || process.env.NEAR_PRIVATE_KEY;
81
- envVars.GATEWAY_PRIVATE_KEY =
82
- envVars.GATEWAY_PRIVATE_KEY || process.env.GATEWAY_PRIVATE_KEY;
83
- envVars.NOVA_SECRETS_CID =
84
- envVars.NOVA_SECRETS_CID || process.env.NOVA_SECRETS_CID;
85
-
86
- return envVars;
87
- });
88
-
89
- export const ZEPHYR_DOCS_URL =
90
- "https://docs.zephyr-cloud.io/features/ci-cd-server-token";
91
-
92
- export const getBuildEnv = (bosEnv: BosEnv): Record<string, string> => {
93
- const env: Record<string, string> = {
94
- ...(process.env as Record<string, string>),
95
- };
96
-
97
- if (bosEnv.ZE_SERVER_TOKEN) {
98
- env.ZE_SERVER_TOKEN = bosEnv.ZE_SERVER_TOKEN;
99
- }
100
- if (bosEnv.ZE_USER_EMAIL) {
101
- env.ZE_USER_EMAIL = bosEnv.ZE_USER_EMAIL;
102
- }
103
-
104
- return env;
105
- };
106
-
107
- export const hasZephyrConfig = (bosEnv: BosEnv): boolean => {
108
- return !!(bosEnv.ZE_SERVER_TOKEN && bosEnv.ZE_USER_EMAIL);
109
- };
@@ -1,289 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { confirm } from "@inquirer/prompts";
3
- import { Effect } from "every-plugin/effect";
4
- import { colors, icons } from "../utils/theme";
5
-
6
- export interface TransactionConfig {
7
- account: string;
8
- contract: string;
9
- method: string;
10
- argsBase64: string;
11
- network?: "mainnet" | "testnet";
12
- privateKey?: string;
13
- gas?: string;
14
- deposit?: string;
15
- }
16
-
17
- export interface TransactionResult {
18
- success: boolean;
19
- txHash?: string;
20
- error?: string;
21
- }
22
-
23
- const NEAR_CLI_VERSION = "0.23.5";
24
- const INSTALLER_URL = `https://github.com/near/near-cli-rs/releases/download/v${NEAR_CLI_VERSION}/near-cli-rs-installer.sh`;
25
-
26
- export class NearCliNotFoundError extends Error {
27
- readonly _tag = "NearCliNotFoundError";
28
- constructor() {
29
- super("NEAR CLI not found");
30
- }
31
- }
32
-
33
- export class NearCliInstallError extends Error {
34
- readonly _tag = "NearCliInstallError";
35
- constructor(message: string) {
36
- super(`Failed to install NEAR CLI: ${message}`);
37
- }
38
- }
39
-
40
- export class TransactionError extends Error {
41
- readonly _tag = "TransactionError";
42
- constructor(message: string) {
43
- super(message);
44
- }
45
- }
46
-
47
- const checkNearCliInstalled = Effect.gen(function* () {
48
- const result = yield* Effect.tryPromise({
49
- try: async () => {
50
- return new Promise<boolean>((resolve) => {
51
- const proc = spawn("near", ["--version"], { shell: true, stdio: "pipe" });
52
- proc.on("close", (code) => resolve(code === 0));
53
- proc.on("error", () => resolve(false));
54
- });
55
- },
56
- catch: () => new Error("Failed to check NEAR CLI"),
57
- });
58
- return result;
59
- });
60
-
61
- const installNearCli = Effect.gen(function* () {
62
- console.log();
63
- console.log(` ${icons.pkg} Installing NEAR CLI v${NEAR_CLI_VERSION}...`);
64
- console.log(colors.dim(` Using official installer from GitHub`));
65
- console.log();
66
-
67
- yield* Effect.tryPromise({
68
- try: async () => {
69
- return new Promise<void>((resolve, reject) => {
70
- const proc = spawn("sh", ["-c", `curl --proto '=https' --tlsv1.2 -LsSf ${INSTALLER_URL} | sh`], {
71
- stdio: "inherit",
72
- shell: true,
73
- });
74
- proc.on("close", (code) => {
75
- if (code === 0) resolve();
76
- else reject(new NearCliInstallError(`Installer exited with code ${code}`));
77
- });
78
- proc.on("error", (err) => reject(new NearCliInstallError(err.message)));
79
- });
80
- },
81
- catch: (e) => e as Error,
82
- });
83
-
84
- console.log();
85
- console.log(colors.green(` ${icons.ok} NEAR CLI installed successfully`));
86
- });
87
-
88
- export const ensureNearCli = Effect.gen(function* () {
89
- const isInstalled = yield* checkNearCliInstalled;
90
-
91
- if (isInstalled) {
92
- return;
93
- }
94
-
95
- console.log();
96
- console.log(colors.error(` ${icons.err} NEAR CLI not found`));
97
-
98
- const shouldInstall = yield* Effect.tryPromise({
99
- try: () => confirm({
100
- message: "Install NEAR CLI? (required for publishing)",
101
- default: true,
102
- }),
103
- catch: () => new Error("Prompt cancelled"),
104
- });
105
-
106
- if (!shouldInstall) {
107
- console.log();
108
- console.log(colors.dim(" To install manually:"));
109
- console.log(colors.dim(` curl --proto '=https' --tlsv1.2 -LsSf ${INSTALLER_URL} | sh`));
110
- console.log();
111
- yield* Effect.fail(new NearCliNotFoundError());
112
- }
113
-
114
- yield* installNearCli;
115
- });
116
-
117
- export interface CreateSubaccountConfig {
118
- newAccount: string;
119
- parentAccount: string;
120
- initialBalance?: string;
121
- network: "mainnet" | "testnet";
122
- privateKey?: string;
123
- }
124
-
125
- export interface CreateSubaccountResult {
126
- success: boolean;
127
- account: string;
128
- error?: string;
129
- }
130
-
131
- export const createSubaccount = (config: CreateSubaccountConfig): Effect.Effect<CreateSubaccountResult, Error> =>
132
- Effect.gen(function* () {
133
- const balance = config.initialBalance || "0.1NEAR";
134
- const network = config.network;
135
-
136
- const args = [
137
- "account",
138
- "create-account",
139
- "fund-myself",
140
- config.newAccount,
141
- balance,
142
- "autogenerate-new-keypair",
143
- "save-to-keychain",
144
- "sign-as",
145
- config.parentAccount,
146
- "network-config",
147
- network,
148
- ];
149
-
150
- if (config.privateKey) {
151
- args.push("sign-with-plaintext-private-key", "--private-key", config.privateKey, "send");
152
- }
153
-
154
- console.log();
155
- console.log(` ${icons.run} Creating subaccount...`);
156
- console.log(colors.dim(` Account: ${config.newAccount}`));
157
- console.log(colors.dim(` Parent: ${config.parentAccount}`));
158
- console.log(colors.dim(` Balance: ${balance}`));
159
- console.log();
160
-
161
- const output = yield* Effect.tryPromise({
162
- try: async () => {
163
- return new Promise<string>((resolve, reject) => {
164
- const proc = spawn("near", args, {
165
- shell: true,
166
- stdio: ["inherit", "pipe", "pipe"],
167
- });
168
-
169
- let stdout = "";
170
- let stderr = "";
171
-
172
- proc.stdout?.on("data", (data) => {
173
- const text = data.toString();
174
- stdout += text;
175
- process.stdout.write(text);
176
- });
177
-
178
- proc.stderr?.on("data", (data) => {
179
- const text = data.toString();
180
- stderr += text;
181
- process.stderr.write(text);
182
- });
183
-
184
- proc.on("close", (code) => {
185
- if (code === 0) {
186
- resolve(stdout);
187
- } else {
188
- reject(new Error(stderr || `Subaccount creation failed with code ${code}`));
189
- }
190
- });
191
-
192
- proc.on("error", (err) => {
193
- reject(new Error(err.message));
194
- });
195
- });
196
- },
197
- catch: (e) => e as Error,
198
- });
199
-
200
- return {
201
- success: true,
202
- account: config.newAccount,
203
- };
204
- });
205
-
206
- export const executeTransaction = (config: TransactionConfig): Effect.Effect<TransactionResult, Error> =>
207
- Effect.gen(function* () {
208
- const gas = (config.gas || "300Tgas").replace(/\s+/g, "");
209
- const deposit = (config.deposit || "0NEAR").replace(/\s+/g, "");
210
- const network = config.network || (config.account.endsWith(".testnet") ? "testnet" : "mainnet");
211
-
212
- const args = [
213
- "contract",
214
- "call-function",
215
- "as-transaction",
216
- config.contract,
217
- config.method,
218
- "base64-args",
219
- config.argsBase64,
220
- "prepaid-gas",
221
- gas,
222
- "attached-deposit",
223
- deposit,
224
- "sign-as",
225
- config.account,
226
- "network-config",
227
- network,
228
- ];
229
-
230
- if (config.privateKey) {
231
- args.push("sign-with-plaintext-private-key", config.privateKey, "send");
232
- }
233
-
234
- console.log();
235
- console.log(` ${icons.run} Executing transaction...`);
236
- console.log(colors.dim(` Contract: ${config.contract}`));
237
- console.log(colors.dim(` Method: ${config.method}`));
238
- console.log(colors.dim(` Signer: ${config.account}`));
239
- console.log();
240
-
241
- const output = yield* Effect.tryPromise({
242
- try: async () => {
243
- return new Promise<string>((resolve, reject) => {
244
- const proc = spawn("near", args, {
245
- shell: true,
246
- stdio: ["inherit", "pipe", "pipe"],
247
- });
248
-
249
- let stdout = "";
250
- let stderr = "";
251
-
252
- proc.stdout?.on("data", (data) => {
253
- const text = data.toString();
254
- stdout += text;
255
- process.stdout.write(text);
256
- });
257
-
258
- proc.stderr?.on("data", (data) => {
259
- const text = data.toString();
260
- stderr += text;
261
- process.stderr.write(text);
262
- });
263
-
264
- proc.on("close", (code) => {
265
- if (code === 0) {
266
- resolve(stdout);
267
- } else {
268
- reject(new TransactionError(stderr || `Transaction failed with code ${code}`));
269
- }
270
- });
271
-
272
- proc.on("error", (err) => {
273
- reject(new TransactionError(err.message));
274
- });
275
- });
276
- },
277
- catch: (e) => e as Error,
278
- });
279
-
280
- const txHashMatch = output.match(/Transaction ID:\s*([A-Za-z0-9]+)/i) ||
281
- output.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/);
282
-
283
- const txHash = txHashMatch?.[1] || "unknown";
284
-
285
- return {
286
- success: true,
287
- txHash,
288
- };
289
- });
package/src/lib/nova.ts DELETED
@@ -1,266 +0,0 @@
1
- import { Effect } from "every-plugin/effect";
2
- import { NovaSdk } from "nova-sdk-js";
3
- import { getProjectRoot } from "../config";
4
-
5
- export interface NovaConfig {
6
- accountId: string;
7
- sessionToken: string;
8
- }
9
-
10
- export interface SecretsData {
11
- secrets: Record<string, string>;
12
- updatedAt: string;
13
- }
14
-
15
- export interface UploadResult {
16
- cid: string;
17
- groupId: string;
18
- txHash?: string;
19
- }
20
-
21
- export const getNovaConfig = Effect.gen(function* () {
22
- const accountId = process.env.NOVA_ACCOUNT_ID;
23
- const sessionToken = process.env.NOVA_API_KEY;
24
-
25
- if (!accountId || !sessionToken) {
26
- return yield* Effect.fail(
27
- new Error(
28
- "NOVA credentials not configured. Run 'bos login' to authenticate with NOVA.",
29
- ),
30
- );
31
- }
32
-
33
- return { accountId, sessionToken } satisfies NovaConfig;
34
- });
35
-
36
- export function createNovaClient(config: NovaConfig): NovaSdk {
37
- return new NovaSdk(config.accountId, {
38
- apiKey: config.sessionToken,
39
- });
40
- }
41
-
42
- export function getSecretsGroupId(nearAccount: string): string {
43
- return `${nearAccount}-secrets`;
44
- }
45
-
46
- export const registerSecretsGroup = (
47
- nova: NovaSdk,
48
- nearAccount: string,
49
- novaAccount: string,
50
- ) =>
51
- Effect.gen(function* () {
52
- const groupId = getSecretsGroupId(nearAccount);
53
-
54
- yield* Effect.tryPromise({
55
- try: () => nova.registerGroup(groupId),
56
- catch: (e) => new Error(`Failed to register NOVA group: ${e}`),
57
- });
58
-
59
- yield* Effect.tryPromise({
60
- try: () => nova.addGroupMember(groupId, novaAccount),
61
- catch: (e) =>
62
- new Error(`Failed to add gateway Nova account to group: ${e}`),
63
- });
64
-
65
- return groupId;
66
- });
67
-
68
- export const uploadSecrets = (
69
- nova: NovaSdk,
70
- groupId: string,
71
- secrets: Record<string, string>,
72
- ) =>
73
- Effect.gen(function* () {
74
- const secretsData: SecretsData = {
75
- secrets,
76
- updatedAt: new Date().toISOString(),
77
- };
78
-
79
- const buffer = Buffer.from(JSON.stringify(secretsData, null, 2));
80
-
81
- const result = yield* Effect.tryPromise({
82
- try: () => nova.upload(groupId, buffer, "secrets.json"),
83
- catch: (e) => new Error(`Failed to upload secrets to NOVA: ${e}`),
84
- });
85
-
86
- return {
87
- cid: result.cid,
88
- groupId,
89
- txHash: result.trans_id,
90
- } satisfies UploadResult;
91
- });
92
-
93
- export const retrieveSecrets = (nova: NovaSdk, groupId: string, cid: string) =>
94
- Effect.gen(function* () {
95
- const result = yield* Effect.tryPromise({
96
- try: () => nova.retrieve(groupId, cid),
97
- catch: (e) => new Error(`Failed to retrieve secrets from NOVA: ${e}`),
98
- });
99
-
100
- const secretsData = JSON.parse(result.data.toString()) as SecretsData;
101
- return secretsData;
102
- });
103
-
104
- export function parseEnvFile(content: string): Record<string, string> {
105
- const secrets: Record<string, string> = {};
106
- const lines = content.split("\n");
107
-
108
- for (const line of lines) {
109
- const trimmed = line.trim();
110
-
111
- if (!trimmed || trimmed.startsWith("#")) {
112
- continue;
113
- }
114
-
115
- const eqIndex = trimmed.indexOf("=");
116
- if (eqIndex === -1) {
117
- continue;
118
- }
119
-
120
- const key = trimmed.slice(0, eqIndex).trim();
121
- let value = trimmed.slice(eqIndex + 1).trim();
122
-
123
- if (
124
- (value.startsWith('"') && value.endsWith('"')) ||
125
- (value.startsWith("'") && value.endsWith("'"))
126
- ) {
127
- value = value.slice(1, -1);
128
- }
129
-
130
- if (key) {
131
- secrets[key] = value;
132
- }
133
- }
134
-
135
- return secrets;
136
- }
137
-
138
- export function filterSecretsToRequired(
139
- allSecrets: Record<string, string>,
140
- requiredKeys: string[],
141
- ): Record<string, string> {
142
- const filtered: Record<string, string> = {};
143
-
144
- for (const key of requiredKeys) {
145
- if (key in allSecrets) {
146
- filtered[key] = allSecrets[key];
147
- }
148
- }
149
-
150
- return filtered;
151
- }
152
-
153
- export function hasNovaCredentials(): boolean {
154
- return !!(process.env.NOVA_ACCOUNT_ID && process.env.NOVA_API_KEY);
155
- }
156
-
157
- function getBosEnvPath(): string {
158
- try {
159
- return `${getProjectRoot()}/.env.bos`;
160
- } catch {
161
- // Fallback to cwd if config not loaded
162
- return `${process.cwd()}/.env.bos`;
163
- }
164
- }
165
-
166
- export const saveNovaCredentials = (accountId: string, sessionToken: string) =>
167
- Effect.gen(function* () {
168
- const envPath = getBosEnvPath();
169
- let content = "";
170
-
171
- const file = Bun.file(envPath);
172
- const exists = yield* Effect.promise(() => file.exists());
173
-
174
- if (exists) {
175
- content = yield* Effect.tryPromise({
176
- try: () => file.text(),
177
- catch: () => new Error("File read failed"),
178
- }).pipe(Effect.orElseSucceed(() => ""));
179
- }
180
-
181
- const lines = content.split("\n");
182
- const newLines: string[] = [];
183
- let foundAccountId = false;
184
- let foundSessionToken = false;
185
-
186
- for (const line of lines) {
187
- const trimmed = line.trim();
188
- if (trimmed.startsWith("NOVA_ACCOUNT_ID=")) {
189
- newLines.push(`NOVA_ACCOUNT_ID=${accountId}`);
190
- foundAccountId = true;
191
- } else if (trimmed.startsWith("NOVA_API_KEY=")) {
192
- newLines.push(`NOVA_API_KEY=${sessionToken}`);
193
- foundSessionToken = true;
194
- } else {
195
- newLines.push(line);
196
- }
197
- }
198
-
199
- if (!foundAccountId) {
200
- if (newLines.length > 0 && newLines[newLines.length - 1] !== "") {
201
- newLines.push("");
202
- }
203
- newLines.push(`NOVA_ACCOUNT_ID=${accountId}`);
204
- }
205
-
206
- if (!foundSessionToken) {
207
- newLines.push(`NOVA_API_KEY=${sessionToken}`);
208
- }
209
-
210
- yield* Effect.tryPromise({
211
- try: () => Bun.write(envPath, newLines.join("\n")),
212
- catch: (e) => new Error(`Failed to save credentials: ${e}`),
213
- });
214
-
215
- process.env.NOVA_ACCOUNT_ID = accountId;
216
- process.env.NOVA_API_KEY = sessionToken;
217
- });
218
-
219
- export const removeNovaCredentials = Effect.gen(function* () {
220
- const envPath = getBosEnvPath();
221
- let content = "";
222
-
223
- try {
224
- content = yield* Effect.tryPromise({
225
- try: () => Bun.file(envPath).text(),
226
- catch: () => "",
227
- });
228
- } catch {
229
- return;
230
- }
231
-
232
- const lines = content.split("\n");
233
- const newLines = lines.filter((line) => {
234
- const trimmed = line.trim();
235
- return (
236
- !trimmed.startsWith("NOVA_ACCOUNT_ID=") &&
237
- !trimmed.startsWith("NOVA_API_KEY=")
238
- );
239
- });
240
-
241
- yield* Effect.tryPromise({
242
- try: () => Bun.write(envPath, newLines.join("\n")),
243
- catch: (e) => new Error(`Failed to remove credentials: ${e}`),
244
- });
245
-
246
- delete process.env.NOVA_ACCOUNT_ID;
247
- delete process.env.NOVA_API_KEY;
248
- });
249
-
250
- export const verifyNovaCredentials = (
251
- accountId: string,
252
- sessionToken: string,
253
- ) =>
254
- Effect.gen(function* () {
255
- const nova = new NovaSdk(accountId, { apiKey: sessionToken });
256
-
257
- yield* Effect.tryPromise({
258
- try: () => nova.getBalance(),
259
- catch: (e) => {
260
- const message = e instanceof Error ? e.message : String(e);
261
- return new Error(`NOVA verification failed: ${message}`);
262
- },
263
- });
264
-
265
- return true;
266
- });