bitbadges 0.35.6 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +98 -1
  2. package/dist/cjs/builder/agent/BitBadgesBuilderAgent.d.ts +1 -0
  3. package/dist/cjs/builder/agent/BitBadgesBuilderAgent.d.ts.map +1 -1
  4. package/dist/cjs/builder/agent/BitBadgesBuilderAgent.js +40 -3
  5. package/dist/cjs/builder/agent/BitBadgesBuilderAgent.js.map +1 -1
  6. package/dist/cjs/builder/agent/index.d.ts +1 -0
  7. package/dist/cjs/builder/agent/index.d.ts.map +1 -1
  8. package/dist/cjs/builder/agent/index.js +4 -1
  9. package/dist/cjs/builder/agent/index.js.map +1 -1
  10. package/dist/cjs/builder/agent/types.d.ts +2 -0
  11. package/dist/cjs/builder/agent/types.d.ts.map +1 -1
  12. package/dist/cjs/builder/tracing/inMemory.d.ts +32 -0
  13. package/dist/cjs/builder/tracing/inMemory.d.ts.map +1 -0
  14. package/dist/cjs/builder/tracing/inMemory.js +95 -0
  15. package/dist/cjs/builder/tracing/inMemory.js.map +1 -0
  16. package/dist/cjs/builder/tracing/index.d.ts +4 -0
  17. package/dist/cjs/builder/tracing/index.d.ts.map +1 -0
  18. package/dist/cjs/builder/tracing/index.js +8 -0
  19. package/dist/cjs/builder/tracing/index.js.map +1 -0
  20. package/dist/cjs/builder/tracing/noop.d.ts +9 -0
  21. package/dist/cjs/builder/tracing/noop.d.ts.map +1 -0
  22. package/dist/cjs/builder/tracing/noop.js +49 -0
  23. package/dist/cjs/builder/tracing/noop.js.map +1 -0
  24. package/dist/cjs/builder/tracing/tracing.spec.d.ts +2 -0
  25. package/dist/cjs/builder/tracing/tracing.spec.d.ts.map +1 -0
  26. package/dist/cjs/builder/tracing/tracing.spec.js +128 -0
  27. package/dist/cjs/builder/tracing/tracing.spec.js.map +1 -0
  28. package/dist/cjs/builder/tracing/types.d.ts +22 -0
  29. package/dist/cjs/builder/tracing/types.d.ts.map +1 -0
  30. package/dist/cjs/builder/tracing/types.js +3 -0
  31. package/dist/cjs/builder/tracing/types.js.map +1 -0
  32. package/dist/cjs/cli/commands/address.d.ts +3 -0
  33. package/dist/cjs/cli/commands/address.d.ts.map +1 -0
  34. package/dist/cjs/cli/commands/address.js +66 -0
  35. package/dist/cjs/cli/commands/address.js.map +1 -0
  36. package/dist/cjs/cli/commands/alias.d.ts +3 -0
  37. package/dist/cjs/cli/commands/alias.d.ts.map +1 -0
  38. package/dist/cjs/cli/commands/alias.js +62 -0
  39. package/dist/cjs/cli/commands/alias.js.map +1 -0
  40. package/dist/cjs/cli/commands/api.d.ts.map +1 -1
  41. package/dist/cjs/cli/commands/api.js +86 -2
  42. package/dist/cjs/cli/commands/api.js.map +1 -1
  43. package/dist/cjs/cli/commands/auth.d.ts +3 -0
  44. package/dist/cjs/cli/commands/auth.d.ts.map +1 -0
  45. package/dist/cjs/cli/commands/auth.js +354 -0
  46. package/dist/cjs/cli/commands/auth.js.map +1 -0
  47. package/dist/cjs/cli/commands/build.d.ts +3 -0
  48. package/dist/cjs/cli/commands/build.d.ts.map +1 -0
  49. package/dist/cjs/cli/commands/{templates.js → build.js} +27 -25
  50. package/dist/cjs/cli/commands/build.js.map +1 -0
  51. package/dist/cjs/cli/commands/burner.js +2 -2
  52. package/dist/cjs/cli/commands/burner.js.map +1 -1
  53. package/dist/cjs/cli/commands/check.d.ts +3 -0
  54. package/dist/cjs/cli/commands/check.d.ts.map +1 -0
  55. package/dist/cjs/cli/commands/check.js +251 -0
  56. package/dist/cjs/cli/commands/check.js.map +1 -0
  57. package/dist/cjs/cli/commands/completion.d.ts +3 -0
  58. package/dist/cjs/cli/commands/completion.d.ts.map +1 -0
  59. package/dist/cjs/cli/commands/completion.js +46 -0
  60. package/dist/cjs/cli/commands/completion.js.map +1 -0
  61. package/dist/cjs/cli/commands/deploy.d.ts +3 -0
  62. package/dist/cjs/cli/commands/deploy.d.ts.map +1 -0
  63. package/dist/cjs/cli/commands/{createWithBurner.js → deploy.js} +71 -16
  64. package/dist/cjs/cli/commands/deploy.js.map +1 -0
  65. package/dist/cjs/cli/commands/docs.d.ts +3 -0
  66. package/dist/cjs/cli/commands/docs.d.ts.map +1 -0
  67. package/dist/cjs/cli/commands/docs.js +173 -0
  68. package/dist/cjs/cli/commands/docs.js.map +1 -0
  69. package/dist/cjs/cli/commands/doctor.d.ts +3 -0
  70. package/dist/cjs/cli/commands/doctor.d.ts.map +1 -0
  71. package/dist/cjs/cli/commands/doctor.js +355 -0
  72. package/dist/cjs/cli/commands/doctor.js.map +1 -0
  73. package/dist/cjs/cli/commands/explain.d.ts +3 -0
  74. package/dist/cjs/cli/commands/explain.d.ts.map +1 -0
  75. package/dist/cjs/cli/commands/explain.js +142 -0
  76. package/dist/cjs/cli/commands/explain.js.map +1 -0
  77. package/dist/cjs/cli/commands/gen-list-id.d.ts +3 -0
  78. package/dist/cjs/cli/commands/gen-list-id.d.ts.map +1 -0
  79. package/dist/cjs/cli/commands/gen-list-id.js +54 -0
  80. package/dist/cjs/cli/commands/gen-list-id.js.map +1 -0
  81. package/dist/cjs/cli/commands/lookup.d.ts +3 -0
  82. package/dist/cjs/cli/commands/lookup.d.ts.map +1 -0
  83. package/dist/cjs/cli/commands/lookup.js +111 -0
  84. package/dist/cjs/cli/commands/lookup.js.map +1 -0
  85. package/dist/cjs/cli/commands/preview.d.ts +3 -0
  86. package/dist/cjs/cli/commands/preview.d.ts.map +1 -0
  87. package/dist/cjs/cli/commands/preview.js +112 -0
  88. package/dist/cjs/cli/commands/preview.js.map +1 -0
  89. package/dist/cjs/cli/commands/resources.d.ts +3 -0
  90. package/dist/cjs/cli/commands/resources.d.ts.map +1 -0
  91. package/dist/cjs/cli/commands/resources.js +31 -0
  92. package/dist/cjs/cli/commands/resources.js.map +1 -0
  93. package/dist/cjs/cli/commands/session.d.ts +3 -0
  94. package/dist/cjs/cli/commands/session.d.ts.map +1 -0
  95. package/dist/cjs/cli/commands/session.js +34 -0
  96. package/dist/cjs/cli/commands/session.js.map +1 -0
  97. package/dist/cjs/cli/commands/simulate.d.ts +3 -0
  98. package/dist/cjs/cli/commands/simulate.d.ts.map +1 -0
  99. package/dist/cjs/cli/commands/simulate.js +119 -0
  100. package/dist/cjs/cli/commands/simulate.js.map +1 -0
  101. package/dist/cjs/cli/commands/skills.d.ts +3 -0
  102. package/dist/cjs/cli/commands/skills.d.ts.map +1 -0
  103. package/dist/cjs/cli/commands/skills.js +14 -0
  104. package/dist/cjs/cli/commands/skills.js.map +1 -0
  105. package/dist/cjs/cli/commands/tool.d.ts +3 -0
  106. package/dist/cjs/cli/commands/tool.d.ts.map +1 -0
  107. package/dist/cjs/cli/commands/tool.js +92 -0
  108. package/dist/cjs/cli/commands/tool.js.map +1 -0
  109. package/dist/cjs/cli/commands/tools.d.ts +3 -0
  110. package/dist/cjs/cli/commands/tools.d.ts.map +1 -0
  111. package/dist/cjs/cli/commands/tools.js +18 -0
  112. package/dist/cjs/cli/commands/tools.js.map +1 -0
  113. package/dist/cjs/cli/commands/tx.d.ts +3 -0
  114. package/dist/cjs/cli/commands/tx.d.ts.map +1 -0
  115. package/dist/cjs/cli/commands/tx.js +255 -0
  116. package/dist/cjs/cli/commands/tx.js.map +1 -0
  117. package/dist/cjs/cli/index.js +123 -49
  118. package/dist/cjs/cli/index.js.map +1 -1
  119. package/dist/cjs/cli/utils/api-client.d.ts +6 -0
  120. package/dist/cjs/cli/utils/api-client.d.ts.map +1 -1
  121. package/dist/cjs/cli/utils/api-client.js +19 -1
  122. package/dist/cjs/cli/utils/api-client.js.map +1 -1
  123. package/dist/cjs/cli/utils/auth-store.d.ts +59 -0
  124. package/dist/cjs/cli/utils/auth-store.d.ts.map +1 -0
  125. package/dist/cjs/cli/utils/auth-store.js +249 -0
  126. package/dist/cjs/cli/utils/auth-store.js.map +1 -0
  127. package/dist/cjs/cli/utils/envelope.d.ts +42 -0
  128. package/dist/cjs/cli/utils/envelope.d.ts.map +1 -0
  129. package/dist/cjs/cli/utils/envelope.js +58 -0
  130. package/dist/cjs/cli/utils/envelope.js.map +1 -0
  131. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  132. package/dist/esm/builder/agent/BitBadgesBuilderAgent.d.ts +1 -0
  133. package/dist/esm/builder/agent/BitBadgesBuilderAgent.d.ts.map +1 -1
  134. package/dist/esm/builder/agent/BitBadgesBuilderAgent.js +41 -3
  135. package/dist/esm/builder/agent/BitBadgesBuilderAgent.js.map +1 -1
  136. package/dist/esm/builder/agent/index.d.ts +1 -0
  137. package/dist/esm/builder/agent/index.d.ts.map +1 -1
  138. package/dist/esm/builder/agent/index.js +1 -0
  139. package/dist/esm/builder/agent/index.js.map +1 -1
  140. package/dist/esm/builder/agent/types.d.ts +2 -0
  141. package/dist/esm/builder/agent/types.d.ts.map +1 -1
  142. package/dist/esm/builder/tracing/inMemory.d.ts +32 -0
  143. package/dist/esm/builder/tracing/inMemory.d.ts.map +1 -0
  144. package/dist/esm/builder/tracing/inMemory.js +97 -0
  145. package/dist/esm/builder/tracing/inMemory.js.map +1 -0
  146. package/dist/esm/builder/tracing/index.d.ts +4 -0
  147. package/dist/esm/builder/tracing/index.d.ts.map +1 -0
  148. package/dist/esm/builder/tracing/index.js +3 -0
  149. package/dist/esm/builder/tracing/index.js.map +1 -0
  150. package/dist/esm/builder/tracing/noop.d.ts +9 -0
  151. package/dist/esm/builder/tracing/noop.d.ts.map +1 -0
  152. package/dist/esm/builder/tracing/noop.js +49 -0
  153. package/dist/esm/builder/tracing/noop.js.map +1 -0
  154. package/dist/esm/builder/tracing/tracing.spec.d.ts +2 -0
  155. package/dist/esm/builder/tracing/tracing.spec.d.ts.map +1 -0
  156. package/dist/esm/builder/tracing/tracing.spec.js +126 -0
  157. package/dist/esm/builder/tracing/tracing.spec.js.map +1 -0
  158. package/dist/esm/builder/tracing/types.d.ts +22 -0
  159. package/dist/esm/builder/tracing/types.d.ts.map +1 -0
  160. package/dist/esm/builder/tracing/types.js +2 -0
  161. package/dist/esm/builder/tracing/types.js.map +1 -0
  162. package/dist/esm/cli/commands/address.d.ts +3 -0
  163. package/dist/esm/cli/commands/address.d.ts.map +1 -0
  164. package/dist/esm/cli/commands/address.js +30 -0
  165. package/dist/esm/cli/commands/address.js.map +1 -0
  166. package/dist/esm/cli/commands/alias.d.ts +3 -0
  167. package/dist/esm/cli/commands/alias.d.ts.map +1 -0
  168. package/dist/esm/cli/commands/alias.js +26 -0
  169. package/dist/esm/cli/commands/alias.js.map +1 -0
  170. package/dist/esm/cli/commands/api.d.ts.map +1 -1
  171. package/dist/esm/cli/commands/api.js +86 -2
  172. package/dist/esm/cli/commands/api.js.map +1 -1
  173. package/dist/esm/cli/commands/auth.d.ts +3 -0
  174. package/dist/esm/cli/commands/auth.d.ts.map +1 -0
  175. package/dist/esm/cli/commands/auth.js +318 -0
  176. package/dist/esm/cli/commands/auth.js.map +1 -0
  177. package/dist/esm/cli/commands/build.d.ts +3 -0
  178. package/dist/esm/cli/commands/build.d.ts.map +1 -0
  179. package/dist/esm/cli/commands/{templates.js → build.js} +26 -24
  180. package/dist/esm/cli/commands/build.js.map +1 -0
  181. package/dist/esm/cli/commands/burner.js +2 -2
  182. package/dist/esm/cli/commands/burner.js.map +1 -1
  183. package/dist/esm/cli/commands/check.d.ts +3 -0
  184. package/dist/esm/cli/commands/check.d.ts.map +1 -0
  185. package/dist/esm/cli/commands/check.js +215 -0
  186. package/dist/esm/cli/commands/check.js.map +1 -0
  187. package/dist/esm/cli/commands/completion.d.ts +3 -0
  188. package/dist/esm/cli/commands/completion.d.ts.map +1 -0
  189. package/dist/esm/cli/commands/completion.js +43 -0
  190. package/dist/esm/cli/commands/completion.js.map +1 -0
  191. package/dist/esm/cli/commands/deploy.d.ts +3 -0
  192. package/dist/esm/cli/commands/deploy.d.ts.map +1 -0
  193. package/dist/esm/cli/commands/{createWithBurner.js → deploy.js} +70 -15
  194. package/dist/esm/cli/commands/deploy.js.map +1 -0
  195. package/dist/esm/cli/commands/docs.d.ts +3 -0
  196. package/dist/esm/cli/commands/docs.d.ts.map +1 -0
  197. package/dist/esm/cli/commands/docs.js +137 -0
  198. package/dist/esm/cli/commands/docs.js.map +1 -0
  199. package/dist/esm/cli/commands/doctor.d.ts +3 -0
  200. package/dist/esm/cli/commands/doctor.d.ts.map +1 -0
  201. package/dist/esm/cli/commands/doctor.js +319 -0
  202. package/dist/esm/cli/commands/doctor.js.map +1 -0
  203. package/dist/esm/cli/commands/explain.d.ts +3 -0
  204. package/dist/esm/cli/commands/explain.d.ts.map +1 -0
  205. package/dist/esm/cli/commands/explain.js +106 -0
  206. package/dist/esm/cli/commands/explain.js.map +1 -0
  207. package/dist/esm/cli/commands/gen-list-id.d.ts +3 -0
  208. package/dist/esm/cli/commands/gen-list-id.d.ts.map +1 -0
  209. package/dist/esm/cli/commands/gen-list-id.js +18 -0
  210. package/dist/esm/cli/commands/gen-list-id.js.map +1 -0
  211. package/dist/esm/cli/commands/lookup.d.ts +3 -0
  212. package/dist/esm/cli/commands/lookup.d.ts.map +1 -0
  213. package/dist/esm/cli/commands/lookup.js +75 -0
  214. package/dist/esm/cli/commands/lookup.js.map +1 -0
  215. package/dist/esm/cli/commands/preview.d.ts +3 -0
  216. package/dist/esm/cli/commands/preview.d.ts.map +1 -0
  217. package/dist/esm/cli/commands/preview.js +76 -0
  218. package/dist/esm/cli/commands/preview.js.map +1 -0
  219. package/dist/esm/cli/commands/resources.d.ts +3 -0
  220. package/dist/esm/cli/commands/resources.d.ts.map +1 -0
  221. package/dist/esm/cli/commands/resources.js +28 -0
  222. package/dist/esm/cli/commands/resources.js.map +1 -0
  223. package/dist/esm/cli/commands/session.d.ts +3 -0
  224. package/dist/esm/cli/commands/session.d.ts.map +1 -0
  225. package/dist/esm/cli/commands/session.js +31 -0
  226. package/dist/esm/cli/commands/session.js.map +1 -0
  227. package/dist/esm/cli/commands/simulate.d.ts +3 -0
  228. package/dist/esm/cli/commands/simulate.d.ts.map +1 -0
  229. package/dist/esm/cli/commands/simulate.js +83 -0
  230. package/dist/esm/cli/commands/simulate.js.map +1 -0
  231. package/dist/esm/cli/commands/skills.d.ts +3 -0
  232. package/dist/esm/cli/commands/skills.d.ts.map +1 -0
  233. package/dist/esm/cli/commands/skills.js +11 -0
  234. package/dist/esm/cli/commands/skills.js.map +1 -0
  235. package/dist/esm/cli/commands/tool.d.ts +3 -0
  236. package/dist/esm/cli/commands/tool.d.ts.map +1 -0
  237. package/dist/esm/cli/commands/tool.js +86 -0
  238. package/dist/esm/cli/commands/tool.js.map +1 -0
  239. package/dist/esm/cli/commands/tools.d.ts +3 -0
  240. package/dist/esm/cli/commands/tools.d.ts.map +1 -0
  241. package/dist/esm/cli/commands/tools.js +15 -0
  242. package/dist/esm/cli/commands/tools.js.map +1 -0
  243. package/dist/esm/cli/commands/tx.d.ts +3 -0
  244. package/dist/esm/cli/commands/tx.d.ts.map +1 -0
  245. package/dist/esm/cli/commands/tx.js +252 -0
  246. package/dist/esm/cli/commands/tx.js.map +1 -0
  247. package/dist/esm/cli/index.js +123 -49
  248. package/dist/esm/cli/index.js.map +1 -1
  249. package/dist/esm/cli/utils/api-client.d.ts +6 -0
  250. package/dist/esm/cli/utils/api-client.d.ts.map +1 -1
  251. package/dist/esm/cli/utils/api-client.js +19 -1
  252. package/dist/esm/cli/utils/api-client.js.map +1 -1
  253. package/dist/esm/cli/utils/auth-store.d.ts +59 -0
  254. package/dist/esm/cli/utils/auth-store.d.ts.map +1 -0
  255. package/dist/esm/cli/utils/auth-store.js +195 -0
  256. package/dist/esm/cli/utils/auth-store.js.map +1 -0
  257. package/dist/esm/cli/utils/envelope.d.ts +42 -0
  258. package/dist/esm/cli/utils/envelope.d.ts.map +1 -0
  259. package/dist/esm/cli/utils/envelope.js +49 -0
  260. package/dist/esm/cli/utils/envelope.js.map +1 -0
  261. package/dist/esm/tsconfig-esm.build.tsbuildinfo +1 -1
  262. package/package.json +8 -1
  263. package/dist/cjs/cli/commands/builder.d.ts +0 -3
  264. package/dist/cjs/cli/commands/builder.d.ts.map +0 -1
  265. package/dist/cjs/cli/commands/builder.js +0 -975
  266. package/dist/cjs/cli/commands/builder.js.map +0 -1
  267. package/dist/cjs/cli/commands/createWithBurner.d.ts +0 -3
  268. package/dist/cjs/cli/commands/createWithBurner.d.ts.map +0 -1
  269. package/dist/cjs/cli/commands/createWithBurner.js.map +0 -1
  270. package/dist/cjs/cli/commands/sdk.d.ts +0 -3
  271. package/dist/cjs/cli/commands/sdk.d.ts.map +0 -1
  272. package/dist/cjs/cli/commands/sdk.js +0 -514
  273. package/dist/cjs/cli/commands/sdk.js.map +0 -1
  274. package/dist/cjs/cli/commands/templates.d.ts +0 -3
  275. package/dist/cjs/cli/commands/templates.d.ts.map +0 -1
  276. package/dist/cjs/cli/commands/templates.js.map +0 -1
  277. package/dist/esm/cli/commands/builder.d.ts +0 -3
  278. package/dist/esm/cli/commands/builder.d.ts.map +0 -1
  279. package/dist/esm/cli/commands/builder.js +0 -936
  280. package/dist/esm/cli/commands/builder.js.map +0 -1
  281. package/dist/esm/cli/commands/createWithBurner.d.ts +0 -3
  282. package/dist/esm/cli/commands/createWithBurner.d.ts.map +0 -1
  283. package/dist/esm/cli/commands/createWithBurner.js.map +0 -1
  284. package/dist/esm/cli/commands/sdk.d.ts +0 -3
  285. package/dist/esm/cli/commands/sdk.d.ts.map +0 -1
  286. package/dist/esm/cli/commands/sdk.js +0 -478
  287. package/dist/esm/cli/commands/sdk.js.map +0 -1
  288. package/dist/esm/cli/commands/templates.d.ts +0 -3
  289. package/dist/esm/cli/commands/templates.d.ts.map +0 -1
  290. package/dist/esm/cli/commands/templates.js.map +0 -1
