@construct-space/cli 1.3.1 → 1.4.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 (3) hide show
  1. package/README.md +56 -0
  2. package/dist/index.js +957 -492
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ var __export = (target, all) => {
26
26
  set: (newValue) => all[name] = () => newValue
27
27
  });
28
28
  };
29
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
30
  var __require = import.meta.require;
30
31
 
31
32
  // node_modules/commander/lib/error.js
@@ -2121,248 +2122,7 @@ var require_commander = __commonJS((exports) => {
2121
2122
  exports.InvalidOptionArgumentError = InvalidArgumentError;
2122
2123
  });
2123
2124
 
2124
- // node_modules/cli-width/index.js
2125
- var require_cli_width = __commonJS((exports, module) => {
2126
- module.exports = cliWidth;
2127
- function normalizeOpts(options) {
2128
- const defaultOpts = {
2129
- defaultWidth: 0,
2130
- output: process.stdout,
2131
- tty: __require("tty")
2132
- };
2133
- if (!options) {
2134
- return defaultOpts;
2135
- }
2136
- Object.keys(defaultOpts).forEach(function(key) {
2137
- if (!options[key]) {
2138
- options[key] = defaultOpts[key];
2139
- }
2140
- });
2141
- return options;
2142
- }
2143
- function cliWidth(options) {
2144
- const opts = normalizeOpts(options);
2145
- if (opts.output.getWindowSize) {
2146
- return opts.output.getWindowSize()[0] || opts.defaultWidth;
2147
- }
2148
- if (opts.tty.getWindowSize) {
2149
- return opts.tty.getWindowSize()[1] || opts.defaultWidth;
2150
- }
2151
- if (opts.output.columns) {
2152
- return opts.output.columns;
2153
- }
2154
- if (process.env.CLI_WIDTH) {
2155
- const width = parseInt(process.env.CLI_WIDTH, 10);
2156
- if (!isNaN(width) && width !== 0) {
2157
- return width;
2158
- }
2159
- }
2160
- return opts.defaultWidth;
2161
- }
2162
- });
2163
-
2164
- // node_modules/mute-stream/lib/index.js
2165
- var require_lib = __commonJS((exports, module) => {
2166
- var Stream = __require("stream");
2167
-
2168
- class MuteStream extends Stream {
2169
- #isTTY = null;
2170
- constructor(opts = {}) {
2171
- super(opts);
2172
- this.writable = this.readable = true;
2173
- this.muted = false;
2174
- this.on("pipe", this._onpipe);
2175
- this.replace = opts.replace;
2176
- this._prompt = opts.prompt || null;
2177
- this._hadControl = false;
2178
- }
2179
- #destSrc(key, def) {
2180
- if (this._dest) {
2181
- return this._dest[key];
2182
- }
2183
- if (this._src) {
2184
- return this._src[key];
2185
- }
2186
- return def;
2187
- }
2188
- #proxy(method, ...args) {
2189
- if (typeof this._dest?.[method] === "function") {
2190
- this._dest[method](...args);
2191
- }
2192
- if (typeof this._src?.[method] === "function") {
2193
- this._src[method](...args);
2194
- }
2195
- }
2196
- get isTTY() {
2197
- if (this.#isTTY !== null) {
2198
- return this.#isTTY;
2199
- }
2200
- return this.#destSrc("isTTY", false);
2201
- }
2202
- set isTTY(val) {
2203
- this.#isTTY = val;
2204
- }
2205
- get rows() {
2206
- return this.#destSrc("rows");
2207
- }
2208
- get columns() {
2209
- return this.#destSrc("columns");
2210
- }
2211
- mute() {
2212
- this.muted = true;
2213
- }
2214
- unmute() {
2215
- this.muted = false;
2216
- }
2217
- _onpipe(src) {
2218
- this._src = src;
2219
- }
2220
- pipe(dest, options) {
2221
- this._dest = dest;
2222
- return super.pipe(dest, options);
2223
- }
2224
- pause() {
2225
- if (this._src) {
2226
- return this._src.pause();
2227
- }
2228
- }
2229
- resume() {
2230
- if (this._src) {
2231
- return this._src.resume();
2232
- }
2233
- }
2234
- write(c) {
2235
- if (this.muted) {
2236
- if (!this.replace) {
2237
- return true;
2238
- }
2239
- if (c.match(/^\u001b/)) {
2240
- if (c.indexOf(this._prompt) === 0) {
2241
- c = c.slice(this._prompt.length);
2242
- c = c.replace(/./g, this.replace);
2243
- c = this._prompt + c;
2244
- }
2245
- this._hadControl = true;
2246
- return this.emit("data", c);
2247
- } else {
2248
- if (this._prompt && this._hadControl && c.indexOf(this._prompt) === 0) {
2249
- this._hadControl = false;
2250
- this.emit("data", this._prompt);
2251
- c = c.slice(this._prompt.length);
2252
- }
2253
- c = c.toString().replace(/./g, this.replace);
2254
- }
2255
- }
2256
- this.emit("data", c);
2257
- }
2258
- end(c) {
2259
- if (this.muted) {
2260
- if (c && this.replace) {
2261
- c = c.toString().replace(/./g, this.replace);
2262
- } else {
2263
- c = null;
2264
- }
2265
- }
2266
- if (c) {
2267
- this.emit("data", c);
2268
- }
2269
- this.emit("end");
2270
- }
2271
- destroy(...args) {
2272
- return this.#proxy("destroy", ...args);
2273
- }
2274
- destroySoon(...args) {
2275
- return this.#proxy("destroySoon", ...args);
2276
- }
2277
- close(...args) {
2278
- return this.#proxy("close", ...args);
2279
- }
2280
- }
2281
- module.exports = MuteStream;
2282
- });
2283
-
2284
- // node_modules/commander/esm.mjs
2285
- var import__ = __toESM(require_commander(), 1);
2286
- var {
2287
- program,
2288
- createCommand,
2289
- createArgument,
2290
- createOption,
2291
- CommanderError,
2292
- InvalidArgumentError,
2293
- InvalidOptionArgumentError,
2294
- Command,
2295
- Argument,
2296
- Option,
2297
- Help
2298
- } = import__.default;
2299
-
2300
- // src/commands/scaffold.ts
2301
- import { mkdirSync, writeFileSync, existsSync as existsSync2, readFileSync } from "fs";
2302
- import { join as join2, dirname } from "path";
2303
-
2304
2125
  // node_modules/chalk/source/vendor/ansi-styles/index.js
2305
- var ANSI_BACKGROUND_OFFSET = 10;
2306
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
2307
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
2308
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
2309
- var styles = {
2310
- modifier: {
2311
- reset: [0, 0],
2312
- bold: [1, 22],
2313
- dim: [2, 22],
2314
- italic: [3, 23],
2315
- underline: [4, 24],
2316
- overline: [53, 55],
2317
- inverse: [7, 27],
2318
- hidden: [8, 28],
2319
- strikethrough: [9, 29]
2320
- },
2321
- color: {
2322
- black: [30, 39],
2323
- red: [31, 39],
2324
- green: [32, 39],
2325
- yellow: [33, 39],
2326
- blue: [34, 39],
2327
- magenta: [35, 39],
2328
- cyan: [36, 39],
2329
- white: [37, 39],
2330
- blackBright: [90, 39],
2331
- gray: [90, 39],
2332
- grey: [90, 39],
2333
- redBright: [91, 39],
2334
- greenBright: [92, 39],
2335
- yellowBright: [93, 39],
2336
- blueBright: [94, 39],
2337
- magentaBright: [95, 39],
2338
- cyanBright: [96, 39],
2339
- whiteBright: [97, 39]
2340
- },
2341
- bgColor: {
2342
- bgBlack: [40, 49],
2343
- bgRed: [41, 49],
2344
- bgGreen: [42, 49],
2345
- bgYellow: [43, 49],
2346
- bgBlue: [44, 49],
2347
- bgMagenta: [45, 49],
2348
- bgCyan: [46, 49],
2349
- bgWhite: [47, 49],
2350
- bgBlackBright: [100, 49],
2351
- bgGray: [100, 49],
2352
- bgGrey: [100, 49],
2353
- bgRedBright: [101, 49],
2354
- bgGreenBright: [102, 49],
2355
- bgYellowBright: [103, 49],
2356
- bgBlueBright: [104, 49],
2357
- bgMagentaBright: [105, 49],
2358
- bgCyanBright: [106, 49],
2359
- bgWhiteBright: [107, 49]
2360
- }
2361
- };
2362
- var modifierNames = Object.keys(styles.modifier);
2363
- var foregroundColorNames = Object.keys(styles.color);
2364
- var backgroundColorNames = Object.keys(styles.bgColor);
2365
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
2366
2126
  function assembleStyles() {
2367
2127
  const codes = new Map;
2368
2128
  for (const [groupName, group] of Object.entries(styles)) {
@@ -2475,8 +2235,68 @@ function assembleStyles() {
2475
2235
  });
2476
2236
  return styles;
2477
2237
  }
