@private.me/xbind 1.3.5 → 3.0.0

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 (306) hide show
  1. package/LICENSES.md +212 -0
  2. package/README.md +388 -6
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -496
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -317
  7. package/dist-standalone/_deps/shared/errors.js +1 -255
  8. package/dist-standalone/_deps/shared/index.js +1 -74
  9. package/dist-standalone/_deps/shared/types.js +1 -90
  10. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  20. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  21. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  28. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  29. package/dist-standalone/_deps/xchange/errors.js +1 -1
  30. package/dist-standalone/_deps/xchange/index.js +1 -1
  31. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  32. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  33. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  34. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  40. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  41. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  42. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  43. package/dist-standalone/_deps/xregistry/index.js +1 -1
  44. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  45. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  46. package/dist-standalone/_deps/xregistry/types.js +1 -1
  47. package/dist-standalone/agent-call.js +1 -642
  48. package/dist-standalone/agent-sdk.js +1 -328
  49. package/dist-standalone/agent.d.ts +95 -5
  50. package/dist-standalone/agent.js +1 -1545
  51. package/dist-standalone/approval.js +1 -193
  52. package/dist-standalone/async-iterators.d.ts +275 -0
  53. package/dist-standalone/async-iterators.js +1 -0
  54. package/dist-standalone/auth.js +1 -219
  55. package/dist-standalone/auto-accept.js +1 -229
  56. package/dist-standalone/backup-config.js +1 -201
  57. package/dist-standalone/backup.d.ts +114 -0
  58. package/dist-standalone/backup.js +1 -0
  59. package/dist-standalone/batch-operations.d.ts +297 -0
  60. package/dist-standalone/batch-operations.js +1 -0
  61. package/dist-standalone/cancellation.d.ts +301 -0
  62. package/dist-standalone/cancellation.js +1 -0
  63. package/dist-standalone/checkpoint.js +1 -186
  64. package/dist-standalone/circuit-breaker.d.ts +351 -0
  65. package/dist-standalone/circuit-breaker.js +1 -0
  66. package/dist-standalone/cjs/agent-call.js +1 -651
  67. package/dist-standalone/cjs/agent-sdk.js +1 -332
  68. package/dist-standalone/cjs/agent.js +1 -1582
  69. package/dist-standalone/cjs/approval.js +1 -199
  70. package/dist-standalone/cjs/async-iterators.js +1 -0
  71. package/dist-standalone/cjs/auth.js +1 -225
  72. package/dist-standalone/cjs/auto-accept.js +1 -233
  73. package/dist-standalone/cjs/backup-config.js +1 -207
  74. package/dist-standalone/cjs/backup.js +1 -0
  75. package/dist-standalone/cjs/batch-operations.js +1 -0
  76. package/dist-standalone/cjs/cancellation.js +1 -0
  77. package/dist-standalone/cjs/checkpoint.js +1 -193
  78. package/dist-standalone/cjs/circuit-breaker.js +1 -0
  79. package/dist-standalone/cjs/cli/init.js +1 -486
  80. package/dist-standalone/cjs/config-validation.js +1 -0
  81. package/dist-standalone/cjs/connect.js +1 -312
  82. package/dist-standalone/cjs/connection-pool.js +1 -0
  83. package/dist-standalone/cjs/correlation-id.js +1 -339
  84. package/dist-standalone/cjs/crypto-utils.js +1 -0
  85. package/dist-standalone/cjs/debug-mode.js +1 -0
  86. package/dist-standalone/cjs/did-document.js +1 -101
  87. package/dist-standalone/cjs/did-privateme.js +1 -130
  88. package/dist-standalone/cjs/did-web.js +1 -201
  89. package/dist-standalone/cjs/discovery.js +1 -462
  90. package/dist-standalone/cjs/dual-mode.js +1 -251
  91. package/dist-standalone/cjs/email-templates.js +1 -313
  92. package/dist-standalone/cjs/email-transport.js +1 -239
  93. package/dist-standalone/cjs/envelope.js +1 -510
  94. package/dist-standalone/cjs/errors.js +1 -826
  95. package/dist-standalone/cjs/event-emitter.js +1 -0
  96. package/dist-standalone/cjs/gateway-state.js +1 -55
  97. package/dist-standalone/cjs/gateway-transport.js +1 -120
  98. package/dist-standalone/cjs/graceful-degradation.js +1 -0
  99. package/dist-standalone/cjs/guardrails.js +1 -223
  100. package/dist-standalone/cjs/health-check.js +1 -0
  101. package/dist-standalone/cjs/http-compat.js +1 -272
  102. package/dist-standalone/cjs/http-status-map.js +1 -571
  103. package/dist-standalone/cjs/identity.js +1 -540
  104. package/dist-standalone/cjs/index.js +1 -237
  105. package/dist-standalone/cjs/invitation.js +1 -421
  106. package/dist-standalone/cjs/invite.js +1 -328
  107. package/dist-standalone/cjs/key-agreement.js +1 -246
  108. package/dist-standalone/cjs/lazy-init.js +1 -300
  109. package/dist-standalone/cjs/logger.js +1 -0
  110. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  111. package/dist-standalone/cjs/nonce-store.js +1 -66
  112. package/dist-standalone/cjs/pairing-manager.js +1 -223
  113. package/dist-standalone/cjs/plugin-system.js +1 -0
  114. package/dist-standalone/cjs/plugins/logging.js +1 -0
  115. package/dist-standalone/cjs/plugins/metrics.js +1 -0
  116. package/dist-standalone/cjs/plugins/validation.js +1 -0
  117. package/dist-standalone/cjs/policy.js +1 -320
  118. package/dist-standalone/cjs/progress-callbacks.js +1 -0
  119. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  120. package/dist-standalone/cjs/registry-middleware.js +1 -50
  121. package/dist-standalone/cjs/retry-strategies.js +1 -0
  122. package/dist-standalone/cjs/retry-transport.js +1 -102
  123. package/dist-standalone/cjs/runtime/browser.js +1 -0
  124. package/dist-standalone/cjs/runtime/edge.js +1 -0
  125. package/dist-standalone/cjs/runtime/react-native.js +1 -0
  126. package/dist-standalone/cjs/security-policy.js +1 -245
  127. package/dist-standalone/cjs/serialization.js +1 -0
  128. package/dist-standalone/cjs/split-channel.js +1 -177
  129. package/dist-standalone/cjs/subscription-proof.js +1 -230
  130. package/dist-standalone/cjs/succession.js +1 -148
  131. package/dist-standalone/cjs/timeouts.js +1 -0
  132. package/dist-standalone/cjs/trace-context.js +1 -0
  133. package/dist-standalone/cjs/trace-spans.js +1 -0
  134. package/dist-standalone/cjs/transport.js +1 -63
  135. package/dist-standalone/cjs/trust-registry.js +1 -742
  136. package/dist-standalone/cjs/types/error-response.js +1 -56
  137. package/dist-standalone/cjs/vault-auth.js +1 -0
  138. package/dist-standalone/cjs/vault-store-loader.js +1 -0
  139. package/dist-standalone/cjs/verify.js +1 -25
  140. package/dist-standalone/cjs/version-info.js +1 -0
  141. package/dist-standalone/cjs/xfetch.js +1 -252
  142. package/dist-standalone/cli/init.js +1 -449
  143. package/dist-standalone/cli/setup.js +1 -514
  144. package/dist-standalone/cli/types.js +1 -27
  145. package/dist-standalone/cli/xbind.js +1 -148
  146. package/dist-standalone/config-validation.d.ts +185 -0
  147. package/dist-standalone/config-validation.js +1 -0
  148. package/dist-standalone/connect.js +1 -274
  149. package/dist-standalone/connection-pool.d.ts +251 -0
  150. package/dist-standalone/connection-pool.js +1 -0
  151. package/dist-standalone/correlation-id.js +1 -326
  152. package/dist-standalone/crypto-utils.d.ts +60 -0
  153. package/dist-standalone/crypto-utils.js +1 -0
  154. package/dist-standalone/debug-mode.d.ts +286 -0
  155. package/dist-standalone/debug-mode.js +1 -0
  156. package/dist-standalone/did-document.js +1 -96
  157. package/dist-standalone/did-privateme.js +1 -121
  158. package/dist-standalone/did-web.js +1 -196
  159. package/dist-standalone/discovery.js +1 -458
  160. package/dist-standalone/dual-mode.js +1 -247
  161. package/dist-standalone/email-templates.js +1 -309
  162. package/dist-standalone/email-transport.js +1 -232
  163. package/dist-standalone/envelope.d.ts +29 -1
  164. package/dist-standalone/envelope.js +1 -497
  165. package/dist-standalone/errors.d.ts +10 -0
  166. package/dist-standalone/errors.js +1 -811
  167. package/dist-standalone/event-emitter.d.ts +395 -0
  168. package/dist-standalone/event-emitter.js +1 -0
  169. package/dist-standalone/gateway-state.js +1 -51
  170. package/dist-standalone/gateway-transport.js +1 -116
  171. package/dist-standalone/graceful-degradation.d.ts +246 -0
  172. package/dist-standalone/graceful-degradation.js +1 -0
  173. package/dist-standalone/guardrails.js +1 -216
  174. package/dist-standalone/health-check.d.ts +150 -0
  175. package/dist-standalone/health-check.js +1 -0
  176. package/dist-standalone/http-compat.js +1 -267
  177. package/dist-standalone/http-status-map.js +1 -561
  178. package/dist-standalone/identity.d.ts +64 -1
  179. package/dist-standalone/identity.js +1 -515
  180. package/dist-standalone/index.d.ts +45 -3
  181. package/dist-standalone/index.js +1 -52
  182. package/dist-standalone/invitation.js +1 -415
  183. package/dist-standalone/invite.js +1 -324
  184. package/dist-standalone/key-agreement.d.ts +61 -13
  185. package/dist-standalone/key-agreement.js +1 -236
  186. package/dist-standalone/lazy-init.js +1 -295
  187. package/dist-standalone/logger.d.ts +77 -0
  188. package/dist-standalone/logger.js +1 -0
  189. package/dist-standalone/mdns-discovery.js +1 -195
  190. package/dist-standalone/nonce-store.d.ts +16 -3
  191. package/dist-standalone/nonce-store.js +1 -62
  192. package/dist-standalone/package.json +0 -1
  193. package/dist-standalone/pairing-manager.js +1 -219
  194. package/dist-standalone/plugin-system.d.ts +145 -0
  195. package/dist-standalone/plugin-system.js +1 -0
  196. package/dist-standalone/policy.js +1 -315
  197. package/dist-standalone/progress-callbacks.d.ts +394 -0
  198. package/dist-standalone/progress-callbacks.js +1 -0
  199. package/dist-standalone/redis-nonce-store.js +1 -72
  200. package/dist-standalone/registry-middleware.js +1 -47
  201. package/dist-standalone/retry-strategies.d.ts +382 -0
  202. package/dist-standalone/retry-strategies.js +1 -0
  203. package/dist-standalone/retry-transport.js +1 -98
  204. package/dist-standalone/security-policy.js +1 -239
  205. package/dist-standalone/serialization.d.ts +244 -0
  206. package/dist-standalone/serialization.js +1 -0
  207. package/dist-standalone/split-channel.d.ts +49 -1
  208. package/dist-standalone/split-channel.js +1 -171
  209. package/dist-standalone/subscription-proof.js +1 -224
  210. package/dist-standalone/succession.js +1 -142
  211. package/dist-standalone/timeouts.d.ts +275 -0
  212. package/dist-standalone/timeouts.js +1 -0
  213. package/dist-standalone/trace-context.d.ts +252 -0
  214. package/dist-standalone/trace-context.js +1 -0
  215. package/dist-standalone/trace-spans.d.ts +360 -0
  216. package/dist-standalone/trace-spans.js +1 -0
  217. package/dist-standalone/transport.js +1 -59
  218. package/dist-standalone/trust-registry.d.ts +106 -5
  219. package/dist-standalone/trust-registry.js +1 -702
  220. package/dist-standalone/vault-auth.d.ts +91 -0
  221. package/dist-standalone/vault-auth.js +1 -0
  222. package/dist-standalone/vault-store-loader.d.ts +110 -0
  223. package/dist-standalone/vault-store-loader.js +1 -0
  224. package/dist-standalone/verify.js +1 -16
  225. package/dist-standalone/version-info.d.ts +259 -0
  226. package/dist-standalone/version-info.js +1 -0
  227. package/dist-standalone/xfetch.js +1 -247
  228. package/llms.txt +1 -0
  229. package/package.json +65 -5
  230. package/share1.dat +0 -0
  231. package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
  232. package/dist-standalone/_deps/crypto/base64.js +0 -222
  233. package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
  234. package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
  235. package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
  236. package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
  237. package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
  238. package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
  239. package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
  240. package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
  241. package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
  242. package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
  243. package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
  244. package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
  245. package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
  246. package/dist-standalone/_deps/crypto/errors.js +0 -199
  247. package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
  248. package/dist-standalone/_deps/crypto/hmac.js +0 -134
  249. package/dist-standalone/_deps/crypto/index.d.ts +0 -20
  250. package/dist-standalone/_deps/crypto/index.js +0 -145
  251. package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
  252. package/dist-standalone/_deps/crypto/padding.js +0 -159
  253. package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
  254. package/dist-standalone/_deps/crypto/share-header.js +0 -92
  255. package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
  256. package/dist-standalone/_deps/crypto/shares.js +0 -295
  257. package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
  258. package/dist-standalone/_deps/crypto/tlv.js +0 -364
  259. package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
  260. package/dist-standalone/_deps/crypto/uuid.js +0 -136
  261. package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
  262. package/dist-standalone/_deps/crypto/verify.js +0 -71
  263. package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
  264. package/dist-standalone/_deps/crypto/xorida.js +0 -366
  265. package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
  266. package/dist-standalone/_deps/shared/errors.js.map +0 -1
  267. package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
  268. package/dist-standalone/_deps/shared/index.js.map +0 -1
  269. package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
  270. package/dist-standalone/_deps/shared/types.js.map +0 -1
  271. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
  272. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
  273. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
  274. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
  275. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
  276. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
  277. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
  278. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
  279. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
  280. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
  281. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
  282. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
  283. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
  284. package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
  285. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
  286. package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
  287. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
  288. package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
  289. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
  290. package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
  291. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
  292. package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
  293. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
  294. package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
  295. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
  296. package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
  297. package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
  298. package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
  299. package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
  300. package/dist-standalone/_deps/xregistry/index.js.map +0 -1
  301. package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
  302. package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
  303. package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
  304. package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
  305. package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
  306. package/dist-standalone/_deps/xregistry/types.js.map +0 -1