@@ -1,975 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.builderCommand = void 0;
40
- const commander_1 = require("commander");
41
- const fs_1 = __importDefault(require("fs"));
42
- const registry_js_1 = require("../../builder/tools/registry.js");
43
- const fileStore_js_1 = require("../../builder/session/fileStore.js");
44
- const templates_js_1 = require("./templates.js");
45
- const createWithBurner_js_1 = require("./createWithBurner.js");
46
- const burner_js_1 = require("./burner.js");
47
- const io_js_1 = require("../utils/io.js");
48
- function ensureTxWrapper(input) {
49
- if (!input || typeof input !== 'object')
50
- return input;
51
- if (Array.isArray(input.messages))
52
- return input;
53
- if (typeof input.typeUrl === 'string' && input.value)
54
- return { messages: [input] };
55
- return input;
56
- }
57
- function parseArgs(argsJson, argsFile) {
58
- if (argsJson && argsFile) {
59
- throw new Error('Pass either --args or --args-file, not both');
60
- }
61
- if (argsFile) {
62
- const raw = fs_1.default.readFileSync(argsFile, 'utf-8');
63
- return JSON.parse(raw);
64
- }
65
- if (argsJson) {
66
- try {
67
- return JSON.parse(argsJson);
68
- }
69
- catch (err) {
70
- throw new Error(`--args is not valid JSON: ${err.message}`);
71
- }
72
- }
73
- return {};
74
- }
75
- function resolveSessionId(parsedArgs, sessionFlag) {
76
- if (sessionFlag)
77
- return sessionFlag;
78
- if (parsedArgs && typeof parsedArgs.sessionId === 'string')
79
- return parsedArgs.sessionId;
80
- return undefined;
81
- }
82
- exports.builderCommand = new commander_1.Command('builder')
83
- .description('BitBadges Builder — deterministic templates, fine-grained tools, docs resources, and session state for composing token transactions.')
84
- .showHelpAfterError('(see `bitbadges-cli builder --help` for the full subcommand list)');
85
- exports.builderCommand.addCommand(templates_js_1.templatesCommand);
86
- exports.builderCommand.addCommand(createWithBurner_js_1.createWithBurnerCommand);
87
- exports.builderCommand.addCommand(burner_js_1.burnerCommand);
88
- const toolsCommand = exports.builderCommand
89
- .command('tools')
90
- .description('Fine-grained builder tool registry (session builders, queries, reviews, utilities).');
91
- toolsCommand
92
- .command('list')
93
- .description('List every builder tool with its schema as JSON.')
94
- .option('--names', 'Print only tool names, one per line')
95
- .action((opts) => {
96
- if (opts.names) {
97
- for (const name of Object.keys(registry_js_1.toolRegistry)) {
98
- process.stdout.write(`${name}\n`);
99
- }
100
- return;
101
- }
102
- process.stdout.write(JSON.stringify((0, registry_js_1.listTools)(), null, 2) + '\n');
103
- });
104
- toolsCommand
105
- .command('call <tool>')
106
- .description('Call a builder tool by name. Args come from --args (JSON) or --args-file.')
107
- .option('--args <json>', 'Tool arguments as a JSON string')
108
- .option('--args-file <path>', 'Tool arguments read from a JSON file')
109
- .option('--session <id>', 'Session id for stateful tools. Stored under ~/.bitbadges/sessions/<id>.json. Defaults to the id inside --args.sessionId, or the builtin default session.')
110
- .option('--raw', 'Print the structured result instead of the formatted text block')
111
- .action(async (toolName, opts) => {
112
- if (!registry_js_1.toolRegistry[toolName]) {
113
- const available = Object.keys(registry_js_1.toolRegistry).sort().join(', ');
114
- process.stderr.write(`Unknown tool: ${toolName}\nAvailable tools: ${available}\n`);
115
- process.exitCode = 1;
116
- return;
117
- }
118
- let parsedArgs;
119
- try {
120
- parsedArgs = parseArgs(opts.args, opts.argsFile);
121
- }
122
- catch (err) {
123
- process.stderr.write(`${err.message}\n`);
124
- process.exitCode = 1;
125
- return;
126
- }
127
- const sessionId = resolveSessionId(parsedArgs, opts.session);
128
- if (sessionId) {
129
- try {
130
- (0, fileStore_js_1.loadSessionFromDisk)(sessionId);
131
- }
132
- catch (err) {
133
- process.stderr.write(`${err.message}\n`);
134
- process.exitCode = 1;
135
- return;
136
- }
137
- if (parsedArgs && typeof parsedArgs === 'object' && parsedArgs.sessionId === undefined) {
138
- parsedArgs.sessionId = sessionId;
139
- }
140
- }
141
- const result = await (0, registry_js_1.callTool)(toolName, parsedArgs);
142
- if (sessionId) {
143
- try {
144
- (0, fileStore_js_1.saveSessionToDisk)(sessionId);
145
- }
146
- catch (err) {
147
- process.stderr.write(`Warning: failed to save session "${sessionId}": ${err.message}\n`);
148
- }
149
- }
150
- if (opts.raw) {
151
- process.stdout.write(JSON.stringify(result.result, null, 2) + '\n');
152
- }
153
- else {
154
- process.stdout.write(result.text + '\n');
155
- }
156
- if (result.isError) {
157
- process.exitCode = 1;
158
- }
159
- });
160
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
161
- .command('review <input>')
162
- .description('Review a built transaction or collection for issues. Input: JSON file, inline JSON, numeric collection ID, or - for stdin.')
163
- .option('--json', 'Output the full ReviewResult as JSON')
164
- .option('--strict', 'Exit 1 on warnings (critical always exits 2)')
165
- .option('--output-file <path>', 'Write output to file instead of stdout'))
166
- .action(async (input, opts) => {
167
- const { readJsonInput, output, getApiUrl, getApiKeyForNetwork } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
168
- let data;
169
- if (/^\d+$/.test(input)) {
170
- const baseUrl = getApiUrl(opts);
171
- const apiKey = getApiKeyForNetwork(opts) || '';
172
- try {
173
- const response = await fetch(`${baseUrl}/api/v0/collection/${input}`, {
174
- headers: { 'x-api-key': apiKey }
175
- });
176
- if (!response.ok) {
177
- process.stderr.write(`Could not fetch collection ${input} from ${baseUrl} — HTTP ${response.status}.\n` +
178
- `Hint: --network local may not have a wired collection-by-id endpoint.\n` +
179
- `Try passing the collection JSON directly instead of a numeric id.\n`);
180
- process.exit(2);
181
- }
182
- data = await response.json();
183
- }
184
- catch (err) {
185
- process.stderr.write(`Could not reach ${baseUrl}/api/v0/collection/${input}: ${err?.message || err}\n`);
186
- process.exit(2);
187
- }
188
- }
189
- else {
190
- try {
191
- data = readJsonInput(input);
192
- }
193
- catch (err) {
194
- process.stderr.write(`Failed to parse input JSON: ${err?.message || err}\n` +
195
- `Accepts: file path, @file.json, inline JSON, numeric collection id, or - for stdin.\n`);
196
- process.exit(2);
197
- }
198
- }
199
- const { reviewCollection } = await Promise.resolve().then(() => __importStar(require('../../core/review.js')));
200
- let result;
201
- try {
202
- result = reviewCollection(ensureTxWrapper(data));
203
- }
204
- catch (err) {
205
- process.stderr.write(`Could not review input: ${err?.message || err}\n` +
206
- `\`builder review\` expects a transaction (with messages[]), a single Msg ({typeUrl,value}), ` +
207
- `or a complete on-chain collection document.\n`);
208
- process.exit(2);
209
- }
210
- if (opts.json) {
211
- output(result, { ...opts, human: false });
212
- }
213
- else {
214
- const { renderReview } = await Promise.resolve().then(() => __importStar(require('../utils/terminal.js')));
215
- const text = renderReview(result, { stream: process.stdout });
216
- if (opts.outputFile) {
217
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
218
- const plain = text.replace(/\x1b\[[0-9;]*m/g, '');
219
- fsMod.writeFileSync(opts.outputFile, plain + '\n', 'utf-8');
220
- process.stderr.write(`Written to ${opts.outputFile}\n`);
221
- }
222
- else {
223
- console.log(text);
224
- }
225
- }
226
- if (result.summary.critical > 0)
227
- process.exit(2);
228
- if (opts.strict && result.summary.warning > 0)
229
- process.exit(1);
230
- });
231
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
232
- .command('verify <input>')
233
- .description('Aggregate validate + review + metadata coverage check. Input: JSON file, inline JSON, or - for stdin.')
234
- .option('--json', 'Output a structured aggregate JSON instead of rendered sections')
235
- .option('--strict', 'Exit 1 on warnings (criticals always exit 2)')
236
- .option('--no-validate', 'Skip the structural validation section')
237
- .option('--no-review', 'Skip the design review section')
238
- .option('--no-metadata', 'Skip the metadata coverage section')
239
- .option('--design', 'Include the design decisions (informational ✓/✗) section. Hidden by default while the surface is being iterated on; the underlying decisions still appear in --json output.')
240
- .option('--output-file <path>', 'Write the rendered sections to a file instead of stdout'))
241
- .action(async (input, opts) => {
242
- const { readJsonInput, output } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
243
- const { renderValidate, renderReview, renderDesignDecisions, renderMetadataPlaceholders, collectMetadataPlaceholders } = await Promise.resolve().then(() => __importStar(require('../utils/terminal.js')));
244
- let raw;
245
- try {
246
- raw = readJsonInput(input);
247
- }
248
- catch (err) {
249
- process.stderr.write(`Failed to parse input JSON: ${err?.message || err}\n` +
250
- `Accepts: file path, @file.json, inline JSON, or - for stdin.\n`);
251
- process.exit(2);
252
- }
253
- const wrapped = ensureTxWrapper(raw);
254
- const { isCollectionMsg } = await Promise.resolve().then(() => __importStar(require('../utils/normalizeMsg.js')));
255
- const firstMsg = Array.isArray(wrapped?.messages) && wrapped.messages.length > 0
256
- ? wrapped.messages.find((m) => isCollectionMsg(m)) ?? wrapped.messages[0]
257
- : wrapped;
258
- const firstIsCollection = isCollectionMsg(firstMsg);
259
- let validation = null;
260
- if (opts.validate !== false) {
261
- const { validateTransaction } = await Promise.resolve().then(() => __importStar(require('../../core/validate.js')));
262
- validation = validateTransaction(wrapped);
263
- }
264
- let review = null;
265
- if (opts.review !== false && firstIsCollection) {
266
- const { reviewCollection } = await Promise.resolve().then(() => __importStar(require('../../core/review.js')));
267
- review = reviewCollection(wrapped);
268
- }
269
- let design = null;
270
- if (firstIsCollection) {
271
- const { runDesignChecks } = await Promise.resolve().then(() => __importStar(require('../../core/design-decisions/index.js')));
272
- design = runDesignChecks(wrapped);
273
- }
274
- let placeholders = [];
275
- if (opts.metadata !== false && firstIsCollection) {
276
- placeholders = collectMetadataPlaceholders(firstMsg);
277
- }
278
- if (opts.json) {
279
- output({
280
- validate: validation,
281
- review,
282
- design,
283
- metadata: {
284
- placeholders,
285
- filled: firstMsg?.value?._meta?.metadataPlaceholders || {}
286
- }
287
- }, { ...opts, human: false });
288
- }
289
- else {
290
- const lines = [];
291
- if (validation) {
292
- lines.push(renderValidate(validation, { stream: process.stdout }));
293
- lines.push('');
294
- }
295
- if (review) {
296
- lines.push(renderReview(review, { stream: process.stdout }));
297
- lines.push('');
298
- }
299
- if (design && opts.design === true) {
300
- lines.push(renderDesignDecisions(design, { stream: process.stdout }));
301
- lines.push('');
302
- }
303
- if (placeholders.length > 0) {
304
- lines.push(renderMetadataPlaceholders(placeholders, firstMsg?.value?._meta?.metadataPlaceholders, {
305
- stream: process.stdout
306
- }));
307
- }
308
- const text = lines.join('\n');
309
- if (opts.outputFile) {
310
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
311
- const plain = text.replace(/\x1b\[[0-9;]*m/g, '');
312
- fsMod.writeFileSync(opts.outputFile, plain + '\n', 'utf-8');
313
- process.stderr.write(`Written to ${opts.outputFile}\n`);
314
- }
315
- else {
316
- console.log(text);
317
- }
318
- }
319
- const hasValidationErrors = validation && validation.issues?.some((i) => i.severity === 'error');
320
- const hasCritical = review && review.summary?.critical > 0;
321
- if (hasValidationErrors || hasCritical) {
322
- process.exit(2);
323
- }
324
- const hasValidationWarnings = validation && validation.issues?.some((i) => i.severity === 'warning');
325
- const hasReviewWarnings = review && review.summary?.warning > 0;
326
- if (opts.strict && (hasValidationWarnings || hasReviewWarnings)) {
327
- process.exit(1);
328
- }
329
- });
330
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
331
- .command('doctor')
332
- .description('Environment + session health check. Verifies Node/SDK/config/API key/MCP bin/session integrity. Pass --with-preview to also probe the indexer\'s shareable-preview upload + fetch roundtrip.')
333
- .option('--json', 'Output the full DoctorReport as JSON')
334
- .option('--with-preview', 'Add a preview-roundtrip probe: builds a minimal tx, POSTs it to /api/v0/builder/preview, GETs it back by code, and asserts the round trip is byte-equivalent. Catches indexer / Redis / preview-route regressions.')).action(async (opts) => {
335
- const checks = [];
336
- const nodeVersion = process.versions.node;
337
- const nodeMajor = parseInt(nodeVersion.split('.')[0], 10);
338
- if (nodeMajor >= 18) {
339
- checks.push({ name: 'Node version', status: 'pass', detail: `v${nodeVersion}` });
340
- }
341
- else {
342
- checks.push({
343
- name: 'Node version',
344
- status: 'fail',
345
- detail: `v${nodeVersion} — bitbadges requires Node 18+`
346
- });
347
- }
348
- const sdkPackageNames = ['bitbadges', 'bitbadgesjs-sdk'];
349
- try {
350
- const pathMod = await Promise.resolve().then(() => __importStar(require('path')));
351
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
352
- const startFrom = pathMod.dirname(process.argv[1] || process.cwd());
353
- let dir = startFrom;
354
- let pkgPath = null;
355
- for (let i = 0; i < 8; i++) {
356
- const candidate = pathMod.join(dir, 'package.json');
357
- if (fsMod.existsSync(candidate)) {
358
- try {
359
- const pkg = JSON.parse(fsMod.readFileSync(candidate, 'utf-8'));
360
- if (sdkPackageNames.includes(pkg.name)) {
361
- pkgPath = candidate;
362
- break;
363
- }
364
- }
365
- catch {
366
- }
367
- }
368
- const parent = pathMod.dirname(dir);
369
- if (parent === dir)
370
- break;
371
- dir = parent;
372
- }
373
- if (pkgPath) {
374
- const pkg = JSON.parse(fsMod.readFileSync(pkgPath, 'utf-8'));
375
- checks.push({ name: 'SDK package', status: 'pass', detail: `${pkg.name}@${pkg.version}` });
376
- }
377
- else {
378
- checks.push({
379
- name: 'SDK package',
380
- status: 'warn',
381
- detail: 'Could not locate bitbadges package.json from CLI entry'
382
- });
383
- }
384
- }
385
- catch (err) {
386
- checks.push({ name: 'SDK package', status: 'warn', detail: err.message });
387
- }
388
- try {
389
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
390
- const pathMod = await Promise.resolve().then(() => __importStar(require('path')));
391
- const osMod = await Promise.resolve().then(() => __importStar(require('os')));
392
- const configPath = pathMod.join(osMod.homedir(), '.bitbadges', 'config.json');
393
- if (fsMod.existsSync(configPath)) {
394
- try {
395
- JSON.parse(fsMod.readFileSync(configPath, 'utf-8'));
396
- checks.push({ name: 'Config file', status: 'pass', detail: configPath });
397
- }
398
- catch {
399
- checks.push({ name: 'Config file', status: 'fail', detail: `${configPath} exists but is not valid JSON` });
400
- }
401
- }
402
- else {
403
- checks.push({ name: 'Config file', status: 'skip', detail: 'no ~/.bitbadges/config.json (env vars also OK)' });
404
- }
405
- }
406
- catch (err) {
407
- checks.push({ name: 'Config file', status: 'fail', detail: err.message });
408
- }
409
- try {
410
- const { getApiUrl, getApiKeyForNetwork, resolveNetwork } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
411
- const key = getApiKeyForNetwork(opts);
412
- const network = resolveNetwork(opts);
413
- if (!key) {
414
- checks.push({
415
- name: `API key (${network})`,
416
- status: 'skip',
417
- detail: `no key set (BITBADGES_API_KEY or config.apiKey${network !== 'mainnet' ? `/apiKey${network[0].toUpperCase() + network.slice(1)}` : ''})`
418
- });
419
- }
420
- else {
421
- const url = `${getApiUrl(opts)}/api/v0/simulate`;
422
- try {
423
- const response = await fetch(url, {
424
- method: 'POST',
425
- headers: { 'Content-Type': 'application/json', 'x-api-key': key },
426
- body: JSON.stringify({ txs: [] })
427
- });
428
- if (response.status >= 200 && response.status < 500) {
429
- checks.push({
430
- name: `API key (${network})`,
431
- status: 'pass',
432
- detail: `${url} responded with HTTP ${response.status}`
433
- });
434
- }
435
- else {
436
- checks.push({ name: `API key (${network})`, status: 'warn', detail: `HTTP ${response.status} from ${url}` });
437
- }
438
- }
439
- catch (err) {
440
- checks.push({
441
- name: `API key (${network})`,
442
- status: 'warn',
443
- detail: `network error pinging ${url}: ${err.message}`
444
- });
445
- }
446
- }
447
- }
448
- catch (err) {
449
- checks.push({ name: 'API key', status: 'fail', detail: err.message });
450
- }
451
- try {
452
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
453
- const pathMod = await Promise.resolve().then(() => __importStar(require('path')));
454
- const startFrom = pathMod.dirname(process.argv[1] || process.cwd());
455
- let dir = startFrom;
456
- let pkgRoot = null;
457
- for (let i = 0; i < 8; i++) {
458
- const candidate = pathMod.join(dir, 'package.json');
459
- if (fsMod.existsSync(candidate)) {
460
- try {
461
- const pkg = JSON.parse(fsMod.readFileSync(candidate, 'utf-8'));
462
- if (sdkPackageNames.includes(pkg.name)) {
463
- pkgRoot = dir;
464
- break;
465
- }
466
- }
467
- catch {
468
- }
469
- }
470
- const parent = pathMod.dirname(dir);
471
- if (parent === dir)
472
- break;
473
- dir = parent;
474
- }
475
- if (!pkgRoot) {
476
- checks.push({
477
- name: 'MCP stdio bin',
478
- status: 'warn',
479
- detail: 'Could not locate SDK root from CLI entry'
480
- });
481
- }
482
- else {
483
- const binCandidates = [
484
- pathMod.join(pkgRoot, 'dist', 'cjs', 'builder', 'index.js'),
485
- pathMod.join(pkgRoot, 'dist', 'esm', 'builder', 'index.js')
486
- ];
487
- const found = binCandidates.find((p) => fsMod.existsSync(p));
488
- if (found) {
489
- checks.push({ name: 'MCP stdio bin', status: 'pass', detail: found });
490
- }
491
- else {
492
- checks.push({
493
- name: 'MCP stdio bin',
494
- status: 'warn',
495
- detail: 'dist/cjs/builder/index.js not found — run `npm run build` in the bitbadges package'
496
- });
497
- }
498
- }
499
- }
500
- catch (err) {
501
- checks.push({ name: 'MCP stdio bin', status: 'fail', detail: err.message });
502
- }
503
- try {
504
- const { listSessionFilesOnDisk, readSessionFileRaw } = await Promise.resolve().then(() => __importStar(require('../../builder/session/fileStore.js')));
505
- const ids = listSessionFilesOnDisk();
506
- let parseable = 0;
507
- let corrupt = 0;
508
- for (const id of ids) {
509
- const raw = readSessionFileRaw(id);
510
- if (!raw)
511
- continue;
512
- try {
513
- JSON.parse(raw);
514
- parseable++;
515
- }
516
- catch {
517
- corrupt++;
518
- }
519
- }
520
- if (corrupt > 0) {
521
- checks.push({
522
- name: 'Sessions',
523
- status: 'warn',
524
- detail: `${parseable} parseable, ${corrupt} corrupt — run \`bitbadges-cli builder session reset <id>\` on broken ones`
525
- });
526
- }
527
- else {
528
- checks.push({ name: 'Sessions', status: 'pass', detail: `${parseable} session(s) on disk` });
529
- }
530
- }
531
- catch (err) {
532
- checks.push({ name: 'Sessions', status: 'fail', detail: err.message });
533
- }
534
- if (opts.withPreview) {
535
- try {
536
- const { getApiUrl: gAU, resolveNetwork: rN } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
537
- const network = rN(opts);
538
- const baseUrl = gAU(opts);
539
- const probeTx = {
540
- transaction: {
541
- messages: [
542
- {
543
- typeUrl: '/tokenization.MsgCreateCollection',
544
- value: {
545
- creator: 'bb1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpdguex7',
546
- validTokenIds: [],
547
- standards: [],
548
- collectionApprovals: [],
549
- tokenMetadata: [],
550
- aliasPathsToAdd: [],
551
- cosmosCoinWrapperPathsToAdd: [],
552
- mintEscrowCoinsToTransfer: [],
553
- _meta: {
554
- metadataPlaceholders: {
555
- 'ipfs://METADATA_DOCTOR_PROBE': { name: 'doctor probe', description: '', image: '' }
556
- }
557
- }
558
- }
559
- }
560
- ]
561
- }
562
- };
563
- const postRes = await fetch(`${baseUrl}/api/v0/builder/preview`, {
564
- method: 'POST',
565
- headers: { 'Content-Type': 'application/json' },
566
- body: JSON.stringify(probeTx)
567
- });
568
- if (!postRes.ok) {
569
- checks.push({
570
- name: `Preview roundtrip (${network})`,
571
- status: 'fail',
572
- detail: `POST /api/v0/builder/preview returned HTTP ${postRes.status}`
573
- });
574
- }
575
- else {
576
- const { code } = (await postRes.json());
577
- const getRes = await fetch(`${baseUrl}/api/v0/builder/preview?code=${encodeURIComponent(code)}`);
578
- if (!getRes.ok) {
579
- checks.push({
580
- name: `Preview roundtrip (${network})`,
581
- status: 'fail',
582
- detail: `GET /api/v0/builder/preview returned HTTP ${getRes.status} for the code we just uploaded (${code})`
583
- });
584
- }
585
- else {
586
- const fetched = (await getRes.json());
587
- const echoedTypeUrl = fetched?.transaction?.messages?.[0]?.typeUrl;
588
- const sidecarKey = fetched?.transaction?.messages?.[0]?.value?._meta?.metadataPlaceholders?.['ipfs://METADATA_DOCTOR_PROBE']?.name;
589
- if (echoedTypeUrl !== '/tokenization.MsgCreateCollection' || sidecarKey !== 'doctor probe') {
590
- checks.push({
591
- name: `Preview roundtrip (${network})`,
592
- status: 'fail',
593
- detail: `Round trip mutated the payload — got typeUrl=${echoedTypeUrl}, sidecarName=${sidecarKey}`
594
- });
595
- }
596
- else {
597
- checks.push({
598
- name: `Preview roundtrip (${network})`,
599
- status: 'pass',
600
- detail: `${baseUrl}/api/v0/builder/preview · uploaded ${code} · fetched and verified`
601
- });
602
- }
603
- }
604
- }
605
- }
606
- catch (err) {
607
- checks.push({
608
- name: 'Preview roundtrip',
609
- status: 'fail',
610
- detail: `network error: ${err?.message || err}`
611
- });
612
- }
613
- }
614
- if (opts.json) {
615
- const { output: outputFn } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
616
- outputFn(checks, { ...opts, human: false });
617
- }
618
- else {
619
- const { makeColor, rule } = await Promise.resolve().then(() => __importStar(require('../utils/terminal.js')));
620
- const { c } = makeColor(process.stdout);
621
- const width = Math.min(80, process.stdout.columns || 80);
622
- const lines = [];
623
- lines.push(c('gray', rule('━', width, 'Doctor')));
624
- lines.push('');
625
- const sigil = { pass: '✓', fail: '■', warn: '▲', skip: '·' };
626
- const colorFor = { pass: 'green', fail: 'red', warn: 'yellow', skip: 'gray' };
627
- const labelFor = { pass: 'PASS', fail: 'FAIL', warn: 'WARN', skip: 'SKIP' };
628
- for (const ch of checks) {
629
- const badge = `${sigil[ch.status]} ${labelFor[ch.status]}`;
630
- lines.push(` ${c(colorFor[ch.status], c('bold', badge))} ${c('bold', ch.name)}`);
631
- if (ch.detail) {
632
- lines.push(` ${c('dim', ch.detail)}`);
633
- }
634
- }
635
- lines.push('');
636
- const counts = checks.reduce((acc, ch) => ({ ...acc, [ch.status]: (acc[ch.status] || 0) + 1 }), {});
637
- lines.push(c('gray', rule('━', width)));
638
- lines.push(` ${c('bold', 'Summary')} ${counts.pass || 0} pass · ${counts.fail
639
- ? c('red', `${counts.fail} fail`)
640
- : c('gray', '0 fail')} · ${counts.warn ? c('yellow', `${counts.warn} warn`) : c('gray', '0 warn')} · ${counts.skip || 0} skip`);
641
- lines.push(c('gray', rule('━', width)));
642
- console.log(lines.join('\n'));
643
- }
644
- if (checks.some((ch) => ch.status === 'fail'))
645
- process.exit(2);
646
- });
647
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
648
- .command('preview <input>')
649
- .description('Upload a tx to the indexer and print a shareable bitbadges.io preview URL. Input: JSON file, inline JSON, or - for stdin.')
650
- .option('--frontend-url <url>', 'Override the bitbadges.io frontend base for the printed preview URL', 'https://bitbadges.io')
651
- .option('--json', 'Output the structured upload result as JSON instead of just the URL')).action(async (input, opts) => {
652
- const { readJsonInput, getApiUrl } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
653
- const raw = readJsonInput(input);
654
- const wrapped = ensureTxWrapper(raw);
655
- const { normalizeToCreateOrUpdate: _normalize } = await Promise.resolve().then(() => __importStar(require('../utils/normalizeMsg.js')));
656
- const cleanedMessages = (wrapped.messages || []).map((m) => _normalize(m));
657
- const payload = {
658
- transaction: {
659
- messages: cleanedMessages,
660
- ...(wrapped.memo ? { memo: wrapped.memo } : {}),
661
- ...(wrapped.fee ? { fee: wrapped.fee } : {})
662
- }
663
- };
664
- const apiUrl = getApiUrl(opts);
665
- const url = `${apiUrl}/api/v0/builder/preview`;
666
- let response;
667
- try {
668
- response = await fetch(url, {
669
- method: 'POST',
670
- headers: { 'Content-Type': 'application/json' },
671
- body: JSON.stringify(payload)
672
- });
673
- }
674
- catch (err) {
675
- process.stderr.write(`Preview upload failed: ${err instanceof Error ? err.message : String(err)}\n`);
676
- process.exit(2);
677
- }
678
- if (!response.ok) {
679
- const text = await response.text().catch(() => '');
680
- process.stderr.write(`Preview upload failed: HTTP ${response.status} ${text}\n`);
681
- process.exit(2);
682
- }
683
- const result = (await response.json());
684
- const frontendBase = opts.frontendUrl || 'https://bitbadges.io';
685
- const previewUrl = `${frontendBase.replace(/\/$/, '')}/builder/preview?code=${encodeURIComponent(result.code)}`;
686
- if (opts.json) {
687
- process.stdout.write(JSON.stringify({
688
- code: result.code,
689
- url: previewUrl,
690
- expiresAt: result.expiresAt,
691
- expiresIn: result.expiresIn
692
- }, null, 2) + '\n');
693
- }
694
- else {
695
- process.stdout.write(previewUrl + '\n');
696
- process.stderr.write(`Expires in ${result.expiresIn}.\n`);
697
- }
698
- });
699
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
700
- .command('simulate <input>')
701
- .description('Dry-run a built tx against the BitBadges API simulate endpoint. Returns gas + per-address net balance changes. Input: JSON file, inline JSON, or - for stdin.')
702
- .option('--json', 'Output the structured SimulateResult as JSON instead of a rendered section')
703
- .option('--creator <address>', 'Override the simulation context address (default: bb1simulation)')
704
- .option('--events', 'Dump the full raw chain events array in the rendered output (default: just the count)')).action(async (input, opts) => {
705
- const { readJsonInput, output, getApiUrl, getApiKeyForNetwork } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
706
- const { simulateMessages } = await Promise.resolve().then(() => __importStar(require('../../builder/tools/queries/simulateTransaction.js')));
707
- const { renderSimulate } = await Promise.resolve().then(() => __importStar(require('../utils/terminal.js')));
708
- const { prefetchSimulateCollections } = await Promise.resolve().then(() => __importStar(require('../utils/simulateSymbols.js')));
709
- const apiKey = getApiKeyForNetwork(opts);
710
- if (!apiKey) {
711
- process.stderr.write(renderSimulate({
712
- success: false,
713
- error: 'No API key. Set BITBADGES_API_KEY, run `bitbadges-cli config set apiKey <key>`, or pass --network local against a key-less local indexer.'
714
- }, { stream: process.stderr }) + '\n');
715
- process.exit(2);
716
- }
717
- const raw = readJsonInput(input);
718
- const wrapped = ensureTxWrapper(raw);
719
- const messages = Array.isArray(wrapped?.messages) ? wrapped.messages : [];
720
- if (messages.length === 0) {
721
- process.stderr.write(renderSimulate({ success: false, error: 'No messages found in input. Expected `{messages: [...]}` or a single Msg.' }, { stream: process.stderr }) + '\n');
722
- process.exit(2);
723
- }
724
- const APPROVAL_RE = /\.(MsgUpdateUserApprovals|MsgSetIncomingApproval|MsgSetOutgoingApproval|MsgDeleteIncomingApproval|MsgDeleteOutgoingApproval|MsgPurgeApprovals)$/;
725
- const firstApprovalMsg = messages.find((m) => typeof m?.typeUrl === 'string' && APPROVAL_RE.test(m.typeUrl));
726
- if (firstApprovalMsg) {
727
- process.stderr.write(renderSimulate({
728
- success: false,
729
- error: `Cannot simulate user-level approval message (${firstApprovalMsg.typeUrl}). ` +
730
- 'Use `builder validate` and `builder review` to check it, or include it inside an ' +
731
- 'alternative approval message that wraps a full collection transaction.'
732
- }, { stream: process.stderr }) + '\n');
733
- process.exit(2);
734
- }
735
- const result = await simulateMessages({
736
- messages,
737
- memo: wrapped.memo,
738
- fee: wrapped.fee,
739
- creatorAddress: opts.creator,
740
- apiKey,
741
- apiUrl: getApiUrl(opts)
742
- });
743
- if (opts.json) {
744
- output(result, { ...opts, human: false });
745
- }
746
- else {
747
- const collectionCache = await prefetchSimulateCollections(result, {
748
- apiKey,
749
- apiUrl: getApiUrl(opts)
750
- });
751
- console.log(renderSimulate(result, {
752
- stream: process.stdout,
753
- events: opts.events ? 'full' : 'count',
754
- collectionCache
755
- }));
756
- }
757
- if (!result.success || result.valid === false)
758
- process.exit(2);
759
- });
760
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
761
- .command('explain <input>')
762
- .description('Explain a transaction or collection in plain English. Input: JSON file, inline JSON, numeric collection ID, or - for stdin.')
763
- .option('--output-file <path>', 'Write output to file instead of stdout')).action(async (input, opts) => {
764
- const { readJsonInput, getApiUrl, getApiKeyForNetwork } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
765
- let data;
766
- let fetchedCollection = false;
767
- if (/^\d+$/.test(input)) {
768
- const baseUrl = getApiUrl(opts);
769
- const apiKey = getApiKeyForNetwork(opts) || '';
770
- try {
771
- const response = await fetch(`${baseUrl}/api/v0/collection/${input}`, {
772
- headers: { 'x-api-key': apiKey }
773
- });
774
- if (!response.ok) {
775
- process.stderr.write(`Could not fetch collection ${input} from ${baseUrl} — HTTP ${response.status}.\n` +
776
- `Hint: the indexer's collection-by-id endpoint may not be wired on --network local.\n` +
777
- `Try passing the collection JSON directly (file or inline) instead of a numeric id.\n`);
778
- process.exit(2);
779
- }
780
- data = await response.json();
781
- fetchedCollection = true;
782
- }
783
- catch (err) {
784
- process.stderr.write(`Could not reach ${baseUrl}/api/v0/collection/${input}: ${err?.message || err}.\n` +
785
- `Check that the network is reachable, or pass the collection JSON directly.\n`);
786
- process.exit(2);
787
- }
788
- }
789
- else {
790
- try {
791
- data = readJsonInput(input);
792
- }
793
- catch (err) {
794
- process.stderr.write(`Failed to parse input JSON: ${err?.message || err}.\n` +
795
- `Accepts: file path, @file.json, inline JSON, numeric collection id, or - for stdin.\n`);
796
- process.exit(2);
797
- }
798
- }
799
- let text;
800
- const { isCollectionMsg } = await Promise.resolve().then(() => __importStar(require('../utils/normalizeMsg.js')));
801
- const hasMessages = Array.isArray(data?.messages);
802
- const firstCollectionMsg = hasMessages ? data.messages.find((m) => isCollectionMsg(m)) : null;
803
- try {
804
- if (fetchedCollection ||
805
- (data && typeof data === 'object' && !data.typeUrl && !hasMessages && !data.value)) {
806
- const { interpretCollection } = await Promise.resolve().then(() => __importStar(require('../../api-indexer/interpret.js')));
807
- text = interpretCollection(data);
808
- }
809
- else {
810
- const txBody = firstCollectionMsg?.value ?? data.value ?? data;
811
- const { interpretTransaction } = await Promise.resolve().then(() => __importStar(require('../../core/interpret-transaction.js')));
812
- text = interpretTransaction(txBody);
813
- }
814
- }
815
- catch (err) {
816
- process.stderr.write(`Could not interpret input: ${err?.message || err}.\n` +
817
- `Hint: \`builder explain\` expects either a full transaction (with messages[]),\n` +
818
- `a single Msg ({typeUrl, value}), a complete on-chain collection document\n` +
819
- `(returned by query_collection), or a numeric collection id. Minimal ad-hoc\n` +
820
- `JSON like {collectionId:"1"} is not a valid input — it lacks the fields the\n` +
821
- `interpreter needs (collectionMetadata.uri, validTokenIds, etc).\n`);
822
- process.exit(2);
823
- }
824
- if (opts.outputFile) {
825
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
826
- fsMod.writeFileSync(opts.outputFile, text + '\n', 'utf-8');
827
- process.stderr.write(`Written to ${opts.outputFile}\n`);
828
- }
829
- else {
830
- console.log(text);
831
- }
832
- });
833
- (0, io_js_1.addNetworkOptions)(exports.builderCommand
834
- .command('validate <input>')
835
- .description('Run static validation over a transaction JSON (structure, uint ranges, approval criteria, …). Offline — no API calls. Input: JSON file, inline JSON, or - for stdin. Exits 1 on validation failure, 2 on parse failure.'))
836
- .option('--json', 'Output the full ValidationResult as JSON')
837
- .option('--output-file <path>', 'Write output to file instead of stdout')
838
- .action(async (input, opts) => {
839
- const { readJsonInput, output } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
840
- let data;
841
- try {
842
- data = ensureTxWrapper(readJsonInput(input));
843
- }
844
- catch (err) {
845
- const friendly = err?.message || String(err);
846
- if (opts.json) {
847
- const { output: outFn } = await Promise.resolve().then(() => __importStar(require('../utils/io.js')));
848
- outFn({ valid: false, issues: [{ severity: 'error', path: '(input)', message: friendly }] }, { ...opts, human: false });
849
- }
850
- else {
851
- process.stderr.write(`✗ Could not parse input: ${friendly}\n`);
852
- }
853
- process.exit(2);
854
- }
855
- if (Array.isArray(data?.messages) && data.messages.length === 0) {
856
- const result = {
857
- valid: true,
858
- issues: [
859
- {
860
- severity: 'warning',
861
- path: 'messages',
862
- message: 'Transaction has an empty messages array. Did you forget to add any messages?'
863
- }
864
- ]
865
- };
866
- if (opts.json) {
867
- output(result, { ...opts, human: false });
868
- }
869
- else {
870
- process.stderr.write('▲ WARNING messages: Transaction has an empty messages array.\n');
871
- }
872
- process.exitCode = 1;
873
- return;
874
- }
875
- const { validateTransaction } = await Promise.resolve().then(() => __importStar(require('../../core/validate.js')));
876
- const result = validateTransaction(data);
877
- if (opts.json) {
878
- output(result, { ...opts, human: false });
879
- }
880
- else {
881
- const { makeColor, rule } = await Promise.resolve().then(() => __importStar(require('../utils/terminal.js')));
882
- const { c } = makeColor(process.stdout);
883
- const width = Math.min(80, process.stdout.columns || 80);
884
- const lines = [];
885
- lines.push(c('gray', rule('━', width, 'Validate')));
886
- if (result.issues.length === 0) {
887
- lines.push('');
888
- lines.push(` ${c('green', '✓')} ${c('bold', 'Clean')} — no structural issues`);
889
- lines.push('');
890
- }
891
- else {
892
- lines.push('');
893
- for (const issue of result.issues) {
894
- const levelColor = issue.severity === 'error' ? 'red' : 'yellow';
895
- const badge = issue.severity === 'error' ? '■ ERROR ' : '▲ WARNING';
896
- lines.push(` ${c(levelColor, c('bold', badge))} ${c('dim', issue.path || '(root)')}`);
897
- lines.push(` ${issue.message}`);
898
- lines.push('');
899
- }
900
- }
901
- lines.push(c('gray', rule('━', width)));
902
- const errCount = result.issues.filter((i) => i.severity === 'error').length;
903
- const warnCount = result.issues.filter((i) => i.severity === 'warning').length;
904
- lines.push(` ${c('bold', 'Summary')} ${errCount > 0 ? c('red', `${errCount} error`) : c('gray', `${errCount} error`)} · ${warnCount > 0 ? c('yellow', `${warnCount} warning`) : c('gray', `${warnCount} warning`)}`);
905
- lines.push(c('gray', rule('━', width)));
906
- const text = lines.join('\n');
907
- if (opts.outputFile) {
908
- const fsMod = await Promise.resolve().then(() => __importStar(require('fs')));
909
- const plain = text.replace(/\x1b\[[0-9;]*m/g, '');
910
- fsMod.writeFileSync(opts.outputFile, plain + '\n', 'utf-8');
911
- process.stderr.write(`Written to ${opts.outputFile}\n`);
912
- }
913
- else {
914
- console.log(text);
915
- }
916
- }
917
- if (!result.valid)
918
- process.exitCode = 1;
919
- });
920
- const sessionCommand = exports.builderCommand
921
- .command('session')
922
- .description('Inspect, dump, or reset persisted builder sessions.');
923
- sessionCommand
924
- .command('list')
925
- .description('List persisted session ids under ~/.bitbadges/sessions/.')
926
- .action(() => {
927
- for (const id of (0, fileStore_js_1.listSessionFilesOnDisk)()) {
928
- process.stdout.write(id + '\n');
929
- }
930
- });
931
- sessionCommand
932
- .command('show <id>')
933
- .description('Print a session snapshot as JSON.')
934
- .action((id) => {
935
- const raw = (0, fileStore_js_1.readSessionFileRaw)(id);
936
- if (raw === null) {
937
- process.stderr.write(`No session file at ${(0, fileStore_js_1.sessionFilePath)(id)}\n`);
938
- process.exitCode = 1;
939
- return;
940
- }
941
- process.stdout.write(raw);
942
- });
943
- sessionCommand
944
- .command('reset <id>')
945
- .description('Delete a persisted session file.')
946
- .action((id) => {
947
- (0, fileStore_js_1.resetSessionFile)(id);
948
- });
949
- const resourcesCommand = exports.builderCommand
950
- .command('resources')
951
- .description('Read static builder resources (token registry, recipes, skills, docs, error patterns, ...).');
952
- resourcesCommand
953
- .command('list')
954
- .description('List every resource with its metadata as JSON.')
955
- .option('--uris', 'Print only resource URIs, one per line')
956
- .action((opts) => {
957
- if (opts.uris) {
958
- for (const uri of Object.keys(registry_js_1.resourceRegistry)) {
959
- process.stdout.write(`${uri}\n`);
960
- }
961
- return;
962
- }
963
- process.stdout.write(JSON.stringify((0, registry_js_1.listResources)(), null, 2) + '\n');
964
- });
965
- resourcesCommand
966
- .command('read <uri>')
967
- .description('Read a resource body by URI (e.g. bitbadges://recipes/all).')
968
- .action((uri) => {
969
- const result = (0, registry_js_1.readResource)(uri);
970
- process.stdout.write(result.text + '\n');
971
- if (result.isError) {
972
- process.exitCode = 1;
973
- }
974
- });
975
- //# sourceMappingURL=builder.js.map