2478
- var ansiStyles = assembleStyles();
2479
- var ansi_styles_default = ansiStyles;
2238
+ var ANSI_BACKGROUND_OFFSET = 10, wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`, wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`, wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`, styles, modifierNames, foregroundColorNames, backgroundColorNames, colorNames, ansiStyles, ansi_styles_default;
2239
+ var init_ansi_styles = __esm(() => {
2240
+ styles = {
2241
+ modifier: {
2242
+ reset: [0, 0],
2243
+ bold: [1, 22],
2244
+ dim: [2, 22],
2245
+ italic: [3, 23],
2246
+ underline: [4, 24],
2247
+ overline: [53, 55],
2248
+ inverse: [7, 27],
2249
+ hidden: [8, 28],
2250
+ strikethrough: [9, 29]
2251
+ },
2252
+ color: {
2253
+ black: [30, 39],
2254
+ red: [31, 39],
2255
+ green: [32, 39],
2256
+ yellow: [33, 39],
2257
+ blue: [34, 39],
2258
+ magenta: [35, 39],
2259
+ cyan: [36, 39],
2260
+ white: [37, 39],
2261
+ blackBright: [90, 39],
2262
+ gray: [90, 39],
2263
+ grey: [90, 39],
2264
+ redBright: [91, 39],
2265
+ greenBright: [92, 39],
2266
+ yellowBright: [93, 39],
2267
+ blueBright: [94, 39],
2268
+ magentaBright: [95, 39],
2269
+ cyanBright: [96, 39],
2270
+ whiteBright: [97, 39]
2271
+ },
2272
+ bgColor: {
2273
+ bgBlack: [40, 49],
2274
+ bgRed: [41, 49],
2275
+ bgGreen: [42, 49],
2276
+ bgYellow: [43, 49],
2277
+ bgBlue: [44, 49],
2278
+ bgMagenta: [45, 49],
2279
+ bgCyan: [46, 49],
2280
+ bgWhite: [47, 49],
2281
+ bgBlackBright: [100, 49],
2282
+ bgGray: [100, 49],
2283
+ bgGrey: [100, 49],
2284
+ bgRedBright: [101, 49],
2285
+ bgGreenBright: [102, 49],
2286
+ bgYellowBright: [103, 49],
2287
+ bgBlueBright: [104, 49],
2288
+ bgMagentaBright: [105, 49],
2289
+ bgCyanBright: [106, 49],
2290
+ bgWhiteBright: [107, 49]
2291
+ }
2292
+ };
2293
+ modifierNames = Object.keys(styles.modifier);
2294
+ foregroundColorNames = Object.keys(styles.color);
2295
+ backgroundColorNames = Object.keys(styles.bgColor);
2296
+ colorNames = [...foregroundColorNames, ...backgroundColorNames];
2297
+ ansiStyles = assembleStyles();
2298
+ ansi_styles_default = ansiStyles;
2299
+ });
2480
2300
 
2481
2301
  // node_modules/chalk/source/vendor/supports-color/index.js
2482
2302
  import process2 from "process";
@@ -2488,13 +2308,6 @@ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.
2488
2308
  const terminatorPosition = argv.indexOf("--");
2489
2309
  return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
2490
2310
  }
2491
- var { env } = process2;
2492
- var flagForceColor;
2493
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
2494
- flagForceColor = 0;
2495
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
2496
- flagForceColor = 1;
2497
- }
2498
2311
  function envForceColor() {
2499
2312
  if ("FORCE_COLOR" in env) {
2500
2313
  if (env.FORCE_COLOR === "true") {
@@ -2604,11 +2417,20 @@ function createSupportsColor(stream, options = {}) {
2604
2417
  });
2605
2418
  return translateLevel(level);
2606
2419
  }
2607
- var supportsColor = {
2608
- stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
2609
- stderr: createSupportsColor({ isTTY: tty.isatty(2) })
2610
- };
2611
- var supports_color_default = supportsColor;
2420
+ var env, flagForceColor, supportsColor, supports_color_default;
2421
+ var init_supports_color = __esm(() => {
2422
+ ({ env } = process2);
2423
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
2424
+ flagForceColor = 0;
2425
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
2426
+ flagForceColor = 1;
2427
+ }
2428
+ supportsColor = {
2429
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
2430
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
2431
+ };
2432
+ supports_color_default = supportsColor;
2433
+ });
2612
2434
 
2613
2435
  // node_modules/chalk/source/utilities.js
2614
2436
  function stringReplaceAll(string, substring, replacer) {
@@ -2643,152 +2465,856 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2643
2465
  return returnValue;
2644
2466
  }
2645
2467
 
2646
- // node_modules/chalk/source/index.js
2647
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
2648
- var GENERATOR = Symbol("GENERATOR");
2649
- var STYLER = Symbol("STYLER");
2650
- var IS_EMPTY = Symbol("IS_EMPTY");
2651
- var levelMapping = [
2652
- "ansi",
2653
- "ansi",
2654
- "ansi256",
2655
- "ansi16m"
2656
- ];
2657
- var styles2 = Object.create(null);
2658
- var applyOptions = (object, options = {}) => {
2659
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2660
- throw new Error("The `level` option should be an integer from 0 to 3");
2468
+ // node_modules/chalk/source/index.js
2469
+ function createChalk(options) {
2470
+ return chalkFactory(options);
2471
+ }
2472
+ var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions = (object, options = {}) => {
2473
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2474
+ throw new Error("The `level` option should be an integer from 0 to 3");
2475
+ }
2476
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
2477
+ object.level = options.level === undefined ? colorLevel : options.level;
2478
+ }, chalkFactory = (options) => {
2479
+ const chalk = (...strings) => strings.join(" ");
2480
+ applyOptions(chalk, options);
2481
+ Object.setPrototypeOf(chalk, createChalk.prototype);
2482
+ return chalk;
2483
+ }, getModelAnsi = (model, level, type, ...arguments_) => {
2484
+ if (model === "rgb") {
2485
+ if (level === "ansi16m") {
2486
+ return ansi_styles_default[type].ansi16m(...arguments_);
2487
+ }
2488
+ if (level === "ansi256") {
2489
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
2490
+ }
2491
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
2492
+ }
2493
+ if (model === "hex") {
2494
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
2495
+ }
2496
+ return ansi_styles_default[type][model](...arguments_);
2497
+ }, usedModels, proto, createStyler = (open, close, parent) => {
2498
+ let openAll;
2499
+ let closeAll;
2500
+ if (parent === undefined) {
2501
+ openAll = open;
2502
+ closeAll = close;
2503
+ } else {
2504
+ openAll = parent.openAll + open;
2505
+ closeAll = close + parent.closeAll;
2506
+ }
2507
+ return {
2508
+ open,
2509
+ close,
2510
+ openAll,
2511
+ closeAll,
2512
+ parent
2513
+ };
2514
+ }, createBuilder = (self, _styler, _isEmpty) => {
2515
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2516
+ Object.setPrototypeOf(builder, proto);
2517
+ builder[GENERATOR] = self;
2518
+ builder[STYLER] = _styler;
2519
+ builder[IS_EMPTY] = _isEmpty;
2520
+ return builder;
2521
+ }, applyStyle = (self, string) => {
2522
+ if (self.level <= 0 || !string) {
2523
+ return self[IS_EMPTY] ? "" : string;
2524
+ }
2525
+ let styler = self[STYLER];
2526
+ if (styler === undefined) {
2527
+ return string;
2528
+ }
2529
+ const { openAll, closeAll } = styler;
2530
+ if (string.includes("\x1B")) {
2531
+ while (styler !== undefined) {
2532
+ string = stringReplaceAll(string, styler.close, styler.open);
2533
+ styler = styler.parent;
2534
+ }
2535
+ }
2536
+ const lfIndex = string.indexOf(`
2537
+ `);
2538
+ if (lfIndex !== -1) {
2539
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
2540
+ }
2541
+ return openAll + string + closeAll;
2542
+ }, chalk, chalkStderr, source_default;
2543
+ var init_source = __esm(() => {
2544
+ init_ansi_styles();
2545
+ init_supports_color();
2546
+ ({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default);
2547
+ GENERATOR = Symbol("GENERATOR");
2548
+ STYLER = Symbol("STYLER");
2549
+ IS_EMPTY = Symbol("IS_EMPTY");
2550
+ levelMapping = [
2551
+ "ansi",
2552
+ "ansi",
2553
+ "ansi256",
2554
+ "ansi16m"
2555
+ ];
2556
+ styles2 = Object.create(null);
2557
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2558
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2559
+ styles2[styleName] = {
2560
+ get() {
2561
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2562
+ Object.defineProperty(this, styleName, { value: builder });
2563
+ return builder;
2564
+ }
2565
+ };
2566
+ }
2567
+ styles2.visible = {
2568
+ get() {
2569
+ const builder = createBuilder(this, this[STYLER], true);
2570
+ Object.defineProperty(this, "visible", { value: builder });
2571
+ return builder;
2572
+ }
2573
+ };
2574
+ usedModels = ["rgb", "hex", "ansi256"];
2575
+ for (const model of usedModels) {
2576
+ styles2[model] = {
2577
+ get() {
2578
+ const { level } = this;
2579
+ return function(...arguments_) {
2580
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2581
+ return createBuilder(this, styler, this[IS_EMPTY]);
2582
+ };
2583
+ }
2584
+ };
2585
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2586
+ styles2[bgModel] = {
2587
+ get() {
2588
+ const { level } = this;
2589
+ return function(...arguments_) {
2590
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2591
+ return createBuilder(this, styler, this[IS_EMPTY]);
2592
+ };
2593
+ }
2594
+ };
2595
+ }
2596
+ proto = Object.defineProperties(() => {}, {
2597
+ ...styles2,
2598
+ level: {
2599
+ enumerable: true,
2600
+ get() {
2601
+ return this[GENERATOR].level;
2602
+ },
2603
+ set(level) {
2604
+ this[GENERATOR].level = level;
2605
+ }
2606
+ }
2607
+ });
2608
+ Object.defineProperties(createChalk.prototype, styles2);
2609
+ chalk = createChalk();
2610
+ chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
2611
+ source_default = chalk;
2612
+ });
2613
+
2614
+ // node_modules/cli-width/index.js
2615
+ var require_cli_width = __commonJS((exports, module) => {
2616
+ module.exports = cliWidth;
2617
+ function normalizeOpts(options) {
2618
+ const defaultOpts = {
2619
+ defaultWidth: 0,
2620
+ output: process.stdout,
2621
+ tty: __require("tty")
2622
+ };
2623
+ if (!options) {
2624
+ return defaultOpts;
2625
+ }
2626
+ Object.keys(defaultOpts).forEach(function(key) {
2627
+ if (!options[key]) {
2628
+ options[key] = defaultOpts[key];
2629
+ }
2630
+ });
2631
+ return options;
2632
+ }
2633
+ function cliWidth(options) {
2634
+ const opts = normalizeOpts(options);
2635
+ if (opts.output.getWindowSize) {
2636
+ return opts.output.getWindowSize()[0] || opts.defaultWidth;
2637
+ }
2638
+ if (opts.tty.getWindowSize) {
2639
+ return opts.tty.getWindowSize()[1] || opts.defaultWidth;
2640
+ }
2641
+ if (opts.output.columns) {
2642
+ return opts.output.columns;
2643
+ }
2644
+ if (process.env.CLI_WIDTH) {
2645
+ const width = parseInt(process.env.CLI_WIDTH, 10);
2646
+ if (!isNaN(width) && width !== 0) {
2647
+ return width;
2648
+ }
2649
+ }
2650
+ return opts.defaultWidth;
2651
+ }
2652
+ });
2653
+
2654
+ // node_modules/mute-stream/lib/index.js
2655
+ var require_lib = __commonJS((exports, module) => {
2656
+ var Stream = __require("stream");
2657
+
2658
+ class MuteStream extends Stream {
2659
+ #isTTY = null;
2660
+ constructor(opts = {}) {
2661
+ super(opts);
2662
+ this.writable = this.readable = true;
2663
+ this.muted = false;
2664
+ this.on("pipe", this._onpipe);
2665
+ this.replace = opts.replace;
2666
+ this._prompt = opts.prompt || null;
2667
+ this._hadControl = false;
2668
+ }
2669
+ #destSrc(key, def) {
2670
+ if (this._dest) {
2671
+ return this._dest[key];
2672
+ }
2673
+ if (this._src) {
2674
+ return this._src[key];
2675
+ }
2676
+ return def;
2677
+ }
2678
+ #proxy(method, ...args) {
2679
+ if (typeof this._dest?.[method] === "function") {
2680
+ this._dest[method](...args);
2681
+ }
2682
+ if (typeof this._src?.[method] === "function") {
2683
+ this._src[method](...args);
2684
+ }
2685
+ }
2686
+ get isTTY() {
2687
+ if (this.#isTTY !== null) {
2688
+ return this.#isTTY;
2689
+ }
2690
+ return this.#destSrc("isTTY", false);
2691
+ }
2692
+ set isTTY(val) {
2693
+ this.#isTTY = val;
2694
+ }
2695
+ get rows() {
2696
+ return this.#destSrc("rows");
2697
+ }
2698
+ get columns() {
2699
+ return this.#destSrc("columns");
2700
+ }
2701
+ mute() {
2702
+ this.muted = true;
2703
+ }
2704
+ unmute() {
2705
+ this.muted = false;
2706
+ }
2707
+ _onpipe(src) {
2708
+ this._src = src;
2709
+ }
2710
+ pipe(dest, options) {
2711
+ this._dest = dest;
2712
+ return super.pipe(dest, options);
2713
+ }
2714
+ pause() {
2715
+ if (this._src) {
2716
+ return this._src.pause();
2717
+ }
2718
+ }
2719
+ resume() {
2720
+ if (this._src) {
2721
+ return this._src.resume();
2722
+ }
2723
+ }
2724
+ write(c) {
2725
+ if (this.muted) {
2726
+ if (!this.replace) {
2727
+ return true;
2728
+ }
2729
+ if (c.match(/^\u001b/)) {
2730
+ if (c.indexOf(this._prompt) === 0) {
2731
+ c = c.slice(this._prompt.length);
2732
+ c = c.replace(/./g, this.replace);
2733
+ c = this._prompt + c;
2734
+ }
2735
+ this._hadControl = true;
2736
+ return this.emit("data", c);
2737
+ } else {
2738
+ if (this._prompt && this._hadControl && c.indexOf(this._prompt) === 0) {
2739
+ this._hadControl = false;
2740
+ this.emit("data", this._prompt);
2741
+ c = c.slice(this._prompt.length);
2742
+ }
2743
+ c = c.toString().replace(/./g, this.replace);
2744
+ }
2745
+ }
2746
+ this.emit("data", c);
2747
+ }
2748
+ end(c) {
2749
+ if (this.muted) {
2750
+ if (c && this.replace) {
2751
+ c = c.toString().replace(/./g, this.replace);
2752
+ } else {
2753
+ c = null;
2754
+ }
2755
+ }
2756
+ if (c) {
2757
+ this.emit("data", c);
2758
+ }
2759
+ this.emit("end");
2760
+ }
2761
+ destroy(...args) {
2762
+ return this.#proxy("destroy", ...args);
2763
+ }
2764
+ destroySoon(...args) {
2765
+ return this.#proxy("destroySoon", ...args);
2766
+ }
2767
+ close(...args) {
2768
+ return this.#proxy("close", ...args);
2769
+ }
2770
+ }
2771
+ module.exports = MuteStream;
2772
+ });
2773
+
2774
+ // src/lib/appdir.ts
2775
+ import { join as join10 } from "path";
2776
+ import { homedir } from "os";
2777
+ import { platform } from "process";
2778
+ function dataDir() {
2779
+ if (process.env.CONSTRUCT_DATA_DIR)
2780
+ return process.env.CONSTRUCT_DATA_DIR;
2781
+ const home = homedir();
2782
+ switch (platform) {
2783
+ case "darwin":
2784
+ return join10(home, "Library", "Application Support", "Construct");
2785
+ case "win32": {
2786
+ const appData = process.env.APPDATA || join10(home, "AppData", "Roaming");
2787
+ return join10(appData, "Construct");
2788
+ }
2789
+ default: {
2790
+ const xdg = process.env.XDG_DATA_HOME || join10(home, ".local", "share");
2791
+ return join10(xdg, "construct");
2792
+ }
2793
+ }
2794
+ }
2795
+ function spacesDir() {
2796
+ return join10(dataDir(), "spaces");
2797
+ }
2798
+ function profilesDir() {
2799
+ return join10(dataDir(), "profiles");
2800
+ }
2801
+ function spaceDir(spaceId) {
2802
+ return join10(spacesDir(), spaceId);
2803
+ }
2804
+ var init_appdir = () => {};
2805
+
2806
+ // src/lib/auth.ts
2807
+ import { readFileSync as readFileSync6, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4, unlinkSync, existsSync as existsSync9, readdirSync as readdirSync4, statSync as statSync4 } from "fs";
2808
+ import { join as join12, dirname as dirname4 } from "path";
2809
+ function listDesktopProfiles() {
2810
+ const dir = profilesDir();
2811
+ if (!existsSync9(dir))
2812
+ return [];
2813
+ const results = [];
2814
+ for (const entry of readdirSync4(dir)) {
2815
+ const full = join12(dir, entry);
2816
+ try {
2817
+ if (!statSync4(full).isDirectory())
2818
+ continue;
2819
+ const authPath = join12(full, "auth.json");
2820
+ if (!existsSync9(authPath))
2821
+ continue;
2822
+ const data = JSON.parse(readFileSync6(authPath, "utf-8"));
2823
+ if (!data.token)
2824
+ continue;
2825
+ if (data.authenticated !== undefined && !data.authenticated)
2826
+ continue;
2827
+ results.push({
2828
+ id: entry,
2829
+ token: data.token,
2830
+ user: data.user,
2831
+ updatedAt: data.updated_at,
2832
+ authenticated: true
2833
+ });
2834
+ } catch {}
2835
+ }
2836
+ return results;
2837
+ }
2838
+ function credentialsPath() {
2839
+ return join12(dataDir(), CREDENTIALS_FILE);
2840
+ }
2841
+ function store(creds) {
2842
+ const path = credentialsPath();
2843
+ mkdirSync4(dirname4(path), { recursive: true });
2844
+ writeFileSync5(path, JSON.stringify(creds, null, 2) + `
2845
+ `, { mode: 384 });
2846
+ }
2847
+ function load2() {
2848
+ const path = credentialsPath();
2849
+ if (!existsSync9(path)) {
2850
+ throw new Error("not logged in \u2014 run 'construct login' first");
2851
+ }
2852
+ const data = JSON.parse(readFileSync6(path, "utf-8"));
2853
+ if (!data.token) {
2854
+ throw new Error("not logged in \u2014 run 'construct login' first");
2855
+ }
2856
+ return data;
2857
+ }
2858
+ function isAuthenticated() {
2859
+ try {
2860
+ load2();
2861
+ return true;
2862
+ } catch {
2863
+ return false;
2864
+ }
2865
+ }
2866
+ function clear() {
2867
+ const path = credentialsPath();
2868
+ if (existsSync9(path))
2869
+ unlinkSync(path);
2870
+ }
2871
+ var CREDENTIALS_FILE = "credentials.json", DEFAULT_PORTAL = "https://my.construct.space/api/developer";
2872
+ var init_auth = __esm(() => {
2873
+ init_appdir();
2874
+ });
2875
+
2876
+ // src/lib/graphClient.ts
2877
+ function graphBaseURL() {
2878
+ return process.env.GRAPH_URL || "https://my.construct.space/api/graph";
2879
+ }
2880
+ function resolveOrgId(explicit) {
2881
+ if (explicit)
2882
+ return explicit;
2883
+ return process.env.CONSTRUCT_ORG_ID || "";
2884
+ }
2885
+ function loadCreds() {
2886
+ try {
2887
+ return load2();
2888
+ } catch (err) {
2889
+ const msg = err instanceof Error ? err.message : String(err);
2890
+ throw new Error(msg + `
2891
+ Run 'construct login' first.`);
2892
+ }
2893
+ }
2894
+ async function graphRequest(opts) {
2895
+ const creds = loadCreds();
2896
+ const headers = {
2897
+ Authorization: `Bearer ${creds.token}`,
2898
+ "Content-Type": "application/json"
2899
+ };
2900
+ if (creds.user?.id)
2901
+ headers["X-Auth-User-ID"] = creds.user.id;
2902
+ if (opts.orgId)
2903
+ headers["X-Auth-Org-ID"] = opts.orgId;
2904
+ const resp = await fetch(graphBaseURL() + opts.path, {
2905
+ method: opts.method || "GET",
2906
+ headers,
2907
+ body: opts.body === undefined ? undefined : JSON.stringify(opts.body)
2908
+ });
2909
+ if (!resp.ok) {
2910
+ const text2 = await resp.text().catch(() => "");
2911
+ let msg = text2;
2912
+ try {
2913
+ const parsed = JSON.parse(text2);
2914
+ if (parsed.error)
2915
+ msg = parsed.error;
2916
+ } catch {}
2917
+ throw new Error(`${resp.status}: ${msg || resp.statusText}`);
2918
+ }
2919
+ const text = await resp.text();
2920
+ if (!text)
2921
+ return;
2922
+ return JSON.parse(text);
2923
+ }
2924
+ function requireOrgId(explicit) {
2925
+ const org = resolveOrgId(explicit);
2926
+ if (!org) {
2927
+ throw new Error("org context required. Pass --org <id> or set CONSTRUCT_ORG_ID. " + "Find your org id on the profile page or via accounts /api/me/scope.");
2928
+ }
2929
+ return org;
2930
+ }
2931
+ var init_graphClient = __esm(() => {
2932
+ init_auth();
2933
+ });
2934
+
2935
+ // src/commands/graph/spaces.ts
2936
+ var exports_spaces = {};
2937
+ __export(exports_spaces, {
2938
+ spacesList: () => spacesList
2939
+ });
2940
+ async function spacesList(opts = {}) {
2941
+ const orgId = requireOrgId(opts.org);
2942
+ try {
2943
+ const resp = await graphRequest({
2944
+ method: "GET",
2945
+ path: "/api/spaces",
2946
+ orgId
2947
+ });
2948
+ let spaces = resp.spaces || [];
2949
+ if (opts.bundle) {
2950
+ spaces = spaces.filter((s) => s.bundle_id === opts.bundle);
2951
+ }
2952
+ if (opts.json) {
2953
+ console.log(JSON.stringify(spaces, null, 2));
2954
+ return;
2955
+ }
2956
+ if (spaces.length === 0) {
2957
+ const hint = opts.bundle ? `No spaces in bundle "${opts.bundle}".` : "No spaces published by this org yet. Publish one with: construct space publish";
2958
+ console.log(source_default.dim(hint));
2959
+ return;
2960
+ }
2961
+ const rows = spaces.map((s) => ({
2962
+ id: s.id,
2963
+ version: s.latest_version || "0.0.0",
2964
+ bundle: s.bundle_id || source_default.dim("\u2014"),
2965
+ distribution: colorizeDistribution(s.distribution),
2966
+ installs: String(s.install_count)
2967
+ }));
2968
+ const widths = {
2969
+ id: Math.max(4, ...rows.map((r) => r.id.length)),
2970
+ version: Math.max(7, ...rows.map((r) => r.version.length)),
2971
+ bundle: Math.max(6, ...rows.map((r) => plain(r.bundle).length)),
2972
+ distribution: Math.max(12, ...rows.map((r) => plain(r.distribution).length))
2973
+ };
2974
+ const header = [
2975
+ source_default.bold("SPACE".padEnd(widths.id)),
2976
+ source_default.bold("VERSION".padEnd(widths.version)),
2977
+ source_default.bold("BUNDLE".padEnd(widths.bundle)),
2978
+ source_default.bold("DISTRIBUTION".padEnd(widths.distribution)),
2979
+ source_default.bold("INSTALLS")
2980
+ ].join(" ");
2981
+ console.log(header);
2982
+ for (const r of rows) {
2983
+ console.log([
2984
+ source_default.cyan(r.id.padEnd(widths.id)),
2985
+ r.version.padEnd(widths.version),
2986
+ padVisible(r.bundle, widths.bundle),
2987
+ padVisible(r.distribution, widths.distribution),
2988
+ r.installs
2989
+ ].join(" "));
2990
+ }
2991
+ console.log(source_default.dim(`
2992
+ ${spaces.length} space${spaces.length === 1 ? "" : "s"}`));
2993
+ } catch (err) {
2994
+ const msg = err instanceof Error ? err.message : String(err);
2995
+ console.error(source_default.red(msg));
2996
+ process.exit(1);
2997
+ }
2998
+ }
2999
+ function colorizeDistribution(mode) {
3000
+ switch (mode) {
3001
+ case "public":
3002
+ return source_default.green(mode);
3003
+ case "org_allowlist":
3004
+ return source_default.yellow(mode);
3005
+ case "private":
3006
+ return source_default.magenta(mode);
3007
+ default:
3008
+ return mode;
3009
+ }
3010
+ }
3011
+ function plain(s) {
3012
+ return s.replace(/\u001b\[[0-9;]*m/g, "");
3013
+ }
3014
+ function padVisible(s, width) {
3015
+ const visible = plain(s);
3016
+ if (visible.length >= width)
3017
+ return s;
3018
+ return s + " ".repeat(width - visible.length);
3019
+ }
3020
+ var init_spaces = __esm(() => {
3021
+ init_source();
3022
+ init_graphClient();
3023
+ });
3024
+
3025
+ // src/commands/graph/bundles.ts
3026
+ var exports_bundles = {};
3027
+ __export(exports_bundles, {
3028
+ bundlesList: () => bundlesList,
3029
+ bundleShow: () => bundleShow,
3030
+ bundleCreate: () => bundleCreate
3031
+ });
3032
+ async function bundlesList(opts = {}) {
3033
+ const orgId = requireOrgId(opts.org);
3034
+ try {
3035
+ const resp = await graphRequest({
3036
+ method: "GET",
3037
+ path: "/api/space-bundles",
3038
+ orgId
3039
+ });
3040
+ const bundles = resp.bundles || [];
3041
+ if (opts.json) {
3042
+ console.log(JSON.stringify(bundles, null, 2));
3043
+ return;
3044
+ }
3045
+ if (bundles.length === 0) {
3046
+ console.log(source_default.dim("No bundles yet. Create one with: construct graph bundles create <id> <name>"));
3047
+ return;
3048
+ }
3049
+ console.log(source_default.bold(`Bundles for org ${orgId}:`));
3050
+ for (const b of bundles) {
3051
+ console.log(` ${source_default.cyan(b.id)} \u2014 ${b.name}`);
3052
+ }
3053
+ } catch (err) {
3054
+ fail(err);
3055
+ }
3056
+ }
3057
+ async function bundleCreate(id, name, opts = {}) {
3058
+ const orgId = requireOrgId(opts.org);
3059
+ if (!id || !name) {
3060
+ console.error(source_default.red("Usage: construct graph bundles create <id> <name>"));
3061
+ process.exit(1);
3062
+ }
3063
+ try {
3064
+ const resp = await graphRequest({
3065
+ method: "POST",
3066
+ path: "/api/space-bundles",
3067
+ body: { id, name },
3068
+ orgId
3069
+ });
3070
+ if (opts.json) {
3071
+ console.log(JSON.stringify(resp, null, 2));
3072
+ return;
3073
+ }
3074
+ console.log(source_default.green(`\u2713 Bundle created: ${source_default.cyan(resp.id)} \u2014 ${resp.name}`));
3075
+ console.log(source_default.dim(` Next: add bundle_id: "${resp.id}" to your data.manifest.json and publish.`));
3076
+ } catch (err) {
3077
+ fail(err);
3078
+ }
3079
+ }
3080
+ async function bundleShow(id, opts = {}) {
3081
+ const orgId = requireOrgId(opts.org);
3082
+ if (!id) {
3083
+ console.error(source_default.red("Usage: construct graph bundles show <id>"));
3084
+ process.exit(1);
3085
+ }
3086
+ try {
3087
+ const bundle = await graphRequest({
3088
+ method: "GET",
3089
+ path: `/api/space-bundles/${encodeURIComponent(id)}`,
3090
+ orgId
3091
+ });
3092
+ if (opts.json) {
3093
+ console.log(JSON.stringify(bundle, null, 2));
3094
+ return;
3095
+ }
3096
+ console.log(source_default.bold(bundle.id));
3097
+ console.log(` Name: ${bundle.name}`);
3098
+ console.log(` Owner org: ${bundle.owner_org_id}`);
3099
+ if (bundle.created_at)
3100
+ console.log(` Created: ${bundle.created_at}`);
3101
+ } catch (err) {
3102
+ fail(err);
3103
+ }
3104
+ }
3105
+ function fail(err) {
3106
+ const msg = err instanceof Error ? err.message : String(err);
3107
+ console.error(source_default.red(msg));
3108
+ process.exit(1);
3109
+ }
3110
+ var init_bundles = __esm(() => {
3111
+ init_source();
3112
+ init_graphClient();
3113
+ });
3114
+
3115
+ // src/commands/graph/install.ts
3116
+ var exports_install = {};
3117
+ __export(exports_install, {
3118
+ uninstallSpace: () => uninstallSpace,
3119
+ installsList: () => installsList,
3120
+ installSpace: () => installSpace
3121
+ });
3122
+ async function installSpace(spaceId, opts = {}) {
3123
+ const orgId = requireOrgId(opts.org);
3124
+ if (!spaceId) {
3125
+ console.error(source_default.red("Usage: construct graph install <space-id>"));
3126
+ process.exit(1);
2661
3127
  }
2662
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
2663
- object.level = options.level === undefined ? colorLevel : options.level;
2664
- };
2665
- var chalkFactory = (options) => {
2666
- const chalk = (...strings) => strings.join(" ");
2667
- applyOptions(chalk, options);
2668
- Object.setPrototypeOf(chalk, createChalk.prototype);
2669
- return chalk;
2670
- };
2671
- function createChalk(options) {
2672
- return chalkFactory(options);
2673
- }
2674
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2675
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2676
- styles2[styleName] = {
2677
- get() {
2678
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2679
- Object.defineProperty(this, styleName, { value: builder });
2680
- return builder;
3128
+ try {
3129
+ const resp = await graphRequest({
3130
+ method: "POST",
3131
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/install`,
3132
+ orgId
3133
+ });
3134
+ if (opts.json) {
3135
+ console.log(JSON.stringify(resp, null, 2));
3136
+ return;
2681
3137
  }
