@myop/cli 0.1.17 β†’ 0.1.19

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 (2) hide show
  1. package/dist/myop-cli.js +446 -461
  2. package/package.json +1 -1
package/dist/myop-cli.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import F from "ora";
3
- import { select as Ie, Separator as me } from "@inquirer/prompts";
4
- import { Command as We, Option as ce } from "commander";
5
- import { execSync as re, spawn as Ge } from "child_process";
3
+ import { select as _e, Separator as ue } from "@inquirer/prompts";
4
+ import { Command as Ge, Option as ce } from "commander";
5
+ import { execSync as re, spawn as Ye } from "child_process";
6
6
  import Z from "path";
7
7
  import A from "fs";
8
- import fe from "crypto";
9
- import Ye from "http";
10
- import { URL as je, URLSearchParams as _e } from "url";
11
- import Ke from "open";
12
- import Xe from "os";
13
- const Qe = `
8
+ import ge from "crypto";
9
+ import Ke from "http";
10
+ import { URL as Ne, URLSearchParams as ke } from "url";
11
+ import Xe from "open";
12
+ import Qe from "os";
13
+ const Ze = `
14
14
  Usage: myop [OPTIONS] COMMAND [ARGS]...
15
15
 
16
16
  A powerful command-line interface for managing your Myop projects.
@@ -52,7 +52,7 @@ Examples:
52
52
  verbose: !1
53
53
  },
54
54
  myopConfig: null
55
- }, Pe = {
55
+ }, Ee = {
56
56
  name: "πŸ“₯ Install Myop generated dependencies",
57
57
  value: "myopInstall",
58
58
  description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
@@ -64,69 +64,69 @@ Examples:
64
64
  }
65
65
  process.exit();
66
66
  }
67
- }, Ze = (e) => {
67
+ }, qe = (e) => {
68
68
  const o = Z.join(d.executionPath, e);
69
69
  console.info(`reading config file from: ${o}`);
70
- const n = A.readFileSync(o, "utf8"), a = JSON.parse(n);
71
- return console.info("config file loaded, ", a), a;
72
- }, ge = (e, o) => {
73
- const n = Z.join(d.executionPath, e);
74
- console.info(`writing config file to: ${n}`);
70
+ const s = A.readFileSync(o, "utf8"), r = JSON.parse(s);
71
+ return console.info("config file loaded, ", r), r;
72
+ }, he = (e, o) => {
73
+ const s = Z.join(d.executionPath, e);
74
+ console.info(`writing config file to: ${s}`);
75
75
  try {
76
- const a = JSON.stringify(o, null, 2);
77
- A.writeFileSync(n, a), console.info(`config file updated ${a}`);
78
- } catch (a) {
79
- throw console.info(`error ${a} while writing to ${n}, JSON: ${o}`), console.log(`
80
- ⚠️ Failed write config file to ${n}, for more info use verbose flag`), a;
76
+ const r = JSON.stringify(o, null, 2);
77
+ A.writeFileSync(s, r), console.info(`config file updated ${r}`);
78
+ } catch (r) {
79
+ throw console.info(`error ${r} while writing to ${s}, JSON: ${o}`), console.log(`
80
+ ⚠️ Failed write config file to ${s}, for more info use verbose flag`), r;
81
81
  }
82
- }, Ee = {
82
+ }, Te = {
83
83
  name: "🌟 Add flow definition to your project",
84
84
  value: "addFlow",
85
85
  description: "Adds flow to yours myop.config.json",
86
86
  _action: (e) => {
87
- d.myopConfig.flows.includes(e) || d.myopConfig.flows.push(e), ge(d.options.configPath, d.myopConfig);
87
+ d.myopConfig.flows.includes(e) || d.myopConfig.flows.push(e), he(d.options.configPath, d.myopConfig);
88
88
  },
89
89
  action: async () => {
90
90
  }
91
- }, Ne = {
91
+ }, Pe = {
92
92
  name: "🚫 Remove flow definition from your project",
93
93
  value: "removeFlow",
94
94
  description: "Removes flow to yours myop.config.json",
95
95
  _action: (e) => {
96
- d.myopConfig.flows = d.myopConfig.flows.filter((o) => o !== e), ge(d.options.configPath, d.myopConfig);
96
+ d.myopConfig.flows = d.myopConfig.flows.filter((o) => o !== e), he(d.options.configPath, d.myopConfig);
97
97
  },
98
98
  action: () => {
99
99
  }
100
- }, qe = {
100
+ }, et = {
101
101
  name: "πŸ‘‹ Quit",
102
102
  value: "quit",
103
103
  description: "Quit and continue coding.",
104
104
  action: () => {
105
105
  process.exit();
106
106
  }
107
- }, et = {
107
+ }, tt = {
108
108
  name: "🟒 Create new component",
109
109
  value: "-",
110
110
  disabled: "(not available yet)"
111
- }, tt = {
111
+ }, ot = {
112
112
  name: "πŸ”΅ Create new experience",
113
113
  value: "-",
114
114
  disabled: "(not available yet)"
115
- }, ot = {
115
+ }, nt = {
116
116
  name: "🟑 Create new skin",
117
117
  value: "-",
118
118
  disabled: "(not available yet)"
119
- }, nt = {
119
+ }, st = {
120
120
  name: "πŸ”΄ Create new flow",
121
121
  value: "-",
122
122
  disabled: "(not available yet)"
123
- }, st = {
123
+ }, rt = {
124
124
  name: "πŸ†• Define new custom Myop message",
125
125
  value: "generateMyopMessage",
126
126
  description: "️Help you creates the right structure for a new Myop message, including types and handlers.",
127
127
  disabled: "(not available yet)"
128
- }, rt = [st, et, tt, ot, nt];
129
- function it(e, o, n, a) {
128
+ }, it = [rt, tt, ot, nt, st];
129
+ function at(e, o, s, r) {
130
130
  return `<!DOCTYPE html>
131
131
  <html lang="en">
132
132
  <head>
@@ -134,7 +134,7 @@ function it(e, o, n, a) {
134
134
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
135
135
  <title>Myop DevTools - localhost:${e}</title>
136
136
  <style>
137
- ${n}
137
+ ${s}
138
138
  </style>
139
139
  </head>
140
140
  <body>
@@ -211,32 +211,32 @@ ${n}
211
211
  // Inject PORT as a global variable for the app to use
212
212
  window.PORT = ${e};
213
213
 
214
- ${a}
214
+ ${r}
215
215
  <\/script>
216
216
  </body>
217
217
  </html>`;
218
218
  }