@@ -1,487 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- /* eslint-disable no-console */
4
- /**
5
- * @module cli/init
6
- * One-line CLI setup for XBind connections.
7
- *
8
- * Enables: npx xbind-init --invite <code>
9
- *
10
- * Flow:
11
- * 1. Parse invite URL or code
12
- * 2. Fetch invite details from registry server
13
- * 3. Interactive prompts for: project name, runtime, TypeScript vs JavaScript
14
- * 4. Generate project directory with template files
15
- * 5. Install dependencies
16
- * 6. Write .env file with XBIND_INVITE_CODE
17
- * 7. Register with XBind registry (auto-accept flow)
18
- * 8. Print success message with next steps
19
- *
20
- * @example
21
- * ```bash
22
- * npx xbind-init --invite https://xbind.to/invite/XBD-abc123
23
- *
24
- * # Prompts:
25
- * # → Project name: my-xbind-app
26
- * # → Runtime: node-typescript
27
- * # Creating project...
28
- * # Installing dependencies...
29
- * # Registering with XBind...
30
- * # ✅ Ready! Run: cd my-xbind-app && npm start
31
- * ```
32
- */
33
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
34
- if (k2 === undefined) k2 = k;
35
- var desc = Object.getOwnPropertyDescriptor(m, k);
36
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
37
- desc = { enumerable: true, get: function() { return m[k]; } };
38
- }
39
- Object.defineProperty(o, k2, desc);
40
- }) : (function(o, m, k, k2) {
41
- if (k2 === undefined) k2 = k;
42
- o[k2] = m[k];
43
- }));
44
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
45
- Object.defineProperty(o, "default", { enumerable: true, value: v });
46
- }) : function(o, v) {
47
- o["default"] = v;
48
- });
49
- var __importStar = (this && this.__importStar) || (function () {
50
- var ownKeys = function(o) {
51
- ownKeys = Object.getOwnPropertyNames || function (o) {
52
- var ar = [];
53
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
54
- return ar;
55
- };
56
- return ownKeys(o);
57
- };
58
- return function (mod) {
59
- if (mod && mod.__esModule) return mod;
60
- var result = {};
61
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
62
- __setModuleDefault(result, mod);
63
- return result;
64
- };
65
- })();
66
- Object.defineProperty(exports, "__esModule", { value: true });
67
- exports.initCommand = initCommand;
68
- exports.main = main;
69
- const node_util_1 = require("node:util");
70
- const fs = __importStar(require("node:fs"));
71
- const path = __importStar(require("node:path"));
72
- const node_child_process_1 = require("node:child_process");
73
- const readline = __importStar(require("node:readline/promises"));
74
- const node_process_1 = require("node:process");
75
- const invite_js_1 = require("../invite.js");
76
- // Get template directory path
77
- // In production, templates are at ../templates relative to dist/cli/init.js
78
- // We'll resolve this dynamically based on the package root
79
- function getTemplateDir() {
80
- // Find package root by looking for package.json
81
- let currentDir = __dirname;
82
- while (currentDir !== '/') {
83
- if (fs.existsSync(path.join(currentDir, 'package.json'))) {
84
- return path.join(currentDir, 'templates');
85
- }
86
- currentDir = path.dirname(currentDir);
87
- }
88
- // Fallback: assume we're in dist/cli and templates are in package root
89
- return path.join(__dirname, '../../templates');
90
- }
91
- const TEMPLATES = {
92
- 'node-typescript': {
93
- name: 'Node.js + TypeScript',
94
- description: 'Node.js with TypeScript, best for backend services',
95
- packageManager: 'npm',
96
- entryPoint: 'src/index.ts',
97
- startCommand: 'npm run dev',
98
- },
99
- 'node-javascript': {
100
- name: 'Node.js + JavaScript',
101
- description: 'Node.js with JavaScript, minimal setup',
102
- packageManager: 'npm',
103
- entryPoint: 'src/index.js',
104
- startCommand: 'npm start',
105
- },
106
- 'deno': {
107
- name: 'Deno',
108
- description: 'Modern TypeScript runtime',
109
- packageManager: 'deno',
110
- entryPoint: 'mod.ts',
111
- startCommand: 'deno run --allow-net --allow-env --allow-read mod.ts',
112
- },
113
- 'cloudflare-worker': {
114
- name: 'Cloudflare Worker',
115
- description: 'Edge runtime on Cloudflare',
116
- packageManager: 'npm',
117
- entryPoint: 'src/index.ts',
118
- startCommand: 'npm run dev',
119
- },
120
- 'vercel-function': {
121
- name: 'Vercel Function',
122
- description: 'Serverless function on Vercel',
123
- packageManager: 'npm',
124
- entryPoint: 'api/xbind.ts',
125
- startCommand: 'npm run dev',
126
- },
127
- };
128
- /**
129
- * Spinner for progress indication.
130
- */
131
- class Spinner {
132
- frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
133
- currentFrame = 0;
134
- intervalId;
135
- message;
136
- constructor(message) {
137
- this.message = message;
138
- }
139
- start() {
140
- this.intervalId = setInterval(() => {
141
- const frame = this.frames[this.currentFrame];
142
- process.stdout.write(`\r${frame} ${this.message}`);
143
- this.currentFrame = (this.currentFrame + 1) % this.frames.length;
144
- }, 80);
145
- }
146
- succeed(message) {
147
- this.stop();
148
- process.stdout.write(`\r✅ ${message ?? this.message}\n`);
149
- }
150
- fail(message) {
151
- this.stop();
152
- process.stdout.write(`\r❌ ${message ?? this.message}\n`);
153
- }
154
- stop() {
155
- if (this.intervalId) {
156
- clearInterval(this.intervalId);
157
- this.intervalId = undefined;
158
- }
159
- }
160
- }
161
- /**
162
- * Parse invite code/URL to extract invite ID.
163
- *
164
- * @param inviteInput - Invite URL or code
165
- * @returns Invite URL
166
- */
167
- function normalizeInviteUrl(inviteInput, registryUrl) {
168
- // If it's already a full URL, return as-is
169
- if (inviteInput.startsWith('http://') || inviteInput.startsWith('https://')) {
170
- return inviteInput;
171
- }
172
- // If it starts with XBD-, treat as code
173
- if (inviteInput.startsWith('XBD-')) {
174
- return `${registryUrl}/invite/${inviteInput}`;
175
- }
176
- // Otherwise, assume it's an ID
177
- return `${registryUrl}/invite/${inviteInput}`;
178
- }
179
- /**
180
- * Validate project name.
181
- *
182
- * @param name - Project name
183
- * @returns true if valid
184
- */
185
- function isValidProjectName(name) {
186
- return /^[a-z0-9-_]+$/i.test(name) && name.length > 0 && name.length <= 100;
187
- }
188
- /**
189
- * Prompt user for input.
190
- *
191
- * @param question - Question text
192
- * @param defaultValue - Default value
193
- * @returns User input
194
- */
195
- async function prompt(question, defaultValue) {
196
- const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
197
- const answer = await rl.question(defaultValue ? `${question} (${defaultValue}): ` : `${question}: `);
198
- rl.close();
199
- return answer.trim() || defaultValue || '';
200
- }
201
- /**
202
- * Prompt user to select from a list.
203
- *
204
- * @param question - Question text
205
- * @param choices - Available choices
206
- * @param defaultIndex - Default choice index
207
- * @returns Selected choice
208
- */
209
- async function select(question, choices, defaultIndex = 0) {
210
- console.log(question);
211
- choices.forEach((choice, i) => {
212
- const prefix = i === defaultIndex ? '→' : ' ';
213
- console.log(` ${prefix} ${i + 1}. ${choice.label} - ${choice.description}`);
214
- });
215
- const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
216
- const answer = await rl.question(`Select (1-${choices.length}): `);
217
- rl.close();
218
- const selectedIndex = parseInt(answer.trim(), 10) - 1;
219
- if (selectedIndex >= 0 && selectedIndex < choices.length) {
220
- return choices[selectedIndex]?.value ?? choices[defaultIndex]?.value ?? '';
221
- }
222
- return choices[defaultIndex]?.value ?? '';
223
- }
224
- /**
225
- * Run shell command.
226
- *
227
- * @param command - Command to run
228
- * @param args - Command arguments
229
- * @param cwd - Working directory
230
- * @returns Promise that resolves when command completes
231
- */
232
- function runCommand(command, args, cwd) {
233
- return new Promise((resolve, reject) => {
234
- const proc = (0, node_child_process_1.spawn)(command, args, {
235
- cwd,
236
- stdio: 'ignore',
237
- shell: true,
238
- });
239
- proc.on('close', (code) => {
240
- if (code === 0) {
241
- resolve();
242
- }
243
- else {
244
- reject(new Error(`Command failed with code ${code ?? 'unknown'}`));
245
- }
246
- });
247
- proc.on('error', reject);
248
- });
249
- }
250
- /**
251
- * Copy template files to project directory.
252
- *
253
- * @param templateName - Template name
254
- * @param projectPath - Project directory path
255
- * @param invite - Invite details
256
- */
257
- async function copyTemplate(templateName, projectPath, invite) {
258
- const templateDir = path.join(getTemplateDir(), templateName);
259
- // Read all files in template directory
260
- const files = await fs.promises.readdir(templateDir, { recursive: true, withFileTypes: true });
261
- for (const file of files) {
262
- if (file.isFile()) {
263
- // Get the parent path from the file dirent
264
- // Note: file.parentPath was added in Node.js 20.1.0, file.path is deprecated
265
- const parentPath = file.parentPath || file.path || templateDir;
266
- const relativePath = path.relative(templateDir, path.join(parentPath, file.name));
267
- const sourcePath = path.join(templateDir, relativePath);
268
- const destPath = path.join(projectPath, relativePath);
269
- // Create directory if it doesn't exist
270
- await fs.promises.mkdir(path.dirname(destPath), { recursive: true });
271
- // Read template file
272
- let content = await fs.promises.readFile(sourcePath, 'utf-8');
273
- // Replace placeholders
274
- if (invite) {
275
- content = content.replace(/{{INVITE_URL}}/g, invite.url);
276
- content = content.replace(/{{INVITE_ID}}/g, invite.id);
277
- content = content.replace(/{{SERVICE_NAME}}/g, invite.from.name);
278
- content = content.replace(/{{SERVICE_DID}}/g, invite.from.did);
279
- content = content.replace(/{{SERVICE_ENDPOINT}}/g, invite.from.endpoint);
280
- }
281
- // Write to destination
282
- await fs.promises.writeFile(destPath, content, 'utf-8');
283
- }
284
- }
285
- }
286
- /**
287
- * Install dependencies.
288
- *
289
- * @param projectPath - Project directory
290
- * @param packageManager - Package manager to use
291
- */
292
- async function installDependencies(projectPath, packageManager) {
293
- if (packageManager === 'npm') {
294
- await runCommand('npm', ['install'], projectPath);
295
- }
296
- else if (packageManager === 'deno') {
297
- // Deno doesn't need install, it auto-downloads
298
- }
299
- // 'none' for templates that don't need dependencies
300
- }
301
- /**
302
- * Main init command.
303
- *
304
- * @param options - Init options
305
- */
306
- async function initCommand(options = {}) {
307
- const registryUrl = options.registryUrl || 'https://xbind.to';
308
- // Step 1: Get invite details
309
- let invite;
310
- let inviteUrl;
311
- if (options.invite) {
312
- inviteUrl = normalizeInviteUrl(options.invite, registryUrl);
313
- const spinner = new Spinner('Fetching invite details...');
314
- spinner.start();
315
- try {
316
- const inviteService = new invite_js_1.InviteService({ inviteApiUrl: registryUrl });
317
- const inviteResult = await inviteService.get(inviteUrl);
318
- if (!inviteResult.ok) {
319
- spinner.fail(`Failed to fetch invite: ${inviteResult.error.message}`);
320
- if (inviteResult.error.hint) {
321
- console.error(`Hint: ${inviteResult.error.hint}`);
322
- }
323
- process.exitCode = 1;
324
- return;
325
- }
326
- invite = inviteResult.value;
327
- spinner.succeed(`Connected to ${invite.from.name}`);
328
- }
329
- catch (error) {
330
- spinner.fail('Failed to fetch invite details');
331
- console.error(error instanceof Error ? error.message : String(error));
332
- process.exitCode = 1;
333
- return;
334
- }
335
- }
336
- // Step 2: Prompt for project details (if not in --yes mode)
337
- let projectName = options.name;
338
- let runtime = options.runtime;
339
- if (!options.yes) {
340
- // Prompt for project name
341
- if (!projectName) {
342
- const suggestedName = invite ? `connect-${invite.from.name}` : 'my-xbind-app';
343
- projectName = await prompt('Project name', suggestedName);
344
- }
345
- // Prompt for runtime
346
- if (!runtime) {
347
- runtime = (await select('\nSelect runtime:', Object.entries(TEMPLATES).map(([value, meta]) => ({
348
- value,
349
- label: meta.name,
350
- description: meta.description,
351
- })), 0));
352
- }
353
- }
354
- else {
355
- // In --yes mode, use defaults
356
- projectName = projectName || 'my-xbind-app';
357
- runtime = runtime || 'node-typescript';
358
- }
359
- // Validate project name (applies to both modes)
360
- if (!isValidProjectName(projectName)) {
361
- console.error('❌ Invalid project name. Use only letters, numbers, hyphens, and underscores.');
362
- process.exitCode = 1;
363
- return;
364
- }
365
- // Check if directory exists (applies to both modes)
366
- const projectPath = path.resolve(process.cwd(), projectName);
367
- if (fs.existsSync(projectPath)) {
368
- console.error(`❌ Directory "${projectName}" already exists.`);
369
- process.exitCode = 1;
370
- return;
371
- }
372
- if (!runtime || !TEMPLATES[runtime]) {
373
- console.error('❌ Invalid runtime selection.');
374
- process.exitCode = 1;
375
- return;
376
- }
377
- const template = TEMPLATES[runtime];
378
- console.log(`\n📦 Creating ${template.name} project: ${projectName}`);
379
- // Step 3: Create project directory
380
- const createSpinner = new Spinner('Creating project structure...');
381
- createSpinner.start();
382
- try {
383
- await fs.promises.mkdir(projectPath, { recursive: true });
384
- await copyTemplate(runtime, projectPath, invite);
385
- createSpinner.succeed('Project structure created');
386
- }
387
- catch (error) {
388
- createSpinner.fail('Failed to create project structure');
389
- console.error(error instanceof Error ? error.message : String(error));
390
- process.exitCode = 1;
391
- return;
392
- }
393
- // Step 4: Install dependencies
394
- if (template.packageManager !== 'none' && process.env.NODE_ENV !== 'test') {
395
- const installSpinner = new Spinner('Installing dependencies...');
396
- installSpinner.start();
397
- try {
398
- await installDependencies(projectPath, template.packageManager);
399
- installSpinner.succeed('Dependencies installed');
400
- }
401
- catch (error) {
402
- installSpinner.fail('Failed to install dependencies');
403
- console.error('You can install them manually later.');
404
- // Don't exit, continue
405
- }
406
- }
407
- // Step 5: Write .env file with invite code (if provided)
408
- if (invite || inviteUrl) {
409
- const finalInviteUrl = invite?.url || inviteUrl || '';
410
- if (process.env.DEBUG_CLI) {
411
- console.log('[DEBUG] Writing .env file:', { invite: !!invite, inviteUrl, finalInviteUrl, projectPath });
412
- }
413
- if (finalInviteUrl) {
414
- await fs.promises.writeFile(path.join(projectPath, '.env'), `XBIND_INVITE_CODE=${finalInviteUrl}\n`, 'utf-8');
415
- }
416
- }
417
- else if (process.env.DEBUG_CLI) {
418
- console.log('[DEBUG] Not writing .env file:', { invite: !!invite, inviteUrl });
419
- }
420
- // Step 6: Print success message
421
- console.log('\n✅ Ready!\n');
422
- console.log('Next steps:');
423
- console.log(` cd ${projectName}`);
424
- console.log(` ${template.startCommand}`);
425
- if (invite) {
426
- console.log(`\n🔗 Connected to: ${invite.from.name}`);
427
- console.log(` DID: ${invite.from.did}`);
428
- }
429
- else {
430
- console.log('\n💡 To connect to a service, get an invite code and update .env file.');
431
- }
432
- }
433
- /**
434
- * CLI entry point.
435
- *
436
- * @param argv - Command-line arguments
437
- */
438
- async function main(argv = process.argv.slice(2)) {
439
- const { values } = (0, node_util_1.parseArgs)({
440
- args: argv,
441
- options: {
442
- invite: { type: 'string', short: 'i' },
443
- name: { type: 'string', short: 'n' },
444
- runtime: { type: 'string', short: 'r' },
445
- yes: { type: 'boolean', short: 'y' },
446
- 'registry-url': { type: 'string' },
447
- help: { type: 'boolean', short: 'h' },
448
- },
449
- });
450
- if (values.help) {
451
- console.log(`
452
- XBind CLI - One-Line M2M Setup
453
-
454
- Usage:
455
- npx xbind-init [options]
456
-
457
- Options:
458
- -i, --invite <url> Invite URL or code
459
- -n, --name <name> Project name
460
- -r, --runtime <runtime> Runtime template (node-typescript, node-javascript, deno, cloudflare-worker, vercel-function)
461
- -y, --yes Skip interactive prompts (use defaults)
462
- --registry-url <url> Custom registry URL (default: https://xbind.to)
463
- -h, --help Show this help message
464
-
465
- Examples:
466
- npx xbind-init --invite https://xbind.to/invite/XBD-abc123
467
- npx xbind-init --invite XBD-abc123 --name my-app --runtime node-typescript
468
- npx xbind-init --yes
469
- `.trim());
470
- return;
471
- }
472
- await initCommand({
473
- invite: values.invite,
474
- name: values.name,
475
- runtime: values.runtime,
476
- yes: values.yes,
477
- 'registry-url': values['registry-url'],
478
- });
479
- }
480
- // Auto-run if executed directly
481
- const isDirectRun = process.argv[1]?.endsWith('init.ts') || process.argv[1]?.endsWith('init.js');
482
- if (isDirectRun) {
483
- main().catch((error) => {
484
- console.error('Fatal:', error instanceof Error ? error.message : String(error));
485
- process.exitCode = 1;
486
- });
487
- }
2
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(null!=t)for(var r=e(t),i=0;i<r.length;i++)"default"!==r[i]&&__createBinding(n,t,r[i]);return __setModuleDefault(n,t),n}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.initCommand=initCommand,exports.main=main;const node_util_1=require("node:util"),fs=__importStar(require("node:fs")),path=__importStar(require("node:path")),node_child_process_1=require("node:child_process"),readline=__importStar(require("node:readline/promises")),node_process_1=require("node:process"),invite_js_1=require("../invite.js");function getTemplateDir(){let e=__dirname;for(;"/"!==e;){if(fs.existsSync(path.join(e,"package.json")))return path.join(e,"templates");e=path.dirname(e)}return path.join(__dirname,"../../templates")}const TEMPLATES={"node-typescript":{name:"Node.js + TypeScript",description:"Node.js with TypeScript, best for backend services",packageManager:"npm",entryPoint:"src/index.ts",startCommand:"npm run dev"},"node-javascript":{name:"Node.js + JavaScript",description:"Node.js with JavaScript, minimal setup",packageManager:"npm",entryPoint:"src/index.js",startCommand:"npm start"},deno:{name:"Deno",description:"Modern TypeScript runtime",packageManager:"deno",entryPoint:"mod.ts",startCommand:"deno run --allow-net --allow-env --allow-read mod.ts"},"cloudflare-worker":{name:"Cloudflare Worker",description:"Edge runtime on Cloudflare",packageManager:"npm",entryPoint:"src/index.ts",startCommand:"npm run dev"},"vercel-function":{name:"Vercel Function",description:"Serverless function on Vercel",packageManager:"npm",entryPoint:"api/xbind.ts",startCommand:"npm run dev"}};class Spinner{frames=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];currentFrame=0;intervalId;message;constructor(e){this.message=e}start(){this.intervalId=setInterval(()=>{const e=this.frames[this.currentFrame];process.stdout.write(`\r${e} ${this.message}`),this.currentFrame=(this.currentFrame+1)%this.frames.length},80)}succeed(e){this.stop(),process.stdout.write(`\r✅ ${e??this.message}\n`)}fail(e){this.stop(),process.stdout.write(`\r❌ ${e??this.message}\n`)}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=void 0)}}function normalizeInviteUrl(e,t){return e.startsWith("http://")||e.startsWith("https://")?e:(e.startsWith("XBD-"),`${t}/invite/${e}`)}function isValidProjectName(e){return/^[a-z0-9-_]+$/i.test(e)&&e.length>0&&e.length<=100}async function prompt(e,t){const n=readline.createInterface({input:node_process_1.stdin,output:node_process_1.stdout}),r=await n.question(t?`${e} (${t}): `:`${e}: `);return n.close(),r.trim()||t||""}async function select(e,t,n=0){console.log(e),t.forEach((e,t)=>{const r=t===n?"→":" ";console.log(` ${r} ${t+1}. ${e.label} - ${e.description}`)});const r=readline.createInterface({input:node_process_1.stdin,output:node_process_1.stdout}),i=await r.question(`Select (1-${t.length}): `);r.close();const o=parseInt(i.trim(),10)-1;return o>=0&&o<t.length?t[o]?.value??t[n]?.value??"":t[n]?.value??""}function runCommand(e,t,n){return new Promise((r,i)=>{const o=(0,node_child_process_1.spawn)(e,t,{cwd:n,stdio:"ignore",shell:!0});o.on("close",e=>{0===e?r():i(new Error(`Command failed with code ${e??"unknown"}`))}),o.on("error",i)})}async function copyTemplate(e,t,n){const r=path.join(getTemplateDir(),e),i=await fs.promises.readdir(r,{recursive:!0,withFileTypes:!0});for(const e of i)if(e.isFile()){const i=e.parentPath||e.path||r,o=path.relative(r,path.join(i,e.name)),s=path.join(r,o),a=path.join(t,o);await fs.promises.mkdir(path.dirname(a),{recursive:!0});let c=await fs.promises.readFile(s,"utf-8");n&&(c=c.replace(/{{INVITE_URL}}/g,n.url),c=c.replace(/{{INVITE_ID}}/g,n.id),c=c.replace(/{{SERVICE_NAME}}/g,n.from.name),c=c.replace(/{{SERVICE_DID}}/g,n.from.did),c=c.replace(/{{SERVICE_ENDPOINT}}/g,n.from.endpoint)),await fs.promises.writeFile(a,c,"utf-8")}}async function installDependencies(e,t){"npm"===t&&await runCommand("npm",["install"],e)}async function initCommand(e={}){const t=e.registryUrl||"https://xbind.to";let n,r;if(e.invite){r=normalizeInviteUrl(e.invite,t);const i=new Spinner("Fetching invite details...");i.start();try{const e=new invite_js_1.InviteService({inviteApiUrl:t}),o=await e.get(r);if(!o.ok)return i.fail(`Failed to fetch invite: ${o.error.message}`),o.error.hint&&console.error(`Hint: ${o.error.hint}`),void(process.exitCode=1);if(n=o.value,!n)return i.fail("Invalid invite data received"),void(process.exitCode=1);i.succeed(`Connected to ${n.from.name}`)}catch(e){return i.fail("Failed to fetch invite details"),console.error(e instanceof Error?e.message:String(e)),void(process.exitCode=1)}}let i=e.name,o=e.runtime;if(e.yes)i=i||"my-xbind-app",o=o||"node-typescript";else{if(!i){const e=n?`connect-${n.from.name}`:"my-xbind-app";i=await prompt("Project name",e)}o||(o=await select("\nSelect runtime:",Object.entries(TEMPLATES).map(([e,t])=>({value:e,label:t.name,description:t.description})),0))}if(!isValidProjectName(i))return console.error("❌ Invalid project name. Use only letters, numbers, hyphens, and underscores."),void(process.exitCode=1);const s=path.resolve(process.cwd(),i);if(fs.existsSync(s))return console.error(`❌ Directory "${i}" already exists.`),void(process.exitCode=1);if(!o||!TEMPLATES[o])return console.error("❌ Invalid runtime selection."),void(process.exitCode=1);const a=TEMPLATES[o];console.log(`\n📦 Creating ${a.name} project: ${i}`);const c=new Spinner("Creating project structure...");c.start();try{await fs.promises.mkdir(s,{recursive:!0}),await copyTemplate(o,s,n),c.succeed("Project structure created")}catch(e){return c.fail("Failed to create project structure"),console.error(e instanceof Error?e.message:String(e)),void(process.exitCode=1)}if("none"!==a.packageManager&&"test"!==process.env.NODE_ENV){const e=new Spinner("Installing dependencies...");e.start();try{await installDependencies(s,a.packageManager),e.succeed("Dependencies installed")}catch(t){e.fail("Failed to install dependencies"),console.error("You can install them manually later.")}}if(n||r){const e=n?.url||r||"";process.env.DEBUG_CLI&&console.log("[DEBUG] Writing .env file:",{invite:!!n,inviteUrl:r,finalInviteUrl:e,projectPath:s}),e&&await fs.promises.writeFile(path.join(s,".env"),`XBIND_INVITE_CODE=${e}\n`,"utf-8")}else process.env.DEBUG_CLI&&console.log("[DEBUG] Not writing .env file:",{invite:!!n,inviteUrl:r});console.log("\n✅ Ready!\n"),console.log("Next steps:"),console.log(` cd ${i}`),console.log(` ${a.startCommand}`),n?(console.log(`\n🔗 Connected to: ${n.from.name}`),console.log(` DID: ${n.from.did}`)):console.log("\n💡 To connect to a service, get an invite code and update .env file.")}async function main(e=process.argv.slice(2)){const{values:t}=(0,node_util_1.parseArgs)({args:e,options:{invite:{type:"string",short:"i"},name:{type:"string",short:"n"},runtime:{type:"string",short:"r"},yes:{type:"boolean",short:"y"},"registry-url":{type:"string"},help:{type:"boolean",short:"h"}}});t.help?console.log("\nXBind CLI - One-Line M2M Setup\n\nUsage:\n npx xbind-init [options]\n\nOptions:\n -i, --invite <url> Invite URL or code\n -n, --name <name> Project name\n -r, --runtime <runtime> Runtime template (node-typescript, node-javascript, deno, cloudflare-worker, vercel-function)\n -y, --yes Skip interactive prompts (use defaults)\n --registry-url <url> Custom registry URL (default: https://xbind.to)\n -h, --help Show this help message\n\nExamples:\n npx xbind-init --invite https://xbind.to/invite/XBD-abc123\n npx xbind-init --invite XBD-abc123 --name my-app --runtime node-typescript\n npx xbind-init --yes\n ".trim()):await initCommand({invite:t.invite,name:t.name,runtime:t.runtime,yes:t.yes,"registry-url":t["registry-url"]})}const isDirectRun=process.argv[1]?.endsWith("init.ts")||process.argv[1]?.endsWith("init.js");isDirectRun&&main().catch(e=>{console.error("Fatal:",e instanceof Error?e.message:String(e)),process.exitCode=1});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AGENT_CREATE_OPTIONS_DEFAULTS=exports.AGENT_OPTIONS_DEFAULTS=exports.ConfigValidationError=void 0,exports.validateAgentOptions=validateAgentOptions,exports.validateAgentCreateOptions=validateAgentCreateOptions,exports.getValidationDetails=getValidationDetails,exports.assertValidConfig=assertValidConfig,exports.assertValidCreateConfig=assertValidCreateConfig;const shared_1=require("../_deps/shared/index.js"),errors_js_1=require("./errors.js");class ConfigValidationError extends errors_js_1.XBindError{field;expected;actual;fix;constructor(t,e,r,i){super("CONFIG_INVALID",`Configuration validation failed for '${t}': Expected ${e}, got ${"object"==typeof r&&null!==r?JSON.stringify(r):String(r)}. ${i}`,"https://private.me/docs/xbind/api/configuration"),this.name="ConfigValidationError",this.field=t,this.expected=e,this.actual=r,this.fix=i}}function validateAgentOptions(t){if(!t||"object"!=typeof t)return(0,shared_1.err)(new ConfigValidationError("options","object",t,"Provide a configuration object with at least one option."));const e=t,r=[],i=[];if(void 0!==e.identity&&("string"!=typeof e.identity?r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Use 'persistent' for long-lived DIDs or 'ephemeral' for short-lived DIDs.")):"persistent"!==e.identity&&"ephemeral"!==e.identity&&r.push(new ConfigValidationError("identity","'persistent' | 'ephemeral'",e.identity,"Invalid identity mode. Use 'persistent' or 'ephemeral'."))),void 0!==e.identityTTL&&("number"!=typeof e.identityTTL?r.push(new ConfigValidationError("identityTTL","number (milliseconds)",e.identityTTL,"Provide TTL as a number in milliseconds (e.g., 3600000 for 1 hour).")):e.identityTTL<=0?r.push(new ConfigValidationError("identityTTL","positive number",e.identityTTL,"TTL must be greater than 0. Use at least 60000 (1 minute).")):e.identityTTL<6e4?i.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute) to avoid frequent re-registrations.`):e.identityTTL>864e5&&i.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead for long-lived agents.`),"persistent"===e.identity&&i.push("identityTTL is ignored for 'persistent' identity mode. Remove this option or switch to 'ephemeral' mode.")),void 0!==e.registry){const t="string"==typeof e.registry,i="object"==typeof e.registry&&null!==e.registry;if(t||i){if(t){const t=e.registry;try{const e=new URL(t);"http:"!==e.protocol&&"https:"!==e.protocol&&r.push(new ConfigValidationError("registry","HTTP(S) URL",t,"Registry URL must use HTTP or HTTPS protocol."))}catch{r.push(new ConfigValidationError("registry","valid URL",t,'Provide a valid URL (e.g., "https://private.me/registry").'))}}else if(i){const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement ${i.join(", ")} method(s). Use HttpTrustRegistry or MemoryTrustRegistry.`))}}else r.push(new ConfigValidationError("registry","TrustRegistry instance or URL string",e.registry,'Provide either a registry URL (e.g., "https://private.me/registry") or a TrustRegistry instance.'))}if(void 0!==e.transport){const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters for split-channel security."))}if(void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}if(void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.backupConfig)if("object"!=typeof e.backupConfig||null===e.backupConfig)r.push(new ConfigValidationError("backupConfig","BackupConfig object",e.backupConfig,"Provide a BackupConfig object with threshold (k) and totalShares (n) properties."));else{const t=e.backupConfig;"number"!=typeof t.threshold?r.push(new ConfigValidationError("backupConfig.threshold","number",t.threshold,"Threshold (k) must be a number representing shares needed for reconstruction.")):t.threshold<2&&r.push(new ConfigValidationError("backupConfig.threshold","number >= 2",t.threshold,"Threshold must be at least 2 for meaningful splitting.")),"number"!=typeof t.totalShares?r.push(new ConfigValidationError("backupConfig.totalShares","number",t.totalShares,"totalShares (n) must be a number representing total shares to create.")):t.totalShares<2&&r.push(new ConfigValidationError("backupConfig.totalShares","number >= 2",t.totalShares,"totalShares must be at least 2 for splitting.")),"number"==typeof t.threshold&&"number"==typeof t.totalShares&&t.threshold>t.totalShares&&r.push(new ConfigValidationError("backupConfig","threshold <= totalShares",`threshold=${t.threshold}, totalShares=${t.totalShares}`,`Threshold (${t.threshold}) cannot exceed totalShares (${t.totalShares}). Use threshold <= totalShares.`))}return r.length>0?(0,shared_1.err)(r[0]):(0,shared_1.ok)(e)}function validateAgentCreateOptions(t){if(!t||"object"!=typeof t)return(0,shared_1.err)(new ConfigValidationError("options","object",t,"Provide a configuration object with required fields: name, registry, transport."));const e=t,r=[];if(void 0===e.name?r.push(new ConfigValidationError("name","string (required)",void 0,'Provide a display name for the agent (e.g., "my-agent").')):"string"!=typeof e.name?r.push(new ConfigValidationError("name","string",e.name,"Agent name must be a string.")):0===e.name.trim().length?r.push(new ConfigValidationError("name","non-empty string",e.name,"Agent name cannot be empty or whitespace only.")):e.name.length>255&&r.push(new ConfigValidationError("name","string with length <= 255",e.name,`Agent name is too long (${e.name.length} characters). Use 255 characters or less.`)),void 0===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry (required)",void 0,"Provide a TrustRegistry instance (e.g., new MemoryTrustRegistry() or new HttpTrustRegistry())."));else if("object"!=typeof e.registry||null===e.registry)r.push(new ConfigValidationError("registry","TrustRegistry instance",e.registry,"Registry must be a TrustRegistry instance, not a string or primitive value."));else{const t=e.registry,i=["register","resolve"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("registry","TrustRegistry instance","object missing required methods",`TrustRegistry must implement: ${i.join(", ")}. Use HttpTrustRegistry or MemoryTrustRegistry.`))}if(void 0===e.transport)r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[] (required)",void 0,"Provide a transport adapter (e.g., new HttpsTransportAdapter()) or array of adapters for split-channel."));else{const t=Array.isArray(e.transport);if("object"==typeof e.transport&&null!==e.transport&&!t||t)if(t){const t=e.transport;0===t.length&&r.push(new ConfigValidationError("transport","non-empty array",t,"Provide at least one transport adapter.")),t.forEach((t,e)=>{if("object"!=typeof t||null===t)r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter",t,"Each transport must be a XailTransportAdapter instance."));else{"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError(`transport[${e}]`,"XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}})}else{const t=e.transport;"send"in t&&"function"==typeof t.send||r.push(new ConfigValidationError("transport","XailTransportAdapter with send() method","object missing send() method","Transport must implement send() method. Use HttpsTransportAdapter or custom adapter."))}else r.push(new ConfigValidationError("transport","XailTransportAdapter or XailTransportAdapter[]",e.transport,"Provide a single transport adapter or an array of adapters."))}if(void 0!==e.nonceStore)if("object"!=typeof e.nonceStore||null===e.nonceStore)r.push(new ConfigValidationError("nonceStore","NonceStore instance",e.nonceStore,"Provide a NonceStore instance (e.g., new MemoryNonceStore())."));else{const t=e.nonceStore,i=["check","cleanup"].filter(e=>!(e in t)||"function"!=typeof t[e]);i.length>0&&r.push(new ConfigValidationError("nonceStore","NonceStore instance","object missing required methods",`NonceStore must implement: ${i.join(", ")}. Use MemoryNonceStore.`))}if(void 0!==e.scopes)if(Array.isArray(e.scopes)){e.scopes.forEach((t,e)=>{"string"!=typeof t?r.push(new ConfigValidationError(`scopes[${e}]`,"string",t,"Each scope must be a string.")):0===t.trim().length&&r.push(new ConfigValidationError(`scopes[${e}]`,"non-empty string",t,"Scope cannot be empty or whitespace only."))})}else r.push(new ConfigValidationError("scopes","string[]",e.scopes,'Provide an array of scope strings (e.g., ["read", "write"]).'));if(void 0!==e.timestampWindowMs&&("number"!=typeof e.timestampWindowMs?r.push(new ConfigValidationError("timestampWindowMs","number (milliseconds)",e.timestampWindowMs,"Provide timestamp window as a number in milliseconds (e.g., 30000 for 30 seconds).")):e.timestampWindowMs<=0?r.push(new ConfigValidationError("timestampWindowMs","positive number",e.timestampWindowMs,"Timestamp window must be greater than 0. Use at least 1000 (1 second).")):e.timestampWindowMs<5e3?r.push(new ConfigValidationError("timestampWindowMs","number >= 5000",e.timestampWindowMs,"Timestamp window is very short. Use at least 5000ms (5 seconds) to account for clock skew.")):e.timestampWindowMs>3e5&&r.push(new ConfigValidationError("timestampWindowMs","number <= 300000",e.timestampWindowMs,"Timestamp window is very long. Consider using 300000ms (5 minutes) or less for security."))),void 0!==e.postQuantumSig&&"boolean"!=typeof e.postQuantumSig&&r.push(new ConfigValidationError("postQuantumSig","boolean",e.postQuantumSig,"Use true to enable ML-DSA-65 post-quantum signatures, or false to disable.")),void 0!==e.xchange&&"boolean"!=typeof e.xchange&&r.push(new ConfigValidationError("xchange","boolean",e.xchange,"Use true to advertise Xchange mode support, or false to disable.")),void 0!==e.securityPolicy)if("object"!=typeof e.securityPolicy||null===e.securityPolicy)r.push(new ConfigValidationError("securityPolicy","SecurityPolicy instance",e.securityPolicy,"Provide a SecurityPolicy instance (e.g., DefaultSecurityPolicy or custom policy)."));else{const t=e.securityPolicy;"classify"in t&&"function"==typeof t.classify||r.push(new ConfigValidationError("securityPolicy","SecurityPolicy with classify() method","object missing classify() method","SecurityPolicy must implement classify() method. Use DefaultSecurityPolicy."))}return r.length>0?(0,shared_1.err)(r[0]):(0,shared_1.ok)(e)}function getValidationDetails(t){const e=[],r=[],i=validateAgentOptions(t);if(i.ok||e.push(i.error),t&&"object"==typeof t){const e=t;"number"==typeof e.identityTTL&&(e.identityTTL<6e4&&e.identityTTL>0?r.push(`identityTTL is very short (${e.identityTTL}ms). Consider using at least 60000ms (1 minute).`):e.identityTTL>864e5&&r.push(`identityTTL is very long (${e.identityTTL}ms). Consider using 'persistent' identity mode instead.`),"persistent"===e.identity&&r.push("identityTTL is ignored for 'persistent' identity mode."))}return{valid:0===e.length,errors:e,warnings:r}}function assertValidConfig(t){const e=validateAgentOptions(t);if(!e.ok)throw e.error}function assertValidCreateConfig(t){const e=validateAgentCreateOptions(t);if(!e.ok)throw e.error}exports.ConfigValidationError=ConfigValidationError,exports.AGENT_OPTIONS_DEFAULTS={identity:"persistent",identityTTL:36e5,postQuantumSig:!1},exports.AGENT_CREATE_OPTIONS_DEFAULTS={timestampWindowMs:3e4,postQuantumSig:!1,xchange:!1,scopes:[]};