2682
- };
3138
+ console.log(source_default.green(`\u2713 Installed ${source_default.cyan(spaceId)} for org ${orgId}`));
3139
+ } catch (err) {
3140
+ fail2(err);
3141
+ }
2683
3142
  }
2684
- styles2.visible = {
2685
- get() {
2686
- const builder = createBuilder(this, this[STYLER], true);
2687
- Object.defineProperty(this, "visible", { value: builder });
2688
- return builder;
3143
+ async function uninstallSpace(spaceId, opts = {}) {
3144
+ const orgId = requireOrgId(opts.org);
3145
+ if (!spaceId) {
3146
+ console.error(source_default.red("Usage: construct graph uninstall <space-id>"));
3147
+ process.exit(1);
2689
3148
  }
2690
- };
2691
- var getModelAnsi = (model, level, type, ...arguments_) => {
2692
- if (model === "rgb") {
2693
- if (level === "ansi16m") {
2694
- return ansi_styles_default[type].ansi16m(...arguments_);
2695
- }
2696
- if (level === "ansi256") {
2697
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
3149
+ try {
3150
+ const resp = await graphRequest({
3151
+ method: "DELETE",
3152
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/install`,
3153
+ orgId
3154
+ });
3155
+ if (opts.json) {
3156
+ console.log(JSON.stringify(resp, null, 2));
3157
+ return;
2698
3158
  }
2699
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
3159
+ console.log(source_default.green(`\u2713 Uninstalled ${source_default.cyan(spaceId)} for org ${orgId}`));
3160
+ console.log(source_default.dim(" Note: tenant data is preserved; reinstall to reconnect."));
3161
+ } catch (err) {
3162
+ fail2(err);
2700
3163
  }
2701
- if (model === "hex") {
2702
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
3164
+ }
3165
+ async function installsList(spaceId, opts = {}) {
3166
+ const orgId = requireOrgId(opts.org);
3167
+ if (!spaceId) {
3168
+ console.error(source_default.red("Usage: construct graph installs <space-id>"));
3169
+ process.exit(1);
2703
3170
  }
2704
- return ansi_styles_default[type][model](...arguments_);
2705
- };
2706
- var usedModels = ["rgb", "hex", "ansi256"];
2707
- for (const model of usedModels) {
2708
- styles2[model] = {
2709
- get() {
2710
- const { level } = this;
2711
- return function(...arguments_) {
2712
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2713
- return createBuilder(this, styler, this[IS_EMPTY]);
2714
- };
2715
- }
2716
- };
2717
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2718
- styles2[bgModel] = {
2719
- get() {
2720
- const { level } = this;
2721
- return function(...arguments_) {
2722
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2723
- return createBuilder(this, styler, this[IS_EMPTY]);
2724
- };
3171
+ try {
3172
+ const resp = await graphRequest({
3173
+ method: "GET",
3174
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/installs`,
3175
+ orgId
3176
+ });
3177
+ const orgs = resp.orgs || [];
3178
+ if (opts.json) {
3179
+ console.log(JSON.stringify(resp, null, 2));
3180
+ return;
2725
3181
  }
2726
- };
2727
- }
2728
- var proto = Object.defineProperties(() => {}, {
2729
- ...styles2,
2730
- level: {
2731
- enumerable: true,
2732
- get() {
2733
- return this[GENERATOR].level;
2734
- },
2735
- set(level) {
2736
- this[GENERATOR].level = level;
3182
+ if (orgs.length === 0) {
3183
+ console.log(source_default.dim(`No orgs have installed ${spaceId} yet.`));
3184
+ return;
2737
3185
  }
3186
+ console.log(source_default.bold(`Installs for ${spaceId}:`));
3187
+ for (const o of orgs)
3188
+ console.log(` ${o}`);
3189
+ console.log(source_default.dim(`
3190
+ Total: ${orgs.length}`));
3191
+ } catch (err) {
3192
+ fail2(err);
2738
3193
  }
3194
+ }
3195
+ function fail2(err) {
3196
+ const msg = err instanceof Error ? err.message : String(err);
3197
+ console.error(source_default.red(msg));
3198
+ process.exit(1);
3199
+ }
3200
+ var init_install = __esm(() => {
3201
+ init_source();
3202
+ init_graphClient();
2739
3203
  });
2740
- var createStyler = (open, close, parent) => {
2741
- let openAll;
2742
- let closeAll;
2743
- if (parent === undefined) {
2744
- openAll = open;
2745
- closeAll = close;
2746
- } else {
2747
- openAll = parent.openAll + open;
2748
- closeAll = close + parent.closeAll;
3204
+
3205
+ // src/commands/graph/distribution.ts
3206
+ var exports_distribution = {};
3207
+ __export(exports_distribution, {
3208
+ setDistribution: () => setDistribution,
3209
+ allowlistRemove: () => allowlistRemove,
3210
+ allowlistAdd: () => allowlistAdd
3211
+ });
3212
+ async function setDistribution(spaceId, mode, opts = {}) {
3213
+ const orgId = requireOrgId(opts.org);
3214
+ if (!spaceId || !mode) {
3215
+ console.error(source_default.red("Usage: construct graph distribution <space-id> <public|org_allowlist|private>"));
3216
+ process.exit(1);
2749
3217
  }
2750
- return {
2751
- open,
2752
- close,
2753
- openAll,
2754
- closeAll,
2755
- parent
2756
- };
2757
- };
2758
- var createBuilder = (self, _styler, _isEmpty) => {
2759
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2760
- Object.setPrototypeOf(builder, proto);
2761
- builder[GENERATOR] = self;
2762
- builder[STYLER] = _styler;
2763
- builder[IS_EMPTY] = _isEmpty;
2764
- return builder;
2765
- };
2766
- var applyStyle = (self, string) => {
2767
- if (self.level <= 0 || !string) {
2768
- return self[IS_EMPTY] ? "" : string;
3218
+ if (!VALID_MODES.includes(mode)) {
3219
+ console.error(source_default.red(`Invalid mode "${mode}". Expected one of: ${VALID_MODES.join(", ")}`));
3220
+ process.exit(1);
2769
3221
  }
2770
- let styler = self[STYLER];
2771
- if (styler === undefined) {
2772
- return string;
3222
+ try {
3223
+ const resp = await graphRequest({
3224
+ method: "PUT",
3225
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/distribution`,
3226
+ body: { distribution: mode },
3227
+ orgId
3228
+ });
3229
+ if (opts.json) {
3230
+ console.log(JSON.stringify(resp, null, 2));
3231
+ return;
3232
+ }
3233
+ console.log(source_default.green(`\u2713 ${source_default.cyan(spaceId)} distribution set to ${source_default.bold(resp.distribution)}`));
3234
+ if (mode === "org_allowlist") {
3235
+ console.log(source_default.dim(" Next: add allowed orgs with: construct graph allowlist add <space-id> <org-id>"));
3236
+ }
3237
+ } catch (err) {
3238
+ fail3(err);
2773
3239
  }
2774
- const { openAll, closeAll } = styler;
2775
- if (string.includes("\x1B")) {
2776
- while (styler !== undefined) {
2777
- string = stringReplaceAll(string, styler.close, styler.open);
2778
- styler = styler.parent;
3240
+ }
3241
+ async function allowlistAdd(spaceId, targetOrgId, opts = {}) {
3242
+ const orgId = requireOrgId(opts.org);
3243
+ if (!spaceId || !targetOrgId) {
3244
+ console.error(source_default.red("Usage: construct graph allowlist add <space-id> <org-id>"));
3245
+ process.exit(1);
3246
+ }
3247
+ try {
3248
+ await graphRequest({
3249
+ method: "POST",
3250
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/allowlist`,
3251
+ body: { org_id: targetOrgId },
3252
+ orgId
3253
+ });
3254
+ if (opts.json) {
3255
+ console.log(JSON.stringify({ ok: true, space_id: spaceId, org_id: targetOrgId }, null, 2));
3256
+ return;
2779
3257
  }
3258
+ console.log(source_default.green(`\u2713 Added ${source_default.cyan(targetOrgId)} to ${spaceId} allowlist`));
3259
+ } catch (err) {
3260
+ fail3(err);
2780
3261
  }
2781
- const lfIndex = string.indexOf(`
2782
- `);
2783
- if (lfIndex !== -1) {
2784
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
3262
+ }
3263
+ async function allowlistRemove(spaceId, targetOrgId, opts = {}) {
3264
+ const orgId = requireOrgId(opts.org);
3265
+ if (!spaceId || !targetOrgId) {
3266
+ console.error(source_default.red("Usage: construct graph allowlist rm <space-id> <org-id>"));
3267
+ process.exit(1);
2785
3268
  }
2786
- return openAll + string + closeAll;
2787
- };
2788
- Object.defineProperties(createChalk.prototype, styles2);
2789
- var chalk = createChalk();
2790
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
2791
- var source_default = chalk;
3269
+ try {
3270
+ await graphRequest({
3271
+ method: "DELETE",
3272
+ path: `/api/spaces/${encodeURIComponent(spaceId)}/allowlist`,
3273
+ body: { org_id: targetOrgId },
3274
+ orgId
3275
+ });
3276
+ if (opts.json) {
3277
+ console.log(JSON.stringify({ ok: true }, null, 2));
3278
+ return;
3279
+ }
3280
+ console.log(source_default.green(`\u2713 Removed ${source_default.cyan(targetOrgId)} from ${spaceId} allowlist`));
3281
+ console.log(source_default.dim(" Existing installs by this org are preserved \u2014 uninstall separately if needed."));
3282
+ } catch (err) {
3283
+ fail3(err);
3284
+ }
3285
+ }
3286
+ function fail3(err) {
3287
+ const msg = err instanceof Error ? err.message : String(err);
3288
+ console.error(source_default.red(msg));
3289
+ process.exit(1);
3290
+ }
3291
+ var VALID_MODES;
3292
+ var init_distribution = __esm(() => {
3293
+ init_source();
3294
+ init_graphClient();
3295
+ VALID_MODES = ["public", "org_allowlist", "private"];
3296
+ });
3297
+
3298
+ // node_modules/commander/esm.mjs
3299
+ var import__ = __toESM(require_commander(), 1);
3300
+ var {
3301
+ program,
3302
+ createCommand,
3303
+ createArgument,
3304
+ createOption,
3305
+ CommanderError,
3306
+ InvalidArgumentError,
3307
+ InvalidOptionArgumentError,
3308
+ Command,
3309
+ Argument,
3310
+ Option,
3311
+ Help
3312
+ } = import__.default;
3313
+
3314
+ // src/commands/scaffold.ts
3315
+ init_source();
3316
+ import { mkdirSync, writeFileSync, existsSync as existsSync2, readFileSync } from "fs";
3317
+ import { join as join2, dirname } from "path";
2792
3318
 
2793
3319
  // node_modules/@inquirer/core/dist/lib/key.js
2794
3320
  var isUpKey = (key, keybindings = []) => key.name === "up" || keybindings.includes("vim") && key.name === "k" || keybindings.includes("emacs") && key.ctrl && key.name === "p";
@@ -4694,11 +5220,13 @@ async function scaffold(nameArg, options) {
4694
5220
  }
4695
5221
 
4696
5222
  // src/commands/build.ts
5223
+ init_source();
4697
5224
  import { existsSync as existsSync6, readFileSync as readFileSync4, readdirSync as readdirSync3, renameSync, statSync as statSync3 } from "fs";
4698
5225
  import { join as join6 } from "path";
4699
5226
  import { createHash } from "crypto";
4700
5227
 
4701
5228
  // node_modules/ora/index.js
5229
+ init_source();
4702
5230
  import process9 from "process";
4703
5231
  import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
4704
5232
 
@@ -7683,6 +8211,7 @@ async function build(options) {
7683
8211
  }
7684
8212
 
7685
8213
  // src/commands/dev.ts
8214
+ init_source();
7686
8215
  import { existsSync as existsSync7, readFileSync as readFileSync5 } from "fs";
7687
8216
  import { join as join9 } from "path";
7688
8217
  import { createHash as createHash2 } from "crypto";
@@ -9368,41 +9897,10 @@ async function dev() {
9368
9897
  }
9369
9898
 
9370
9899
  // src/commands/run.ts
9900
+ init_source();
9371
9901
  import { existsSync as existsSync8, cpSync, mkdirSync as mkdirSync3 } from "fs";
9372
9902
  import { join as join11 } from "path";
9373
-
9374
- // src/lib/appdir.ts
9375
- import { join as join10 } from "path";
9376
- import { homedir } from "os";
9377
- import { platform } from "process";
9378
- function dataDir() {
9379
- if (process.env.CONSTRUCT_DATA_DIR)
9380
- return process.env.CONSTRUCT_DATA_DIR;
9381
- const home = homedir();
9382
- switch (platform) {
9383
- case "darwin":
9384
- return join10(home, "Library", "Application Support", "Construct");
9385
- case "win32": {
9386
- const appData = process.env.APPDATA || join10(home, "AppData", "Roaming");
9387
- return join10(appData, "Construct");
9388
- }
9389
- default: {
9390
- const xdg = process.env.XDG_DATA_HOME || join10(home, ".local", "share");
9391
- return join10(xdg, "construct");
9392
- }
9393
- }
9394
- }
9395
- function spacesDir() {
9396
- return join10(dataDir(), "spaces");
9397
- }
9398
- function profilesDir() {
9399
- return join10(dataDir(), "profiles");
9400
- }
9401
- function spaceDir(spaceId) {
9402
- return join10(spacesDir(), spaceId);
9403
- }
9404
-
9405
- // src/commands/run.ts
9903
+ init_appdir();
9406
9904
  function install() {
9407
9905
  const root = process.cwd();
9408
9906
  if (!exists(root)) {
@@ -9427,76 +9925,10 @@ function install() {
9427
9925
  }
9428
9926
 
9429
9927
  // src/commands/publish.ts
9928
+ init_source();
9430
9929
  import { readFileSync as readFileSync7, writeFileSync as writeFileSync6, statSync as statSync6, unlinkSync as unlinkSync2 } from "fs";
9431
9930
  import { join as join14, basename as basename6 } from "path";
9432
-
9433
- // src/lib/auth.ts
9434
- import { readFileSync as readFileSync6, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4, unlinkSync, existsSync as existsSync9, readdirSync as readdirSync4, statSync as statSync4 } from "fs";
9435
- import { join as join12, dirname as dirname4 } from "path";
9436
- var CREDENTIALS_FILE = "credentials.json";
9437
- var DEFAULT_PORTAL = "https://my.construct.space/api/developer";
9438
- function listDesktopProfiles() {
9439
- const dir = profilesDir();
9440
- if (!existsSync9(dir))
9441
- return [];
9442
- const results = [];
9443
- for (const entry of readdirSync4(dir)) {
9444
- const full = join12(dir, entry);
9445
- try {
9446
- if (!statSync4(full).isDirectory())
9447
- continue;
9448
- const authPath = join12(full, "auth.json");
9449
- if (!existsSync9(authPath))
9450
- continue;
9451
- const data = JSON.parse(readFileSync6(authPath, "utf-8"));
9452
- if (!data.token)
9453
- continue;
9454
- if (data.authenticated !== undefined && !data.authenticated)
9455
- continue;
9456
- results.push({
9457
- id: entry,
9458
- token: data.token,
9459
- user: data.user,
9460
- updatedAt: data.updated_at,
9461
- authenticated: true
9462
- });
9463
- } catch {}
9464
- }
9465
- return results;
9466
- }
9467
- function credentialsPath() {
9468
- return join12(dataDir(), CREDENTIALS_FILE);
9469
- }
9470
- function store(creds) {
9471
- const path = credentialsPath();
9472
- mkdirSync4(dirname4(path), { recursive: true });
9473
- writeFileSync5(path, JSON.stringify(creds, null, 2) + `
9474
- `, { mode: 384 });
9475
- }
9476
- function load2() {
9477
- const path = credentialsPath();
9478
- if (!existsSync9(path)) {
9479
- throw new Error("not logged in \u2014 run 'construct login' first");
9480
- }
9481
- const data = JSON.parse(readFileSync6(path, "utf-8"));
9482
- if (!data.token) {
9483
- throw new Error("not logged in \u2014 run 'construct login' first");
9484
- }
9485
- return data;
9486
- }
9487
- function isAuthenticated() {
9488
- try {
9489
- load2();
9490
- return true;
9491
- } catch {
9492
- return false;
9493
- }
9494
- }
9495
- function clear() {
9496
- const path = credentialsPath();
9497
- if (existsSync9(path))
9498
- unlinkSync(path);
9499
- }
9931
+ init_auth();
9500
9932
 
9501
9933
  // src/lib/pack.ts
9502
9934
  import { readdirSync as readdirSync5, statSync as statSync5, existsSync as existsSync10 } from "fs";
@@ -9751,6 +10183,7 @@ async function publish(options) {
9751
10183
  }
9752
10184
 
9753
10185
  // src/commands/validate.ts
10186
+ init_source();
9754
10187
  import { existsSync as existsSync11, readFileSync as readFileSync8 } from "fs";
9755
10188
  import { join as join15 } from "path";
9756
10189
  function validate3() {
@@ -9799,6 +10232,7 @@ function validate3() {
9799
10232
  }
9800
10233
 
9801
10234
  // src/commands/check.ts
10235
+ init_source();
9802
10236
  import { execSync as execSync4 } from "child_process";
9803
10237
  import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
9804
10238
  import { join as join16 } from "path";
@@ -9862,6 +10296,7 @@ function check() {
9862
10296
  }
9863
10297
 
9864
10298
  // src/commands/clean.ts
10299
+ init_source();
9865
10300
  import { rmSync, existsSync as existsSync13 } from "fs";
9866
10301
  import { join as join17 } from "path";
9867
10302
  function clean(options) {
@@ -9891,6 +10326,8 @@ function clean(options) {
9891
10326
  }
9892
10327
 
9893
10328
  // src/commands/login.ts
10329
+ init_source();
10330
+ init_auth();
9894
10331
  var ACCOUNTS_SCOPE_URL = "https://my.construct.space/api/accounts/me/scope";
9895
10332
  async function login(options) {
9896
10333
  if (isAuthenticated()) {
@@ -9982,6 +10419,7 @@ function logout() {
9982
10419
  }
9983
10420
 
9984
10421
  // src/commands/update.ts
10422
+ init_source();
9985
10423
  import { execSync as execSync5 } from "child_process";
9986
10424
  var PKG_NAME = "@construct-space/cli";
9987
10425
  function update() {
@@ -10010,6 +10448,7 @@ function update() {
10010
10448
  }
10011
10449
 
10012
10450
  // src/commands/graph/init.ts
10451
+ init_source();
10013
10452
  import { existsSync as existsSync14, readFileSync as readFileSync10, writeFileSync as writeFileSync7, mkdirSync as mkdirSync5 } from "fs";
10014
10453
  import { join as join18 } from "path";
10015
10454
  import { execSync as execSync6 } from "child_process";
@@ -10063,6 +10502,7 @@ function graphInit() {
10063
10502
  }
10064
10503
 
10065
10504
  // src/commands/graph/generate.ts
10505
+ init_source();
10066
10506
  import { existsSync as existsSync15, readFileSync as readFileSync11, writeFileSync as writeFileSync8, mkdirSync as mkdirSync6 } from "fs";
10067
10507
  import { join as join19 } from "path";
10068
10508
  var FIELD_TYPES = {
@@ -10253,8 +10693,10 @@ function updateBarrel(modelsDir, modelName) {
10253
10693
  }
10254
10694
 
10255
10695
  // src/commands/graph/push.ts
10696
+ init_source();
10256
10697
  import { existsSync as existsSync16, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "fs";
10257
10698
  import { join as join20, basename as basename7 } from "path";
10699
+ init_auth();
10258
10700
  async function graphPush() {
10259
10701
  const root = process.cwd();
10260
10702
  if (!exists(root)) {
@@ -10296,20 +10738,29 @@ async function graphPush() {
10296
10738
  const spinner = ora("Registering models...").start();
10297
10739
  try {
10298
10740
  const userID = creds.user?.id || "";
10741
+ const dataManifest = { version: 1, models };
10742
+ if (m.graph?.bundle_id)
10743
+ dataManifest.bundle_id = m.graph.bundle_id;
10744
+ if (m.graph?.imports && m.graph.imports.length > 0)
10745
+ dataManifest.imports = m.graph.imports;
10746
+ const headers = {
10747
+ "Content-Type": "application/json",
10748
+ Authorization: `Bearer ${creds.token}`,
10749
+ "X-Space-ID": m.id,
10750
+ "X-Auth-User-ID": userID
10751
+ };
10752
+ const pushOrgID = process.env.CONSTRUCT_ORG_ID;
10753
+ if (pushOrgID)
10754
+ headers["X-Auth-Org-ID"] = pushOrgID;
10299
10755
  const resp = await fetch(`${graphURL}/api/schemas/register`, {
10300
10756
  method: "POST",
10301
- headers: {
10302
- "Content-Type": "application/json",
10303
- Authorization: `Bearer ${creds.token}`,
10304
- "X-Space-ID": m.id,
10305
- "X-Auth-User-ID": userID
10306
- },
10757
+ headers,
10307
10758
  body: JSON.stringify({
10308
10759
  space_id: m.id,
10309
10760
  space_name: m.name,
10310
10761
  project_id: "default",
10311
10762
  version: m.version || "0.0.1",
10312
- manifest: { version: 1, models }
10763
+ manifest: dataManifest
10313
10764
  })
10314
10765
  });
10315
10766
  if (resp.status === 403) {
@@ -10408,8 +10859,10 @@ function parseModelFile(content, fileName) {
10408
10859
  }
10409
10860
 
10410
10861
  // src/commands/graph/migrate.ts
10862
+ init_source();
10411
10863
  import { existsSync as existsSync17, readdirSync as readdirSync7, readFileSync as readFileSync13 } from "fs";
10412
10864
  import { join as join21, basename as basename8 } from "path";
10865
+ init_auth();
10413
10866
  async function graphMigrate(options) {
10414
10867
  const root = process.cwd();
10415
10868
  if (!exists(root)) {
@@ -10571,6 +11024,18 @@ graph.command("init").description("Initialize Graph in a space project").action(
10571
11024
  graph.command("generate <model> [fields...]").alias("g").description("Generate a data model").option("--access <rules>", "Access rules (e.g. read:member,create:member,update:owner,delete:admin)").action((model, fields, opts) => generate2(model, fields, opts));
10572
11025
  graph.command("push").description("Register models with the Graph service").action(async () => graphPush());
10573
11026
  graph.command("migrate").description("Compare local models with server schema and apply changes").option("--apply", "Apply destructive changes (drop columns, alter constraints)").action(async (opts) => graphMigrate(opts));
11027
+ graph.command("spaces").alias("list").alias("ls").description("List spaces published by your org").option("--org <id>", "Override org id").option("--bundle <id>", "Filter to a single bundle").option("--json", "Output JSON").action(async (opts) => (await Promise.resolve().then(() => (init_spaces(), exports_spaces))).spacesList(opts));
11028
+ var bundles = graph.command("bundles").description("Manage space bundles (publisher grouping)");
11029
+ bundles.command("list").description("List bundles owned by your org").option("--org <id>", "Override org id (default: $CONSTRUCT_ORG_ID)").option("--json", "Output JSON").action(async (opts) => (await Promise.resolve().then(() => (init_bundles(), exports_bundles))).bundlesList(opts));
11030
+ bundles.command("create <id> <name>").description("Create a new bundle owned by your org").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (id, name, opts) => (await Promise.resolve().then(() => (init_bundles(), exports_bundles))).bundleCreate(id, name, opts));
11031
+ bundles.command("show <id>").description("Show a bundle by id").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (id, opts) => (await Promise.resolve().then(() => (init_bundles(), exports_bundles))).bundleShow(id, opts));
11032
+ graph.command("install <space-id>").description("Install a space for your org").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (spaceId, opts) => (await Promise.resolve().then(() => (init_install(), exports_install))).installSpace(spaceId, opts));
11033
+ graph.command("uninstall <space-id>").description("Uninstall a space for your org (data preserved)").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (spaceId, opts) => (await Promise.resolve().then(() => (init_install(), exports_install))).uninstallSpace(spaceId, opts));
11034
+ graph.command("installs <space-id>").description("List orgs that installed a space (publisher only)").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (spaceId, opts) => (await Promise.resolve().then(() => (init_install(), exports_install))).installsList(spaceId, opts));
11035
+ graph.command("distribution <space-id> <mode>").description("Set distribution: public | org_allowlist | private").option("--org <id>", "Override org id").option("--json", "Output JSON").action(async (spaceId, mode, opts) => (await Promise.resolve().then(() => (init_distribution(), exports_distribution))).setDistribution(spaceId, mode, opts));
11036
+ var allow = graph.command("allowlist").description("Manage which orgs may install org_allowlist-mode spaces");
11037
+ allow.command("add <space-id> <org-id>").description("Grant an org permission to install the space").option("--org <id>", "Override caller org id").option("--json", "Output JSON").action(async (spaceId, orgId, opts) => (await Promise.resolve().then(() => (init_distribution(), exports_distribution))).allowlistAdd(spaceId, orgId, opts));
11038
+ allow.command("rm <space-id> <org-id>").alias("remove").description("Revoke an org from the install allowlist").option("--org <id>", "Override caller org id").option("--json", "Output JSON").action(async (spaceId, orgId, opts) => (await Promise.resolve().then(() => (init_distribution(), exports_distribution))).allowlistRemove(spaceId, orgId, opts));
10574
11039
  var space = program2.command("space").description("Space development commands");
10575
11040
  space.command("scaffold [name]").alias("new").alias("create").option("--with-tests", "Include E2E testing boilerplate").option("--full", "Full preset: multiple pages, extra skills, widget templates").action(async (name, opts) => scaffold(name, opts));
10576
11041
  space.command("build").option("--entry-only").action(async (opts) => build(opts));