219
- async function ke() {
220
- const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash: f } = await import("node:crypto");
219
+ async function Re() {
220
+ const e = await import("fs"), o = await import("path"), { exec: s } = await import("child_process"), r = await import("http"), { createHash: f } = await import("node:crypto");
221
221
  let c;
222
222
  if (import.meta.url.startsWith("file://")) {
223
- const t = new URL(import.meta.url).pathname, r = process.platform === "win32" && t.startsWith("/") ? t.slice(1) : t;
224
- c = o.default.dirname(r);
223
+ const t = new URL(import.meta.url).pathname, i = process.platform === "win32" && t.startsWith("/") ? t.slice(1) : t;
224
+ c = o.default.dirname(i);
225
225
  } else
226
226
  c = o.default.dirname(import.meta.url);
227
- const m = o.default.join(c, "commands", "dev", "management-website"), w = e.default.readFileSync(o.default.join(m, "styles.css"), "utf-8"), I = e.default.readFileSync(o.default.join(m, "app.js"), "utf-8"), u = 9292, y = 9293, S = "./dist";
227
+ const m = o.default.join(c, "commands", "dev", "management-website"), w = e.default.readFileSync(o.default.join(m, "styles.css"), "utf-8"), I = e.default.readFileSync(o.default.join(m, "app.js"), "utf-8"), u = 9292, y = 9293, b = "./dist";
228
228
  let j = !1, v = !1;
229
- const k = /* @__PURE__ */ new Map(), z = d.program.getOptionValue("config") || "./myop.config.json";
230
- let x, E, h = !1;
229
+ const T = /* @__PURE__ */ new Map(), z = d.program.getOptionValue("config") || "./myop.config.json";
230
+ let S, k, h = !1;
231
231
  try {
232
- const s = e.default.readFileSync(z, "utf-8"), t = JSON.parse(s);
233
- x = t.componentId || "DEV", E = t.componentName || t.name || null, h = t.HMR === !0, h && console.log("πŸ”₯ HMR enabled");
234
- } catch (s) {
235
- console.error("❌ Error reading myop.config.json:", s.message), process.exit(1);
232
+ const n = e.default.readFileSync(z, "utf-8"), t = JSON.parse(n);
233
+ S = t.componentId || "DEV", k = t.componentName || t.name || null, h = t.HMR === !0, h && console.log("πŸ”₯ HMR enabled");
234
+ } catch (n) {
235
+ console.error("❌ Error reading myop.config.json:", n.message), process.exit(1);
236
236
  }
237
- const $ = async () => {
238
- if (x !== "DEV" && x !== "NEW")
239
- return x;
237
+ const M = async () => {
238
+ if (S !== "DEV" && S !== "NEW")
239
+ return S;
240
240
  try {
241
241
  const t = ((await new Promise((l, p) => {
242
242
  const g = {
@@ -245,9 +245,9 @@ async function ke() {
245
245
  path: "/_list",
246
246
  method: "GET",
247
247
  timeout: 1e3
248
- }, M = a.default.request(g, (_) => {
248
+ }, $ = r.default.request(g, (N) => {
249
249
  let H = "";
250
- _.on("data", (L) => H += L), _.on("end", () => {
250
+ N.on("data", (L) => H += L), N.on("end", () => {
251
251
  try {
252
252
  l(JSON.parse(H));
253
253
  } catch {
@@ -255,23 +255,23 @@ async function ke() {
255
255
  }
256
256
  });
257
257
  });
258
- M.on("error", () => l({ components: [] })), M.on("timeout", () => {
259
- M.destroy(), l({ components: [] });
260
- }), M.end();
258
+ $.on("error", () => l({ components: [] })), $.on("timeout", () => {
259
+ $.destroy(), l({ components: [] });
260
+ }), $.end();
261
261
  })).components || []).map(([l]) => l).filter((l) => l === "DEV" || l === "NEW" || /^DEV\d+$/.test(l) || /^NEW\d+$/.test(l));
262
262
  if (t.length === 0)
263
263
  return "DEV1";
264
- const r = t.map((l) => {
264
+ const i = t.map((l) => {
265
265
  if (l === "DEV" || l === "NEW") return 1;
266
266
  const p = l.match(/^DEV(\d+)$/), g = l.match(/^NEW(\d+)$/);
267
267
  return p ? parseInt(p[1], 10) : g ? parseInt(g[1], 10) : 0;
268
268
  }).filter((l) => l > 0);
269
- return `DEV${Math.max(...r, 0) + 1}`;
269
+ return `DEV${Math.max(...i, 0) + 1}`;
270
270
  } catch {
271
271
  return "DEV1";
272
272
  }
273
- }, N = process.cwd(), K = (s) => {
274
- const t = o.default.extname(s).toLowerCase();
273
+ }, E = process.cwd(), K = (n) => {
274
+ const t = o.default.extname(n).toLowerCase();
275
275
  return {
276
276
  ".html": "text/html",
277
277
  ".js": "text/javascript",
@@ -283,9 +283,9 @@ async function ke() {
283
283
  ".svg": "image/svg+xml",
284
284
  ".ico": "image/x-icon"
285
285
  }[t] || "application/octet-stream";
286
- }, b = /* @__PURE__ */ new Map(), q = [], Ae = 50, D = [], V = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map(), De = (s, t, r) => {
287
- if (s.url.startsWith("/_hmr/")) {
288
- const i = s.url.split("/_hmr/")[1], l = s.headers["sec-websocket-key"], p = f("sha1").update(l + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
286
+ }, x = /* @__PURE__ */ new Map(), q = [], He = 50, D = [], W = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map(), Le = (n, t, i) => {
287
+ if (n.url.startsWith("/_hmr/")) {
288
+ const a = n.url.split("/_hmr/")[1], l = n.headers["sec-websocket-key"], p = f("sha1").update(l + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
289
289
  t.write(
290
290
  `HTTP/1.1 101 Switching Protocols\r
291
291
  Upgrade: websocket\r
@@ -293,50 +293,50 @@ Connection: Upgrade\r
293
293
  Sec-WebSocket-Accept: ${p}\r
294
294
  \r
295
295
  `
296
- ), U.has(i) || U.set(i, /* @__PURE__ */ new Set()), U.get(i).add(t), console.log(`πŸ”Œ HMR client connected: ${i}`), t.on("close", () => {
297
- const g = U.get(i);
298
- g && (g.delete(t), g.size === 0 && U.delete(i)), console.log(`πŸ”Œ HMR client disconnected: ${i}`);
296
+ ), U.has(a) || U.set(a, /* @__PURE__ */ new Set()), U.get(a).add(t), console.log(`πŸ”Œ HMR client connected: ${a}`), t.on("close", () => {
297
+ const g = U.get(a);
298
+ g && (g.delete(t), g.size === 0 && U.delete(a)), console.log(`πŸ”Œ HMR client disconnected: ${a}`);
299
299
  }), t.on("error", () => {
300
- const g = U.get(i);
300
+ const g = U.get(a);
301
301
  g && g.delete(t);
302
302
  });
303
303
  }
304
- }, de = a.default.createServer((s, t) => {
305
- if (t.setHeader("Content-Type", "application/json"), s.method === "POST" && s.url === "/_register") {
306
- let r = "";
307
- s.on("data", (i) => r += i), s.on("end", () => {
304
+ }, de = r.default.createServer((n, t) => {
305
+ if (t.setHeader("Content-Type", "application/json"), n.method === "POST" && n.url === "/_register") {
306
+ let i = "";
307
+ n.on("data", (a) => i += a), n.on("end", () => {
308
308
  try {
309
- const { componentId: i, distPath: l, componentName: p } = JSON.parse(r);
310
- b.set(i, { path: l, name: p || null });
309
+ const { componentId: a, distPath: l, componentName: p } = JSON.parse(i);
310
+ x.set(a, { path: l, name: p || null });
311
311
  const g = p ? ` (${p})` : "";
312
- console.log(`βœ… Registered: ${i}${g} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
313
- const M = Array.from(b.entries()).map(([_, H]) => ({
314
- id: _,
312
+ console.log(`βœ… Registered: ${a}${g} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(x.keys()) }));
313
+ const $ = Array.from(x.entries()).map(([N, H]) => ({
314
+ id: N,
315
315
  path: H.path,
316
316
  name: H.name
317
317
  }));
318
- D.forEach((_) => {
318
+ D.forEach((N) => {
319
319
  try {
320
- _.write(`data: ${JSON.stringify({
320
+ N.write(`data: ${JSON.stringify({
321
321
  type: "components",
322
- components: M
322
+ components: $
323
323
  })}
324
324
 
325
325
  `);
326
326
  } catch {
327
327
  }
328
328
  });
329
- } catch (i) {
330
- t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
329
+ } catch (a) {
330
+ t.writeHead(400), t.end(JSON.stringify({ error: a.message }));
331
331
  }
332
332
  });
333
- } else if (s.method === "POST" && s.url === "/_unregister") {
334
- let r = "";
335
- s.on("data", (i) => r += i), s.on("end", () => {
333
+ } else if (n.method === "POST" && n.url === "/_unregister") {
334
+ let i = "";
335
+ n.on("data", (a) => i += a), n.on("end", () => {
336
336
  try {
337
- const { componentId: i } = JSON.parse(r);
338
- b.delete(i), console.log(`❌ Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
339
- const l = Array.from(b.entries()).map(([p, g]) => ({
337
+ const { componentId: a } = JSON.parse(i);
338
+ x.delete(a), console.log(`❌ Unregistered: ${a}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
339
+ const l = Array.from(x.entries()).map(([p, g]) => ({
340
340
  id: p,
341
341
  path: g.path,
342
342
  name: g.name
@@ -352,81 +352,81 @@ Sec-WebSocket-Accept: ${p}\r
352
352
  } catch {
353
353
  }
354
354
  });
355
- } catch (i) {
356
- t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
355
+ } catch (a) {
356
+ t.writeHead(400), t.end(JSON.stringify({ error: a.message }));
357
357
  }
358
358
  });
359
- } else s.method === "GET" && s.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(b.entries()) }))) : (t.writeHead(404), t.end(JSON.stringify({ error: "Not found" })));
360
- }), ee = a.default.createServer((s, t) => {
361
- if (s.url.includes("..")) {
359
+ } else n.method === "GET" && n.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(x.entries()) }))) : (t.writeHead(404), t.end(JSON.stringify({ error: "Not found" })));
360
+ }), ee = r.default.createServer((n, t) => {
361
+ if (n.url.includes("..")) {
362
362
  t.writeHead(403, { "Content-Type": "text/plain" }), t.end("Forbidden");
363
363
  return;
364
364
  }
365
- const r = new URL(s.url, `http://localhost:${u}`), i = r.pathname, l = i.split("/").filter((P) => P);
366
- if (i.startsWith("/consume")) {
367
- const P = r.searchParams.get("id");
368
- if (!P) {
365
+ const i = new URL(n.url, `http://localhost:${u}`), a = i.pathname, l = a.split("/").filter((_) => _);
366
+ if (a.startsWith("/consume")) {
367
+ const _ = i.searchParams.get("id");
368
+ if (!_) {
369
369
  t.writeHead(400, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
370
370
  return;
371
371
  }
372
- const R = b.get(P), J = R ? R.path : null, Oe = (W) => {
373
- let C = "Unknown", T = "Unknown";
374
- if (s.headers.referer || s.headers.referrer) {
375
- const O = s.headers.referer || s.headers.referrer;
372
+ const R = x.get(_), J = R ? R.path : null, je = (V) => {
373
+ let C = "Unknown", P = "Unknown";
374
+ if (n.headers.referer || n.headers.referrer) {
375
+ const O = n.headers.referer || n.headers.referrer;
376
376
  try {
377
377
  const G = new URL(O);
378
- C = G.origin, T = G.hostname || G.origin;
378
+ C = G.origin, P = G.hostname || G.origin;
379
379
  } catch {
380
- C = O, T = O;
380
+ C = O, P = O;
381
381
  }
382
- } else if (s.headers.origin)
382
+ } else if (n.headers.origin)
383
383
  try {
384
- const O = new URL(s.headers.origin);
385
- C = O.origin, T = O.hostname || O.origin;
384
+ const O = new URL(n.headers.origin);
385
+ C = O.origin, P = O.hostname || O.origin;
386
386
  } catch {
387
- C = s.headers.origin, T = s.headers.origin;
387
+ C = n.headers.origin, P = n.headers.origin;
388
388
  }
389
- else if (s.socket.remoteAddress) {
390
- const O = s.socket.remoteAddress;
391
- O === "::1" || O === "::ffff:127.0.0.1" ? (C = "localhost", T = "localhost (direct)") : (C = O, T = O.replace("::ffff:", ""));
389
+ else if (n.socket.remoteAddress) {
390
+ const O = n.socket.remoteAddress;
391
+ O === "::1" || O === "::ffff:127.0.0.1" ? (C = "localhost", P = "localhost (direct)") : (C = O, P = O.replace("::ffff:", ""));
392
392
  }
393
- const pe = s.headers.referer || s.headers.referrer || C, ne = {
393
+ const pe = n.headers.referer || n.headers.referrer || C, ne = {
394
394
  type: "request",
395
- componentId: P,
395
+ componentId: _,
396
396
  timestamp: Date.now(),
397
- servedLocally: W,
397
+ servedLocally: V,
398
398
  referrer: pe,
399
399
  origin: C,
400
- originLabel: T
400
+ originLabel: P
401
401
  };
402
- V.has(C) || (V.set(C, {
402
+ W.has(C) || (W.set(C, {
403
403
  url: C,
404
- label: T,
404
+ label: P,
405
405
  firstSeen: Date.now(),
406
406
  requestCount: 0
407
407
  }), D.forEach((O) => {
408
408
  try {
409
409
  O.write(`data: ${JSON.stringify({
410
410
  type: "origins",
411
- origins: Array.from(V.values())
411
+ origins: Array.from(W.values())
412
412
  })}
413
413
 
414
414
  `);
415
415
  } catch {
416
416
  }
417
417
  }));
418
- const Ve = V.get(C);
419
- Ve.requestCount++, D.forEach((O) => {
418
+ const me = W.get(C);
419
+ me.requestCount++, D.forEach((O) => {
420
420
  try {
421
421
  O.write(`data: ${JSON.stringify({
422
422
  type: "origins",
423
- origins: Array.from(V.values())
423
+ origins: Array.from(W.values())
424
424
  })}
425
425
 
426
426
  `);
427
427
  } catch {
428
428
  }
429
- }), q.push(ne), q.length > Ae && q.shift(), D.forEach((O) => {
429
+ }), q.push(ne), q.length > He && q.shift(), D.forEach((O) => {
430
430
  try {
431
431
  O.write(`data: ${JSON.stringify(ne)}
432
432
 
@@ -436,38 +436,38 @@ Sec-WebSocket-Accept: ${p}\r
436
436
  });
437
437
  };
438
438
  if (J) {
439
- const W = o.default.join(J, "index.html");
440
- e.default.readFile(W, "utf-8", (C, T) => {
439
+ const V = o.default.join(J, "index.html");
440
+ e.default.readFile(V, "utf-8", (C, P) => {
441
441
  if (C) {
442
- console.log(`❌ File not found: ${W}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
442
+ console.log(`❌ File not found: ${V}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
443
443
  return;
444
444
  }
445
- const pe = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, ne = {
445
+ const pe = be(P, _), ne = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, me = {
446
446
  item: {
447
- name: P,
448
- id: P,
447
+ name: _,
448
+ id: _,
449
449
  consume_variant: [
450
450
  {
451
- id: pe,
451
+ id: ne,
452
452
  name: "dev version",
453
453
  loader: {
454
454
  type: "HTMLLoader",
455
455
  shadowRootMode: "localFrame",
456
- HTML: T
456
+ HTML: pe
457
457
  }
458
458
  }
459
459
  ]
460
460
  }
461
461
  };
462
- console.log(`βœ… Serving consume JSON for: ${P}`), Oe(!0), t.writeHead(200, {
462
+ console.log(`βœ… Serving consume JSON for: ${_}`), je(!0), t.writeHead(200, {
463
463
  "Content-Type": "application/json",
464
464
  "Access-Control-Allow-Origin": "*"
465
- }), t.end(JSON.stringify(ne, null, 2));
465
+ }), t.end(JSON.stringify(me, null, 2));
466
466
  });
467
467
  } else {
468
- console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${P}`);
469
- const W = `https://cloud.myop.dev/consume${r.search}`;
470
- Oe(!1), fetch(W).then((C) => C.text()).then((C) => {
468
+ console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${_}`);
469
+ const V = `https://cloud.myop.dev/consume${i.search}`;
470
+ je(!1), fetch(V).then((C) => C.text()).then((C) => {
471
471
  t.writeHead(200, {
472
472
  "Content-Type": "application/json",
473
473
  "Access-Control-Allow-Origin": "*"
@@ -478,26 +478,26 @@ Sec-WebSocket-Accept: ${p}\r
478
478
  }
479
479
  return;
480
480
  }
481
- if (i === "/events") {
481
+ if (a === "/events") {
482
482
  t.writeHead(200, {
483
483
  "Content-Type": "text/event-stream",
484
484
  "Cache-Control": "no-cache",
485
485
  Connection: "keep-alive",
486
486
  "Access-Control-Allow-Origin": "*"
487
487
  }), D.push(t);
488
- const P = Array.from(b.entries()).map(([R, J]) => ({
488
+ const _ = Array.from(x.entries()).map(([R, J]) => ({
489
489
  id: R,
490
490
  path: J.path,
491
491
  name: J.name
492
492
  }));
493
493
  t.write(`data: ${JSON.stringify({
494
494
  type: "components",
495
- components: P
495
+ components: _
496
496
  })}
497
497
 
498
498
  `), t.write(`data: ${JSON.stringify({
499
499
  type: "origins",
500
- origins: Array.from(V.values())
500
+ origins: Array.from(W.values())
501
501
  })}
502
502
 
503
503
  `), t.write(`data: ${JSON.stringify({
@@ -505,14 +505,14 @@ Sec-WebSocket-Accept: ${p}\r
505
505
  log: q
506
506
  })}
507
507
 
508
- `), s.on("close", () => {
508
+ `), n.on("close", () => {
509
509
  const R = D.indexOf(t);
510
510
  R !== -1 && D.splice(R, 1);
511
511
  });
512
512
  return;
513
513
  }
514
514
  if (l.length === 0) {
515
- t.writeHead(200, { "Content-Type": "text/html" }), t.end(it(u, y, w, I));
515
+ t.writeHead(200, { "Content-Type": "text/html" }), t.end(at(u, y, w, I));
516
516
  return;
517
517
  }
518
518
  if (l[0] !== "view") {
@@ -523,14 +523,14 @@ Sec-WebSocket-Accept: ${p}\r
523
523
  t.writeHead(400, { "Content-Type": "text/plain" }), t.end("Component ID required. Use /view/<componentId>/");
524
524
  return;
525
525
  }
526
- const p = l[1], g = b.get(p);
526
+ const p = l[1], g = x.get(p);
527
527
  if (!g) {
528
528
  t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${p}`);
529
529
  return;
530
530
  }
531
- const M = g.path, _ = l.slice(2), H = _.length === 0 ? "index.html" : _.join("/"), L = o.default.join(M, H);
532
- console.log(`πŸ“₯ Request: ${s.url} -> ${L}`), e.default.readFile(L, (P, R) => {
533
- if (P) {
531
+ const $ = g.path, N = l.slice(2), H = N.length === 0 ? "index.html" : N.join("/"), L = o.default.join($, H);
532
+ console.log(`πŸ“₯ Request: ${n.url} -> ${L}`), e.default.readFile(L, (_, R) => {
533
+ if (_) {
534
534
  console.log(`❌ File not found: ${L}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
535
535
  return;
536
536
  }
@@ -540,55 +540,46 @@ Sec-WebSocket-Accept: ${p}\r
540
540
  "Access-Control-Allow-Origin": "*"
541
541
  }), t.end(R);
542
542
  });
543
- }), ve = () => new Promise((s, t) => {
544
- const r = JSON.stringify({
545
- componentId: x,
546
- distPath: o.default.resolve(N, S),
547
- componentName: E
548
- }), i = {
543
+ }), Se = () => new Promise((n, t) => {
544
+ const i = JSON.stringify({
545
+ componentId: S,
546
+ distPath: o.default.resolve(E, b),
547
+ componentName: k
548
+ }), a = {
549
549
  hostname: "localhost",
550
550
  port: y,
551
551
  path: "/_register",
552
552
  method: "POST",
553
553
  headers: {
554
554
  "Content-Type": "application/json",
555
- "Content-Length": Buffer.byteLength(r)
555
+ "Content-Length": Buffer.byteLength(i)
556
556
  }
557
- }, l = a.default.request(i, (p) => {
557
+ }, l = r.default.request(a, (p) => {
558
558
  let g = "";
559
- p.on("data", (M) => g += M), p.on("end", () => {
560
- p.statusCode === 200 ? s(JSON.parse(g)) : t(new Error(`Registration failed: ${p.statusCode}`));
559
+ p.on("data", ($) => g += $), p.on("end", () => {
560
+ p.statusCode === 200 ? n(JSON.parse(g)) : t(new Error(`Registration failed: ${p.statusCode}`));
561
561
  });
562
562
  });
563
- l.on("error", t), l.write(r), l.end();
564
- }), He = () => new Promise((s, t) => {
565
- const r = JSON.stringify({ componentId: x }), i = {
563
+ l.on("error", t), l.write(i), l.end();
564
+ }), Je = () => new Promise((n, t) => {
565
+ const i = JSON.stringify({ componentId: S }), a = {
566
566
  hostname: "localhost",
567
567
  port: y,
568
568
  path: "/_unregister",
569
569
  method: "POST",
570
570
  headers: {
571
571
  "Content-Type": "application/json",
572
- "Content-Length": Buffer.byteLength(r)
572
+ "Content-Length": Buffer.byteLength(i)
573
573
  }
574
- }, l = a.default.request(i, (p) => {
575
- s();
574
+ }, l = r.default.request(a, (p) => {
575
+ n();
576
576
  });
577
- l.on("error", () => s()), l.write(r), l.end();
578
- }), Le = () => {
579
- if (!h) return;
580
- const s = o.default.join(S, "index.html");
581
- try {
582
- let t = e.default.readFileSync(s, "utf-8");
583
- if (t.includes("<!-- MYOP HMR -->")) {
584
- const i = t.indexOf("<!-- MYOP HMR -->"), l = t.indexOf("<\/script>", i) + 9;
585
- t = t.slice(0, i) + t.slice(l);
586
- }
587
- const r = `
577
+ l.on("error", () => n()), l.write(i), l.end();
578
+ }), Ue = (n) => `
588
579
  <!-- MYOP HMR -->
589
580
  <script>
590
581
  (function() {
591
- const componentId = '${x}';
582
+ const componentId = '${n}';
592
583
  const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
593
584
  let ws;
594
585
  let reconnectAttempts = 0;
@@ -689,57 +680,51 @@ Sec-WebSocket-Accept: ${p}\r
689
680
  connect();
690
681
  })();
691
682
  <\/script>
692
- `;
693
- t.includes("</body>") ? t = t.replace("</body>", `${r}</body>`) : t.includes("</html>") ? t = t.replace("</html>", `${r}</html>`) : t += r, e.default.writeFileSync(s, t, "utf-8"), console.log("πŸ”₯ HMR script injected");
694
- } catch (t) {
695
- console.error("❌ Failed to inject HMR script:", t.message);
696
- }
697
- }, Je = (s) => {
698
- const t = Buffer.from(s), r = t.length;
699
- let i;
700
- return r < 126 ? i = Buffer.concat([
701
- Buffer.from([129, r]),
683
+ `, be = (n, t) => {
684
+ if (!h) return n;
685
+ const i = Ue(t);
686
+ return n.includes("</body>") ? n.replace("</body>", `${i}</body>`) : n.includes("</html>") ? n.replace("</html>", `${i}</html>`) : n + i;
687
+ }, Be = (n) => {
688
+ const t = Buffer.from(n), i = t.length;
689
+ let a;
690
+ return i < 126 ? a = Buffer.concat([
691
+ Buffer.from([129, i]),
702
692
  // FIN + text frame, length
703
693
  t
704
- ]) : r < 65536 ? i = Buffer.concat([
694
+ ]) : i < 65536 ? a = Buffer.concat([
705
695
  Buffer.from([129, 126]),
706
696
  // FIN + text frame, extended length
707
- Buffer.from([r >> 8, r & 255]),
697
+ Buffer.from([i >> 8, i & 255]),
708
698
  // 16-bit length
709
699
  t
710
- ]) : i = Buffer.concat([
700
+ ]) : a = Buffer.concat([
711
701
  Buffer.from([129, 127]),
712
702
  // FIN + text frame, extended length
713
- Buffer.from([0, 0, 0, 0, r >> 24, r >> 16 & 255, r >> 8 & 255, r & 255]),
703
+ Buffer.from([0, 0, 0, 0, i >> 24, i >> 16 & 255, i >> 8 & 255, i & 255]),
714
704
  // 64-bit length
715
705
  t
716
- ]), i;
717
- }, Ue = () => {
706
+ ]), a;
707
+ }, ze = () => {
718
708
  if (!h) return;
719
- const s = U.get(x);
720
- if (!s || s.size === 0)
709
+ const n = U.get(S);
710
+ if (!n || n.size === 0)
721
711
  return;
722
- console.log(`πŸ”₯ Notifying ${s.size} HMR client(s)`);
723
- const t = o.default.join(S, "index.html");
712
+ console.log(`πŸ”₯ Notifying ${n.size} HMR client(s)`);
713
+ const t = o.default.join(b, "index.html");
724
714
  try {
725
- let r = e.default.readFileSync(t, "utf-8");
726
- if (r.includes("<!-- MYOP HMR -->")) {
727
- const p = r.indexOf("<!-- MYOP HMR -->"), g = r.indexOf("<\/script>", p) + 9;
728
- r = r.slice(0, p) + r.slice(g);
729
- }
730
- const i = JSON.stringify({
715
+ const i = e.default.readFileSync(t, "utf-8"), a = be(i, S), l = JSON.stringify({
731
716
  type: "update",
732
- html: r
733
- }), l = Je(i);
734
- s.forEach((p) => {
717
+ html: a
718
+ }), p = Be(l);
719
+ n.forEach((g) => {
735
720
  try {
736
- p.write(l);
721
+ g.write(p);
737
722
  } catch {
738
- s.delete(p);
723
+ n.delete(g);
739
724
  }
740
725
  });
741
- } catch (r) {
742
- console.error("❌ Failed to read HTML for HMR:", r.message);
726
+ } catch (i) {
727
+ console.error("❌ Failed to read HTML for HMR:", i.message);
743
728
  }
744
729
  };
745
730
  let xe = !1;
@@ -749,157 +734,157 @@ Sec-WebSocket-Accept: ${p}\r
749
734
  return;
750
735
  }
751
736
  j = !0, console.log(`
752
- πŸ”¨ Building...`), n("npm run build", (s, t, r) => {
753
- if (j = !1, s) {
754
- const i = s.message + (r || "");
755
- if (!xe && i.includes("ERR_MODULE_NOT_FOUND") && i.includes("esbuild")) {
756
- xe = !0, console.log("πŸ“¦ Missing dependencies detected, running npm install..."), n("npm install", (l, p, g) => {
737
+ πŸ”¨ Building...`), s("npm run build", (n, t, i) => {
738
+ if (j = !1, n) {
739
+ const a = n.message + (i || "");
740
+ if (!xe && a.includes("ERR_MODULE_NOT_FOUND") && a.includes("esbuild")) {
741
+ xe = !0, console.log("πŸ“¦ Missing dependencies detected, running npm install..."), s("npm install", (l, p, g) => {
757
742
  l ? (console.error("❌ Failed to install dependencies:", l.message), g && console.error(g)) : (console.log("βœ… Dependencies installed"), te());
758
743
  });
759
744
  return;
760
745
  }
761
- console.error("❌ Build failed:", s.message), r && console.error(r);
746
+ console.error("❌ Build failed:", n.message), i && console.error(i);
762
747
  } else
763
- console.log("βœ… Build completed"), t && console.log(t), Le(), Ue();
748
+ console.log("βœ… Build completed"), t && console.log(t), ze();
764
749
  v && (v = !1, te());
765
750
  });
766
- }, Se = /* @__PURE__ */ new Set(), be = (s) => {
767
- e.default.readdir(s, { withFileTypes: !0 }, (t, r) => {
768
- t || (r.forEach((i) => {
769
- const l = o.default.join(s, i.name);
770
- if (i.isDirectory())
771
- i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && be(l);
772
- else if (i.isFile()) {
773
- const p = o.default.extname(i.name);
751
+ }, Ce = /* @__PURE__ */ new Set(), $e = (n) => {
752
+ e.default.readdir(n, { withFileTypes: !0 }, (t, i) => {
753
+ t || (i.forEach((a) => {
754
+ const l = o.default.join(n, a.name);
755
+ if (a.isDirectory())
756
+ a.name !== "node_modules" && a.name !== "dist" && !a.name.startsWith(".") && $e(l);
757
+ else if (a.isFile()) {
758
+ const p = o.default.extname(a.name);
774
759
  if (p === ".js" || p === ".css" || p === ".html")
775
760
  try {
776
761
  const g = e.default.readFileSync(l, "utf-8");
777
- k.set(l, g);
762
+ T.set(l, g);
778
763
  } catch {
779
764
  }
780
765
  }
781
- }), Se.has(s) || (Se.add(s), e.default.watch(s, (i, l) => {
766
+ }), Ce.has(n) || (Ce.add(n), e.default.watch(n, (a, l) => {
782
767
  if (!l) return;
783
768
  const p = o.default.extname(l);
784
769
  if (p !== ".js" && p !== ".css" && p !== ".html") return;
785
- const g = o.default.join(s, l);
770
+ const g = o.default.join(n, l);
786
771
  setTimeout(() => {
787
772
  try {
788
- const M = e.default.readFileSync(g, "utf-8"), _ = k.get(g);
789
- M !== _ && (k.set(g, M), console.log(`πŸ“ File changed: ${g}`), te());
773
+ const $ = e.default.readFileSync(g, "utf-8"), N = T.get(g);
774
+ $ !== N && (T.set(g, $), console.log(`πŸ“ File changed: ${g}`), te());
790
775
  } catch {
791
776
  }
792
777
  }, 50);
793
778
  })));
794
779
  });
795
- }, Ce = () => {
780
+ }, Me = () => {
796
781
  console.log(`
797
- πŸ”¨ Component: ${x}`), te(), be(N), console.log("πŸ‘€ Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
782
+ πŸ”¨ Component: ${S}`), te(), $e(E), console.log("πŸ‘€ Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
798
783
  `);
799
- }, Be = () => new Promise((s) => {
784
+ }, We = () => new Promise((n) => {
800
785
  const t = {
801
786
  hostname: "localhost",
802
787
  port: y,
803
788
  path: "/_list",
804
789
  method: "GET",
805
790
  timeout: 1e3
806
- }, r = a.default.request(t, (i) => {
807
- s(!0);
791
+ }, i = r.default.request(t, (a) => {
792
+ n(!0);
808
793
  });
809
- r.on("error", () => s(!1)), r.on("timeout", () => {
810
- r.destroy(), s(!1);
811
- }), r.end();
812
- }), ze = () => new Promise((s) => {
813
- const t = a.default.createServer((r, i) => {
814
- if (i.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
794
+ i.on("error", () => n(!1)), i.on("timeout", () => {
795
+ i.destroy(), n(!1);
796
+ }), i.end();
797
+ }), Ve = () => new Promise((n) => {
798
+ const t = r.default.createServer((i, a) => {
799
+ if (a.setHeader("Content-Type", "application/json"), i.method === "POST" && i.url === "/_register") {
815
800
  let l = "";
816
- r.on("data", (p) => l += p), r.on("end", () => {
801
+ i.on("data", (p) => l += p), i.on("end", () => {
817
802
  try {
818
- const { componentId: p, distPath: g, componentName: M } = JSON.parse(l);
819
- b.set(p, { path: g, name: M || null });
820
- const _ = M ? ` (${M})` : "";
821
- console.log(`βœ… Registered: ${p}${_} -> ${g}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
803
+ const { componentId: p, distPath: g, componentName: $ } = JSON.parse(l);
804
+ x.set(p, { path: g, name: $ || null });
805
+ const N = $ ? ` (${$})` : "";
806
+ console.log(`βœ… Registered: ${p}${N} -> ${g}`), a.writeHead(200), a.end(JSON.stringify({ success: !0, registered: Array.from(x.keys()) }));
822
807
  } catch (p) {
823
- i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
808
+ a.writeHead(400), a.end(JSON.stringify({ error: p.message }));
824
809
  }
825
810
  });
826
- } else if (r.method === "POST" && r.url === "/_unregister") {
811
+ } else if (i.method === "POST" && i.url === "/_unregister") {
827
812
  let l = "";
828
- r.on("data", (p) => l += p), r.on("end", () => {
813
+ i.on("data", (p) => l += p), i.on("end", () => {
829
814
  try {
830
815
  const { componentId: p } = JSON.parse(l);
831
- b.delete(p), console.log(`❌ Unregistered: ${p}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
816
+ x.delete(p), console.log(`❌ Unregistered: ${p}`), a.writeHead(200), a.end(JSON.stringify({ success: !0 }));
832
817
  } catch (p) {
833
- i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
818
+ a.writeHead(400), a.end(JSON.stringify({ error: p.message }));
834
819
  }
835
820
  });
836
- } else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(b.entries()) }))) : (i.writeHead(404), i.end(JSON.stringify({ error: "Not found" })));
821
+ } else i.method === "GET" && i.url === "/_list" ? (a.writeHead(200), a.end(JSON.stringify({ components: Array.from(x.entries()) }))) : (a.writeHead(404), a.end(JSON.stringify({ error: "Not found" })));
837
822
  });
838
823
  t.on("error", () => {
839
- s(!1);
824
+ n(!1);
840
825
  }), t.listen(y, () => {
841
826
  console.log(`
842
827
  πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${y}`), ee.on("error", () => {
843
- t.close(), s(!1);
828
+ t.close(), n(!1);
844
829
  }), ee.listen(u, () => {
845
- console.log(`πŸ“‘ Main server running at http://localhost:${u}`), b.set(x, {
846
- path: o.default.resolve(N, S),
847
- name: E
830
+ console.log(`πŸ“‘ Main server running at http://localhost:${u}`), x.set(S, {
831
+ path: o.default.resolve(E, b),
832
+ name: k
848
833
  });
849
- const r = E ? ` (${E})` : "";
850
- console.log(`βœ… Registered component: ${x}${r}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${x}/`), s(!0);
834
+ const i = k ? ` (${k})` : "";
835
+ console.log(`βœ… Registered component: ${S}${i}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${S}/`), n(!0);
851
836
  });
852
837
  });
853
838
  });
854
839
  let oe;
855
- const $e = () => {
840
+ const Oe = () => {
856
841
  oe = setInterval(async () => {
857
- await Be() || (clearInterval(oe), console.log(`
858
- ⚠️ Server appears to be down, attempting to take over...`), await ze() ? console.log("βœ… Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
842
+ await We() || (clearInterval(oe), console.log(`
843
+ ⚠️ Server appears to be down, attempting to take over...`), await Ve() ? console.log("βœ… Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
859
844
  try {
860
- await ve(), console.log(`βœ… Re-registered component: ${x}`), $e();
861
- } catch (r) {
862
- console.error("❌ Failed to re-register:", r.message);
845
+ await Se(), console.log(`βœ… Re-registered component: ${S}`), Oe();
846
+ } catch (i) {
847
+ console.error("❌ Failed to re-register:", i.message);
863
848
  }
864
849
  }, 2e3)));
865
850
  }, 3e3);
866
- }, Me = async () => {
851
+ }, Ie = async () => {
867
852
  console.log(`
868
853
 
869
- πŸ›‘ Shutting down...`), oe && clearInterval(oe), await He(), process.exit(0);
854
+ πŸ›‘ Shutting down...`), oe && clearInterval(oe), await Je(), process.exit(0);
870
855
  };
871
- process.on("SIGINT", Me), process.on("SIGTERM", Me), de.on("error", async (s) => {
872
- if (s.code === "EADDRINUSE") {
856
+ process.on("SIGINT", Ie), process.on("SIGTERM", Ie), de.on("error", async (n) => {
857
+ if (n.code === "EADDRINUSE") {
873
858
  console.log(`
874
859
  πŸ”— Connecting to existing dev server...`);
875
860
  try {
876
- x = await $();
877
- const t = await ve();
878
- console.log(`βœ… Registered component: ${x}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${x}/`), console.log(`πŸ“‹ All registered components: ${t.registered.join(", ")}`), Ce(), $e();
861
+ S = await M();
862
+ const t = await Se();
863
+ console.log(`βœ… Registered component: ${S}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${S}/`), console.log(`πŸ“‹ All registered components: ${t.registered.join(", ")}`), Me(), Oe();
879
864
  } catch (t) {
880
865
  console.error("❌ Failed to register component:", t.message), process.exit(1);
881
866
  }
882
867
  } else
883
- console.error("❌ Management server error:", s.message), process.exit(1);
884
- }), de.on("upgrade", De), de.listen(y, async () => {
868
+ console.error("❌ Management server error:", n.message), process.exit(1);
869
+ }), de.on("upgrade", Le), de.listen(y, async () => {
885
870
  console.log(`
886
- πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${y}`), ee.on("error", (s) => {
887
- console.error("❌ Main server error:", s.message), process.exit(1);
871
+ πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${y}`), ee.on("error", (n) => {
872
+ console.error("❌ Main server error:", n.message), process.exit(1);
888
873
  }), ee.listen(u, async () => {
889
- console.log(`πŸ“‘ Main server running at http://localhost:${u}`), (x === "DEV" || x === "NEW") && (x = "DEV1"), b.set(x, {
890
- path: o.default.resolve(N, S),
891
- name: E
874
+ console.log(`πŸ“‘ Main server running at http://localhost:${u}`), (S === "DEV" || S === "NEW") && (S = "DEV1"), x.set(S, {
875
+ path: o.default.resolve(E, b),
876
+ name: k
892
877
  });
893
- const s = E ? ` (${E})` : "";
894
- console.log(`βœ… Registered component: ${x}${s}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${x}/`), Ce();
878
+ const n = k ? ` (${k})` : "";
879
+ console.log(`βœ… Registered component: ${S}${n}`), console.log(`πŸ“‘ Access at: http://localhost:${u}/view/${S}/`), Me();
895
880
  });
896
881
  });
897
882
  }
898
- const ue = Z.join(Xe.homedir(), ".myop"), Q = Z.join(ue, "credentials.json");
899
- function at() {
900
- A.existsSync(ue) || A.mkdirSync(ue, { recursive: !0, mode: 448 });
883
+ const fe = Z.join(Qe.homedir(), ".myop"), Q = Z.join(fe, "credentials.json");
884
+ function ct() {
885
+ A.existsSync(fe) || A.mkdirSync(fe, { recursive: !0, mode: 448 });
901
886
  }
902
- function he() {
887
+ function ye() {
903
888
  try {
904
889
  if (!A.existsSync(Q))
905
890
  return null;
@@ -909,8 +894,8 @@ function he() {
909
894
  return console.info("Failed to read credentials:", e.message), null;
910
895
  }
911
896
  }
912
- function Te(e) {
913
- at();
897
+ function Fe(e) {
898
+ ct();
914
899
  const o = {
915
900
  ...e,
916
901
  savedAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -920,40 +905,40 @@ function Te(e) {
920
905
  // Read/write for owner only
921
906
  });
922
907
  }
923
- function Re() {
908
+ function Ae() {
924
909
  try {
925
910
  return A.existsSync(Q) && A.unlinkSync(Q), !0;
926
911
  } catch (e) {
927
912
  return console.error("Failed to clear credentials:", e.message), !1;
928
913
  }
929
914
  }
930
- function ct(e) {
915
+ function lt(e) {
931
916
  if (!e || !e.expiresAt)
932
917
  return !0;
933
- const o = 5 * 60 * 1e3, n = new Date(e.expiresAt).getTime();
934
- return Date.now() > n - o;
918
+ const o = 5 * 60 * 1e3, s = new Date(e.expiresAt).getTime();
919
+ return Date.now() > s - o;
935
920
  }
936
- function ye() {
937
- const e = he();
921
+ function we() {
922
+ const e = ye();
938
923
  return e ? {
939
924
  email: e.userEmail,
940
925
  userId: e.userId
941
926
  } : null;
942
927
  }
943
- const Y = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", ie = 19284, we = `http://localhost:${ie}/callback`, lt = "myop-cli";
944
- function dt() {
945
- return fe.randomBytes(32).toString("base64url");
928
+ const Y = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", ie = 19284, ve = `http://localhost:${ie}/callback`, dt = "myop-cli";
929
+ function pt() {
930
+ return ge.randomBytes(32).toString("base64url");
946
931
  }
947
- function pt(e) {
948
- return fe.createHash("sha256").update(e).digest("base64url");
932
+ function mt(e) {
933
+ return ge.createHash("sha256").update(e).digest("base64url");
949
934
  }
950
- async function mt() {
935
+ async function ut() {
951
936
  const e = await fetch(`${Y}/oauth/register`, {
952
937
  method: "POST",
953
938
  headers: { "Content-Type": "application/json" },
954
939
  body: JSON.stringify({
955
- client_name: lt,
956
- redirect_uris: [we],
940
+ client_name: dt,
941
+ redirect_uris: [ve],
957
942
  grant_types: ["authorization_code", "refresh_token"],
958
943
  response_types: ["code"]
959
944
  })
@@ -964,7 +949,7 @@ async function mt() {
964
949
  }
965
950
  return e.json();
966
951
  }
967
- function se(e, o, n, a = null) {
952
+ function se(e, o, s, r = null) {
968
953
  const f = {
969
954
  success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
970
955
  <circle cx="12" cy="12" r="10"/>
@@ -1116,8 +1101,8 @@ function se(e, o, n, a = null) {
1116
1101
  ${f[e] || f.error}
1117
1102
  </div>
1118
1103
  <h1>${o}</h1>
1119
- <p class="message">${n}</p>
1120
- ${a ? `<div class="details"><code>Error:</code> ${a}</div>` : ""}
1104
+ <p class="message">${s}</p>
1105
+ ${r ? `<div class="details"><code>Error:</code> ${r}</div>` : ""}
1121
1106
  <div class="hint">
1122
1107
  <span>Press</span>
1123
1108
  <kbd>⌘</kbd><kbd>W</kbd>
@@ -1130,10 +1115,10 @@ function se(e, o, n, a = null) {
1130
1115
  </body>
1131
1116
  </html>`;
1132
1117
  }
1133
- function ut(e) {
1134
- return new Promise((o, n) => {
1135
- const a = Ye.createServer((f, c) => {
1136
- const m = new je(f.url, `http://localhost:${ie}`);
1118
+ function ft(e) {
1119
+ return new Promise((o, s) => {
1120
+ const r = Ke.createServer((f, c) => {
1121
+ const m = new Ne(f.url, `http://localhost:${ie}`);
1137
1122
  if (m.pathname === "/callback") {
1138
1123
  const w = m.searchParams.get("code"), I = m.searchParams.get("state"), u = m.searchParams.get("error");
1139
1124
  if (u) {
@@ -1142,7 +1127,7 @@ function ut(e) {
1142
1127
  "Authentication Failed",
1143
1128
  "Unable to complete the authentication process.",
1144
1129
  u
1145
- )), a.close(), n(new Error(`OAuth error: ${u}`));
1130
+ )), r.close(), s(new Error(`OAuth error: ${u}`));
1146
1131
  return;
1147
1132
  }
1148
1133
  if (I !== e) {
@@ -1151,7 +1136,7 @@ function ut(e) {
1151
1136
  "Security Error",
1152
1137
  "State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
1153
1138
  "state_mismatch"
1154
- )), a.close(), n(new Error("State mismatch"));
1139
+ )), r.close(), s(new Error("State mismatch"));
1155
1140
  return;
1156
1141
  }
1157
1142
  if (!w) {
@@ -1160,59 +1145,59 @@ function ut(e) {
1160
1145
  "Missing Authorization Code",
1161
1146
  "No authorization code was received from the server.",
1162
1147
  "missing_code"
1163
- )), a.close(), n(new Error("No authorization code"));
1148
+ )), r.close(), s(new Error("No authorization code"));
1164
1149
  return;
1165
1150
  }
1166
1151
  c.writeHead(200, { "Content-Type": "text/html" }), c.end(se(
1167
1152
  "success",
1168
1153
  "Authentication Successful",
1169
1154
  "You have been authenticated successfully. Return to the terminal to continue."
1170
- )), a.close(), o(w);
1155
+ )), r.close(), o(w);
1171
1156
  } else
1172
1157
  c.writeHead(404), c.end("Not found");
1173
1158
  });
1174
- a.listen(ie, () => {
1159
+ r.listen(ie, () => {
1175
1160
  console.info(`OAuth callback server listening on port ${ie}`);
1176
1161
  }), setTimeout(() => {
1177
- a.close(), n(new Error("Authentication timed out"));
1162
+ r.close(), s(new Error("Authentication timed out"));
1178
1163
  }, 5 * 60 * 1e3);
1179
1164
  });
1180
1165
  }
1181
- async function ft(e, o, n) {
1182
- const a = await fetch(`${Y}/oauth/token`, {
1166
+ async function gt(e, o, s) {
1167
+ const r = await fetch(`${Y}/oauth/token`, {
1183
1168
  method: "POST",
1184
1169
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1185
- body: new _e({
1170
+ body: new ke({
1186
1171
  grant_type: "authorization_code",
1187
1172
  code: e,
1188
1173
  client_id: o,
1189
- redirect_uri: we,
1190
- code_verifier: n
1174
+ redirect_uri: ve,
1175
+ code_verifier: s
1191
1176
  })
1192
1177
  });
1193
- if (!a.ok) {
1194
- const f = await a.json();
1178
+ if (!r.ok) {
1179
+ const f = await r.json();
1195
1180
  throw new Error(f.error_description || f.error || "Token exchange failed");
1196
1181
  }
1197
- return a.json();
1182
+ return r.json();
1198
1183
  }
1199
- async function gt(e, o) {
1200
- const n = await fetch(`${Y}/oauth/token`, {
1184
+ async function ht(e, o) {
1185
+ const s = await fetch(`${Y}/oauth/token`, {
1201
1186
  method: "POST",
1202
1187
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1203
- body: new _e({
1188
+ body: new ke({
1204
1189
  grant_type: "refresh_token",
1205
1190
  refresh_token: e,
1206
1191
  client_id: o
1207
1192
  })
1208
1193
  });
1209
- if (!n.ok) {
1210
- const a = await n.json();
1211
- throw new Error(a.error_description || a.error || "Token refresh failed");
1194
+ if (!s.ok) {
1195
+ const r = await s.json();
1196
+ throw new Error(r.error_description || r.error || "Token refresh failed");
1212
1197
  }
1213
- return n.json();
1198
+ return s.json();
1214
1199
  }
1215
- async function ht(e) {
1200
+ async function yt(e) {
1216
1201
  var f, c, m;
1217
1202
  const o = await fetch(`${Y}/mcp`, {
1218
1203
  method: "POST",
@@ -1232,81 +1217,81 @@ async function ht(e) {
1232
1217
  });
1233
1218
  if (!o.ok)
1234
1219
  throw new Error("Failed to get user info");
1235
- const n = await o.json();
1236
- if (n.error)
1237
- throw new Error(n.error.message);
1238
- const a = (m = (c = (f = n.result) == null ? void 0 : f.content) == null ? void 0 : c[0]) == null ? void 0 : m.text;
1239
- if (a)
1240
- return JSON.parse(a);
1220
+ const s = await o.json();
1221
+ if (s.error)
1222
+ throw new Error(s.error.message);
1223
+ const r = (m = (c = (f = s.result) == null ? void 0 : f.content) == null ? void 0 : c[0]) == null ? void 0 : m.text;
1224
+ if (r)
1225
+ return JSON.parse(r);
1241
1226
  throw new Error("Invalid response from whoami");
1242
1227
  }
1243
1228
  async function X() {
1244
1229
  const e = F("Starting authentication...").start();
1245
1230
  try {
1246
1231
  e.text = "Registering OAuth client...";
1247
- const n = (await mt()).client_id, a = dt(), f = pt(a), c = fe.randomBytes(16).toString("hex");
1232
+ const s = (await ut()).client_id, r = pt(), f = mt(r), c = ge.randomBytes(16).toString("hex");
1248
1233
  e.text = "Waiting for authorization...";
1249
- const m = ut(c), w = new je(`${Y}/oauth/authorize`);
1250
- w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", n), w.searchParams.set("redirect_uri", we), w.searchParams.set("code_challenge", f), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", c), e.stop(), console.log(`
1234
+ const m = ft(c), w = new Ne(`${Y}/oauth/authorize`);
1235
+ w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", s), w.searchParams.set("redirect_uri", ve), w.searchParams.set("code_challenge", f), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", c), e.stop(), console.log(`
1251
1236
  🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
1252
- `), await Ke(w.toString());
1237
+ `), await Xe(w.toString());
1253
1238
  const I = await m;
1254
1239
  e.start("Exchanging authorization code...");
1255
- const u = await ft(I, n, a);
1240
+ const u = await gt(I, s, r);
1256
1241
  e.text = "Getting user info...";
1257
- const y = await ht(u.access_token), S = {
1242
+ const y = await yt(u.access_token), b = {
1258
1243
  accessToken: u.access_token,
1259
1244
  refreshToken: u.refresh_token,
1260
1245
  expiresAt: new Date(Date.now() + u.expires_in * 1e3).toISOString(),
1261
- clientId: n,
1246
+ clientId: s,
1262
1247
  userId: y.userId,
1263
1248
  userEmail: y.email
1264
1249
  };
1265
- return Te(S), e.succeed(`Authenticated as ${y.email}`), S;
1250
+ return Fe(b), e.succeed(`Authenticated as ${y.email}`), b;
1266
1251
  } catch (o) {
1267
1252
  throw e.fail(`Authentication failed: ${o.message}`), o;
1268
1253
  }
1269
1254
  }
1270
- async function Fe() {
1271
- const e = he();
1255
+ async function De() {
1256
+ const e = ye();
1272
1257
  if (!e) {
1273
1258
  console.log("Not currently logged in.");
1274
1259
  return;
1275
1260
  }
1276
- Re(), console.log(`βœ… Logged out (was: ${e.userEmail})`);
1261
+ Ae(), console.log(`βœ… Logged out (was: ${e.userEmail})`);
1277
1262
  }
1278
- async function yt() {
1279
- let e = he();
1263
+ async function wt() {
1264
+ let e = ye();
1280
1265
  if (!e)
1281
1266
  return console.log(`Not logged in. Starting authentication...
1282
1267
  `), await X();
1283
- if (!ct(e))
1268
+ if (!lt(e))
1284
1269
  return e;
1285
1270
  if (e.refreshToken) {
1286
1271
  const o = F("Refreshing access token...").start();
1287
1272
  try {
1288
- const n = await gt(
1273
+ const s = await ht(
1289
1274
  e.refreshToken,
1290
1275
  e.clientId
1291
1276
  );
1292
1277
  return e = {
1293
1278
  ...e,
1294
- accessToken: n.access_token,
1295
- refreshToken: n.refresh_token,
1296
- expiresAt: new Date(Date.now() + n.expires_in * 1e3).toISOString()
1297
- }, Te(e), o.succeed("Token refreshed"), e;
1279
+ accessToken: s.access_token,
1280
+ refreshToken: s.refresh_token,
1281
+ expiresAt: new Date(Date.now() + s.expires_in * 1e3).toISOString()
1282
+ }, Fe(e), o.succeed("Token refreshed"), e;
1298
1283
  } catch {
1299
- return o.warn("Token refresh failed, please log in again"), Re(), await X();
1284
+ return o.warn("Token refresh failed, please log in again"), Ae(), await X();
1300
1285
  }
1301
1286
  }
1302
1287
  return console.log(`Session expired. Please log in again.
1303
1288
  `), await X();
1304
1289
  }
1305
- function wt() {
1290
+ function vt() {
1306
1291
  return Y;
1307
1292
  }
1308
1293
  const ae = "@myop/cli";
1309
- async function vt() {
1294
+ async function St() {
1310
1295
  try {
1311
1296
  const e = await fetch(`https://registry.npmjs.org/${ae}/latest`);
1312
1297
  return e.ok ? (await e.json()).version : null;
@@ -1314,28 +1299,28 @@ async function vt() {
1314
1299
  return null;
1315
1300
  }
1316
1301
  }
1317
- function xt(e, o) {
1318
- const n = e.split(".").map(Number), a = o.split(".").map(Number);
1319
- for (let f = 0; f < Math.max(n.length, a.length); f++) {
1320
- const c = n[f] || 0, m = a[f] || 0;
1302
+ function bt(e, o) {
1303
+ const s = e.split(".").map(Number), r = o.split(".").map(Number);
1304
+ for (let f = 0; f < Math.max(s.length, r.length); f++) {
1305
+ const c = s[f] || 0, m = r[f] || 0;
1321
1306
  if (c > m) return 1;
1322
1307
  if (c < m) return -1;
1323
1308
  }
1324
1309
  return 0;
1325
1310
  }
1326
- async function St(e) {
1311
+ async function xt(e) {
1327
1312
  const o = F({
1328
1313
  text: "Checking for updates...",
1329
1314
  color: "cyan"
1330
- }).start(), n = await vt();
1331
- if (o.stop(), !n || xt(n, e) <= 0)
1315
+ }).start(), s = await St();
1316
+ if (o.stop(), !s || bt(s, e) <= 0)
1332
1317
  return !1;
1333
1318
  console.log(`
1334
- πŸ“¦ New version available: ${e} β†’ ${n}
1319
+ πŸ“¦ New version available: ${e} β†’ ${s}
1335
1320
  `);
1336
- let a;
1321
+ let r;
1337
1322
  try {
1338
- a = await Ie({
1323
+ r = await _e({
1339
1324
  message: "Would you like to update now?",
1340
1325
  choices: [
1341
1326
  { name: "Yes, update now", value: !0 },
@@ -1348,15 +1333,15 @@ async function St(e) {
1348
1333
  πŸ‘‹ Goodbye!
1349
1334
  `), process.exit(0)), f;
1350
1335
  }
1351
- if (a) {
1336
+ if (r) {
1352
1337
  const f = F({
1353
- text: `Updating ${ae} to v${n}...`,
1338
+ text: `Updating ${ae} to v${s}...`,
1354
1339
  color: "green"
1355
1340
  }).start();
1356
1341
  try {
1357
- return re(`npm install -g ${ae}@latest`, { stdio: "pipe" }), f.succeed(`Updated to v${n}`), console.log(`
1342
+ return re(`npm install -g ${ae}@latest`, { stdio: "pipe" }), f.succeed(`Updated to v${s}`), console.log(`
1358
1343
  πŸ”„ Restarting with new version...
1359
- `), Ge("myop", process.argv.slice(2), {
1344
+ `), Ye("myop", process.argv.slice(2), {
1360
1345
  stdio: "inherit",
1361
1346
  shell: !0
1362
1347
  }).on("close", (m) => {
@@ -1370,7 +1355,7 @@ You can manually update by running: npm install -g ${ae}@latest
1370
1355
  }
1371
1356
  return !1;
1372
1357
  }
1373
- const bt = (e) => new Promise((o) => setTimeout(o, e));
1358
+ const Ct = (e) => new Promise((o) => setTimeout(o, e));
1374
1359
  d.executionPath = process.cwd();
1375
1360
  const le = (e = !1) => {
1376
1361
  const o = d.program.getOptionValue("verbose");
@@ -1380,43 +1365,43 @@ const le = (e = !1) => {
1380
1365
  verbose: o
1381
1366
  };
1382
1367
  try {
1383
- return d.myopConfig = Ze(d.options.configPath), { configFound: !0 };
1384
- } catch (n) {
1368
+ return d.myopConfig = qe(d.options.configPath), { configFound: !0 };
1369
+ } catch (s) {
1385
1370
  if (e) {
1386
1371
  console.info(`
1387
1372
  ⚠️ failed read config file from ${d.options.configPath}, trying to create new one`);
1388
1373
  try {
1389
- const a = {
1374
+ const r = {
1390
1375
  author: "@myop-cli",
1391
1376
  flows: []
1392
1377
  };
1393
- return ge(d.options.configPath, a), d.myopConfig = a, { configFound: !0 };
1378
+ return he(d.options.configPath, r), d.myopConfig = r, { configFound: !0 };
1394
1379
  } catch {
1395
- return console.info("Error details :", n), { configFound: !1, error: n };
1380
+ return console.info("Error details :", s), { configFound: !1, error: s };
1396
1381
  }
1397
1382
  } else
1398
- return console.info("Error details :", n), { configFound: !1, error: n };
1383
+ return console.info("Error details :", s), { configFound: !1, error: s };
1399
1384
  }
1400
1385
  };
1401
1386
  [
1402
- new me(),
1403
- ...rt
1387
+ new ue(),
1388
+ ...it
1404
1389
  ];
1405
- const Ct = "0.1.17";
1406
- d.program = new We();
1407
- d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(Ct);
1390
+ const $t = "0.1.19";
1391
+ d.program = new Ge();
1392
+ d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version($t);
1408
1393
  d.program.addOption(new ce("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
1409
1394
  d.program.addOption(new ce("-h, --help", "Show helpful information"));
1410
1395
  d.program.addOption(new ce("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
1411
1396
  d.program.addOption(new ce("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
1412
1397
  d.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, o) => {
1413
- le(!0), console.info("adding ", e, o, d.options.configPath), e === "flow" && Ee._action(o), process.exit();
1398
+ le(!0), console.info("adding ", e, o, d.options.configPath), e === "flow" && Te._action(o), process.exit();
1414
1399
  });
1415
1400
  d.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, o) => {
1416
- le(), console.info("removing ", e, o, d.options.configPath), e === "flow" && Ne._action(o), process.exit();
1401
+ le(), console.info("removing ", e, o, d.options.configPath), e === "flow" && Pe._action(o), process.exit();
1417
1402
  });
1418
1403
  d.program.command("install").description("Install Myop assets").action(async () => {
1419
- le(), await Pe.action();
1404
+ le(), await Ee.action();
1420
1405
  });
1421
1406
  d.program.command("login").description("Authenticate with Myop platform").action(async () => {
1422
1407
  try {
@@ -1427,22 +1412,22 @@ d.program.command("login").description("Authenticate with Myop platform").action
1427
1412
  process.exit(0);
1428
1413
  });
1429
1414
  d.program.command("logout").description("Clear stored credentials").action(async () => {
1430
- await Fe(), process.exit(0);
1415
+ await De(), process.exit(0);
1431
1416
  });
1432
1417
  d.program.command("whoami").description("Show current authenticated user").action(async () => {
1433
- const e = ye();
1418
+ const e = we();
1434
1419
  e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
1435
1420
  });
1436
1421
  d.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
1437
- var j, v, k, z, x, E;
1438
- const o = d.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"), f = await import("path");
1422
+ var j, v, T, z, S, k;
1423
+ const o = d.program.getOptionValue("config") || "./myop.config.json", s = await import("fs"), { execSync: r } = await import("child_process"), f = await import("path");
1439
1424
  let c = {};
1440
- if (n.existsSync(o))
1425
+ if (s.existsSync(o))
1441
1426
  try {
1442
- const h = n.readFileSync(o, "utf-8");
1427
+ const h = s.readFileSync(o, "utf-8");
1443
1428
  c = JSON.parse(h);
1444
- const $ = c.name || c.componentName;
1445
- console.log(`πŸ“‹ Found config: ${$ || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1429
+ const M = c.name || c.componentName;
1430
+ console.log(`πŸ“‹ Found config: ${M || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1446
1431
  } catch (h) {
1447
1432
  console.error(`⚠️ Failed to parse ${o}:`, h.message);
1448
1433
  }
@@ -1451,20 +1436,20 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1451
1436
  if (!e.skipBuild) {
1452
1437
  const h = F("Building project...").start();
1453
1438
  try {
1454
- a("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
1455
- } catch ($) {
1456
- h.fail("Build failed"), console.error($.message), process.exit(1);
1439
+ r("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
1440
+ } catch (M) {
1441
+ h.fail("Build failed"), console.error(M.message), process.exit(1);
1457
1442
  }
1458
1443
  }
1459
1444
  const m = "./dist/index.html";
1460
- n.existsSync(m) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
1445
+ s.existsSync(m) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
1461
1446
  let w;
1462
1447
  try {
1463
- w = await yt();
1448
+ w = await wt();
1464
1449
  } catch (h) {
1465
1450
  console.error("❌ Authentication failed:", h.message), process.exit(1);
1466
1451
  }
1467
- const I = wt();
1452
+ const I = vt();
1468
1453
  let u = F("Requesting upload URL...").start(), y;
1469
1454
  try {
1470
1455
  const h = await fetch(`${I}/mcp`, {
@@ -1489,11 +1474,11 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1489
1474
  });
1490
1475
  if (!h.ok)
1491
1476
  throw new Error(`Server returned ${h.status}`);
1492
- const $ = await h.json();
1493
- if ($.error)
1494
- throw new Error($.error.message);
1495
- const N = (k = (v = (j = $.result) == null ? void 0 : j.content) == null ? void 0 : v[0]) == null ? void 0 : k.text;
1496
- if (y = JSON.parse(N), !y.success)
1477
+ const M = await h.json();
1478
+ if (M.error)
1479
+ throw new Error(M.error.message);
1480
+ const E = (T = (v = (j = M.result) == null ? void 0 : j.content) == null ? void 0 : v[0]) == null ? void 0 : T.text;
1481
+ if (y = JSON.parse(E), !y.success)
1497
1482
  throw new Error(y.error);
1498
1483
  u.succeed("Upload URL obtained");
1499
1484
  } catch (h) {
@@ -1501,20 +1486,20 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1501
1486
  }
1502
1487
  u = F("Uploading component...").start();
1503
1488
  try {
1504
- const h = n.readFileSync(m, "utf-8");
1505
- let $;
1506
- const N = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1507
- if (N)
1508
- $ = N[1];
1489
+ const h = s.readFileSync(m, "utf-8");
1490
+ let M;
1491
+ const E = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1492
+ if (E)
1493
+ M = E[1];
1509
1494
  else {
1510
- const b = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1511
- if (b)
1512
- $ = b[1];
1495
+ const x = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1496
+ if (x)
1497
+ M = x[1];
1513
1498
  else
1514
1499
  throw new Error("Could not parse presigned URL from: " + y.curlCommand);
1515
1500
  }
1516
- console.info("Uploading to:", $.substring(0, 100) + "...");
1517
- const K = await fetch($, {
1501
+ console.info("Uploading to:", M.substring(0, 100) + "...");
1502
+ const K = await fetch(M, {
1518
1503
  method: "PUT",
1519
1504
  headers: {
1520
1505
  "Content-Type": "text/html"
@@ -1522,15 +1507,15 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1522
1507
  body: h
1523
1508
  });
1524
1509
  if (!K.ok) {
1525
- const b = await K.text();
1526
- throw new Error(`Upload failed with status ${K.status}: ${b}`);
1510
+ const x = await K.text();
1511
+ throw new Error(`Upload failed with status ${K.status}: ${x}`);
1527
1512
  }
1528
1513
  u.succeed("Component uploaded");
1529
1514
  } catch (h) {
1530
1515
  u.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
1531
1516
  }
1532
1517
  u = F("Confirming upload...").start();
1533
- let S;
1518
+ let b;
1534
1519
  try {
1535
1520
  const h = await fetch(`${I}/mcp`, {
1536
1521
  method: "POST",
@@ -1552,31 +1537,31 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1552
1537
  });
1553
1538
  if (!h.ok)
1554
1539
  throw new Error(`Server returned ${h.status}`);
1555
- const $ = await h.json();
1556
- if ($.error)
1557
- throw new Error($.error.message);
1558
- const N = (E = (x = (z = $.result) == null ? void 0 : z.content) == null ? void 0 : x[0]) == null ? void 0 : E.text;
1559
- if (S = JSON.parse(N), !S.success)
1560
- throw new Error(S.error);
1540
+ const M = await h.json();
1541
+ if (M.error)
1542
+ throw new Error(M.error.message);
1543
+ const E = (k = (S = (z = M.result) == null ? void 0 : z.content) == null ? void 0 : S[0]) == null ? void 0 : k.text;
1544
+ if (b = JSON.parse(E), !b.success)
1545
+ throw new Error(b.error);
1561
1546
  u.succeed("Upload confirmed");
1562
1547
  } catch (h) {
1563
1548
  u.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
1564
1549
  }
1565
- if (S.isNewComponent || !c.componentId) {
1566
- c.componentId = S.componentId, c.organization = S.orgId, c.name || (c.name = S.componentName);
1550
+ if (b.isNewComponent || !c.componentId) {
1551
+ c.componentId = b.componentId, c.organization = b.orgId, c.name || (c.name = b.componentName);
1567
1552
  try {
1568
- n.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
1553
+ s.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
1569
1554
  πŸ“ Updated ${o} with componentId`);
1570
1555
  } catch (h) {
1571
1556
  console.log(`
1572
- ⚠️ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${S.componentId}" manually`);
1557
+ ⚠️ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
1573
1558
  }
1574
1559
  }
1575
1560
  console.log(`
1576
- βœ… Sync completed successfully!`), console.log(` Component: ${S.componentName}`), console.log(` Dashboard: ${S.dashboardUrl}`), process.exit(0);
1561
+ βœ… Sync completed successfully!`), console.log(` Component: ${b.componentName}`), console.log(` Dashboard: ${b.dashboardUrl}`), process.exit(0);
1577
1562
  });
1578
- d.program.command("dev").description("Start development server with file watching").action(ke);
1579
- const $t = () => {
1563
+ d.program.command("dev").description("Start development server with file watching").action(Re);
1564
+ const Mt = () => {
1580
1565
  try {
1581
1566
  re("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1582
1567
  } catch {
@@ -1599,21 +1584,21 @@ const $t = () => {
1599
1584
  deletions: 0
1600
1585
  };
1601
1586
  const o = e.split(`
1602
- `), n = o[o.length - 1], a = n.match(/(\d+) insertion/), f = n.match(/(\d+) deletion/), c = n.match(/(\d+) file/);
1587
+ `), s = o[o.length - 1], r = s.match(/(\d+) insertion/), f = s.match(/(\d+) deletion/), c = s.match(/(\d+) file/);
1603
1588
  return {
1604
1589
  files: c ? parseInt(c[1]) : 0,
1605
- insertions: a ? parseInt(a[1]) : 0,
1590
+ insertions: r ? parseInt(r[1]) : 0,
1606
1591
  deletions: f ? parseInt(f[1]) : 0
1607
1592
  };
1608
1593
  } catch {
1609
1594
  return null;
1610
1595
  }
1611
1596
  }, B = async (e = !1, o = !1) => {
1612
- var y, S, j;
1613
- const n = ye(), a = !!(n != null && n.email), f = ((y = d.myopConfig) == null ? void 0 : y.name) || ((S = d.myopConfig) == null ? void 0 : S.componentName), c = (j = d.myopConfig) == null ? void 0 : j.componentId, m = $t();
1597
+ var y, b, j;
1598
+ const s = we(), r = !!(s != null && s.email), f = ((y = d.myopConfig) == null ? void 0 : y.name) || ((b = d.myopConfig) == null ? void 0 : b.componentName), c = (j = d.myopConfig) == null ? void 0 : j.componentId, m = Mt();
1614
1599
  console.log(`
1615
1600
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”`), console.log("β”‚ β”‚"), console.log("β”‚ Welcome to Myop CLI - Remote UI Made Easy β”‚"), console.log("β”‚ β”‚"), console.log(`β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1616
- `), e && f ? (console.log(` Component: ${f}`), c ? (console.log(` ID: ${c}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${c}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${a ? n.email : "Not logged in"}`), m != null && m.gitNotInstalled ? (console.log(" Changes: Git not installed"), console.log(" Install: https://git-scm.com/downloads"), console.log(" Mac: brew install git | Windows: https://gitforwindows.org")) : m != null && m.notARepo ? console.log(" Changes: Not a git repository") : m && (m.insertions > 0 || m.deletions > 0) ? console.log(` Changes: ${m.files} file${m.files !== 1 ? "s" : ""} | \x1B[32m+${m.insertions}\x1B[0m \x1B[31m-${m.deletions}\x1B[0m`) : m && console.log(" Changes: No uncommitted changes"), console.log("");
1601
+ `), e && f ? (console.log(` Component: ${f}`), c ? (console.log(` ID: ${c}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${c}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${r ? s.email : "Not logged in"}`), m != null && m.gitNotInstalled ? (console.log(" Changes: Git not installed"), console.log(" Install: https://git-scm.com/downloads"), console.log(" Mac: brew install git | Windows: https://gitforwindows.org")) : m != null && m.notARepo ? console.log(" Changes: Not a git repository") : m && (m.insertions > 0 || m.deletions > 0) ? console.log(` Changes: ${m.files} file${m.files !== 1 ? "s" : ""} | \x1B[32m+${m.insertions}\x1B[0m \x1B[31m-${m.deletions}\x1B[0m`) : m && console.log(" Changes: No uncommitted changes"), console.log("");
1617
1602
  const I = [
1618
1603
  {
1619
1604
  emoji: "πŸš€",
@@ -1627,7 +1612,7 @@ const $t = () => {
1627
1612
  label: f ? `Push "${f}"` : "Push component",
1628
1613
  value: "sync",
1629
1614
  help: "Builds project & uploads dist/index.html to Myop",
1630
- disabled: e ? a ? !1 : "(login required)" : "(no config file)"
1615
+ disabled: e ? r ? !1 : "(login required)" : "(no config file)"
1631
1616
  },
1632
1617
  {
1633
1618
  emoji: "πŸ› οΈ ",
@@ -1643,18 +1628,18 @@ const $t = () => {
1643
1628
  disabled: v.disabled
1644
1629
  }));
1645
1630
  I.push(
1646
- new me(),
1631
+ new ue(),
1647
1632
  {
1648
- name: o && a ? `πŸ”“ Logout (${n.email})
1649
- Clears stored credentials from this machine` : o && !a ? `πŸ” Login to Myop
1650
- Opens browser to authenticate with Myop` : a ? `πŸ”“ Logout (${n.email})` : "πŸ” Login to Myop",
1651
- value: a ? "logout" : "login"
1633
+ name: o && r ? `πŸ”“ Logout (${s.email})
1634
+ Clears stored credentials from this machine` : o && !r ? `πŸ” Login to Myop
1635
+ Opens browser to authenticate with Myop` : r ? `πŸ”“ Logout (${s.email})` : "πŸ” Login to Myop",
1636
+ value: r ? "logout" : "login"
1652
1637
  },
1653
1638
  {
1654
1639
  name: o ? "πŸ“– Hide help" : "πŸ“– Show help",
1655
1640
  value: "help"
1656
1641
  },
1657
- new me(),
1642
+ new ue(),
1658
1643
  {
1659
1644
  name: "πŸ‘‹ Exit",
1660
1645
  value: "exit"
@@ -1662,7 +1647,7 @@ const $t = () => {
1662
1647
  );
1663
1648
  let u;
1664
1649
  try {
1665
- u = await Ie({
1650
+ u = await _e({
1666
1651
  message: "What would you like to do?",
1667
1652
  choices: I
1668
1653
  });
@@ -1674,7 +1659,7 @@ const $t = () => {
1674
1659
  }
1675
1660
  switch (u) {
1676
1661
  case "init":
1677
- await Mt();
1662
+ await Ot();
1678
1663
  break;
1679
1664
  case "sync":
1680
1665
  console.log(`
@@ -1688,18 +1673,18 @@ Running sync...
1688
1673
  await B(!0, o);
1689
1674
  break;
1690
1675
  case "dev":
1691
- await ke();
1676
+ await Re();
1692
1677
  break;
1693
1678
  case "login":
1694
1679
  try {
1695
1680
  await X(), console.log(`
1696
1681
  `), await B(e, o);
1697
- } catch (k) {
1698
- console.error("Login failed:", k.message), await B(e, o);
1682
+ } catch (T) {
1683
+ console.error("Login failed:", T.message), await B(e, o);
1699
1684
  }
1700
1685
  break;
1701
1686
  case "logout":
1702
- await Fe(), console.log(`
1687
+ await De(), console.log(`
1703
1688
  `), await B(e, o);
1704
1689
  break;
1705
1690
  case "help":
@@ -1708,8 +1693,8 @@ Running sync...
1708
1693
  case "exit":
1709
1694
  process.exit(0);
1710
1695
  }
1711
- }, Mt = async () => {
1712
- const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"), f = (await import("path")).default.basename(process.cwd());
1696
+ }, Ot = async () => {
1697
+ const { input: e, select: o } = await import("@inquirer/prompts"), s = await import("fs"), f = (await import("path")).default.basename(process.cwd());
1713
1698
  let c, m;
1714
1699
  try {
1715
1700
  c = await e({
@@ -1736,7 +1721,7 @@ Running sync...
1736
1721
  author: "@myop-cli"
1737
1722
  }, I = d.program.getOptionValue("config") || "./myop.config.json";
1738
1723
  try {
1739
- n.writeFileSync(I, JSON.stringify(w, null, 2)), console.log(`
1724
+ s.writeFileSync(I, JSON.stringify(w, null, 2)), console.log(`
1740
1725
  βœ… Created ${I}`);
1741
1726
  const u = {
1742
1727
  name: c.toLowerCase().replace(/\s+/g, "-"),
@@ -1750,7 +1735,7 @@ Running sync...
1750
1735
  esbuild: "^0.24.0"
1751
1736
  }
1752
1737
  };
1753
- n.writeFileSync("package.json", JSON.stringify(u, null, 2)), console.log("βœ… Created package.json"), n.mkdirSync("src/modules", { recursive: !0 }), n.mkdirSync("src/styles", { recursive: !0 }), n.writeFileSync("build.js", `import * as esbuild from 'esbuild';
1738
+ s.writeFileSync("package.json", JSON.stringify(u, null, 2)), console.log("βœ… Created package.json"), s.mkdirSync("src/modules", { recursive: !0 }), s.mkdirSync("src/styles", { recursive: !0 }), s.writeFileSync("build.js", `import * as esbuild from 'esbuild';
1754
1739
  import fs from 'fs';
1755
1740
  import path from 'path';
1756
1741
 
@@ -1830,7 +1815,7 @@ fs.writeFileSync('dist/index.html', html);
1830
1815
  console.log('βœ… Built dist/index.html');
1831
1816
  console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
1832
1817
  `), console.log("βœ… Created build.js");
1833
- const S = `<!DOCTYPE html>
1818
+ const b = `<!DOCTYPE html>
1834
1819
  <html lang="en">
1835
1820
  <head>
1836
1821
  <meta charset="UTF-8">
@@ -1847,7 +1832,7 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
1847
1832
  </body>
1848
1833
  </html>
1849
1834
  `;
1850
- n.writeFileSync("index.html", S), console.log("βœ… Created index.html");
1835
+ s.writeFileSync("index.html", b), console.log("βœ… Created index.html");
1851
1836
  const j = `// ${c} - Entry Point
1852
1837
  import { init } from './modules/app.js';
1853
1838
  import { setupMyopInterface } from './modules/myop.js';
@@ -1857,7 +1842,7 @@ document.addEventListener('DOMContentLoaded', () => {
1857
1842
  setupMyopInterface();
1858
1843
  });
1859
1844
  `;
1860
- n.writeFileSync("src/index.js", j), console.log("βœ… Created src/index.js");
1845
+ s.writeFileSync("src/index.js", j), console.log("βœ… Created src/index.js");
1861
1846
  const v = `// ${c} - Main Application Logic
1862
1847
 
1863
1848
  export function init() {
@@ -1866,7 +1851,7 @@ export function init() {
1866
1851
  // Your component logic here
1867
1852
  }
1868
1853
  `;
1869
- n.writeFileSync("src/modules/app.js", v), console.log("βœ… Created src/modules/app.js"), n.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
1854
+ s.writeFileSync("src/modules/app.js", v), console.log("βœ… Created src/modules/app.js"), s.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
1870
1855
 
1871
1856
  export function setupMyopInterface() {
1872
1857
  // Called when host app sends data to this component
@@ -1886,8 +1871,8 @@ export function setupMyopInterface() {
1886
1871
  /* Add your CSS imports here - they will be auto-bundled */
1887
1872
  @import './main.css';
1888
1873
  `;
1889
- n.writeFileSync("src/styles/index.css", z), console.log("βœ… Created src/styles/index.css");
1890
- const x = `/* ${c} - Main Styles */
1874
+ s.writeFileSync("src/styles/index.css", z), console.log("βœ… Created src/styles/index.css");
1875
+ const S = `/* ${c} - Main Styles */
1891
1876
 
1892
1877
  * {
1893
1878
  box-sizing: border-box;
@@ -1916,7 +1901,7 @@ p {
1916
1901
  line-height: 1.5;
1917
1902
  }
1918
1903
  `;
1919
- n.writeFileSync("src/styles/main.css", x), console.log("βœ… Created src/styles/main.css"), console.log(`
1904
+ s.writeFileSync("src/styles/main.css", S), console.log("βœ… Created src/styles/main.css"), console.log(`
1920
1905
  πŸ“¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
1921
1906
  `), d.myopConfig = w, await B(!0);
1922
1907
  } catch (u) {
@@ -1924,8 +1909,8 @@ p {
1924
1909
  }
1925
1910
  };
1926
1911
  d.program.command("default", { isDefault: !0 }).action(async () => {
1927
- if (d.program.getOptionValue("help") && (console.log(Qe), process.exit()), d.program.getOptionValue("ci")) {
1928
- const m = await import("fs"), w = d.program.getOptionValue("config") || "./myop.config.json", I = d.program.version(), u = ye();
1912
+ if (d.program.getOptionValue("help") && (console.log(Ze), process.exit()), d.program.getOptionValue("ci")) {
1913
+ const m = await import("fs"), w = d.program.getOptionValue("config") || "./myop.config.json", I = d.program.version(), u = we();
1929
1914
  let y = { found: !1 };
1930
1915
  try {
1931
1916
  if (m.existsSync(w)) {
@@ -1941,7 +1926,7 @@ d.program.command("default", { isDefault: !0 }).action(async () => {
1941
1926
  } catch (j) {
1942
1927
  y = { found: !1, error: j.message };
1943
1928
  }
1944
- const S = {
1929
+ const b = {
1945
1930
  version: I,
1946
1931
  config: y,
1947
1932
  auth: {
@@ -1949,16 +1934,16 @@ d.program.command("default", { isDefault: !0 }).action(async () => {
1949
1934
  email: (u == null ? void 0 : u.email) || null
1950
1935
  }
1951
1936
  };
1952
- console.log(JSON.stringify(S, null, 2)), process.exit(0);
1937
+ console.log(JSON.stringify(b, null, 2)), process.exit(0);
1953
1938
  }
1954
- let n = F({
1939
+ let s = F({
1955
1940
  text: "Loading Myop CLI...",
1956
1941
  color: "green"
1957
1942
  }).start();
1958
- const a = le();
1959
- await bt(500), n.stop();
1943
+ const r = le();
1944
+ await Ct(500), s.stop();
1960
1945
  const f = d.program.version();
1961
- await St(f) || await B(a.configFound);
1946
+ await xt(f) || await B(r.configFound);
1962
1947
  });
1963
1948
  d.program.parse(process.argv);
1964
1949
  d.program.opts();