@supacloud/cli 0.38.0 → 0.39.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 (2) hide show
  1. package/dist/index.js +1191 -10
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -238452,20 +238452,20 @@ async function runCli(cliTools, args, options = {}) {
238452
238452
  const shape = getSchemaShape(tool2.schema);
238453
238453
  const actionField = shape.action;
238454
238454
  const actionOptions = getEnumOptions(actionField);
238455
+ const actionless = toolName2 === "deploy";
238455
238456
  const otherFields = Object.entries(shape).filter(([name]) => name !== "action");
238456
238457
  const actionLines = actionOptions.length ? `Available actions:
238457
238458
  ${actionOptions.join(`
238458
- `)}` : "This command does not declare action metadata.";
238459
+ `)}` : actionless ? "" : "This command does not declare action metadata.";
238459
238460
  const argLines = otherFields.length ? otherFields.map(([name, field]) => {
238460
238461
  const description = getDescription(field) || "(no description)";
238461
238462
  return ` --${name} ${description}`;
238462
238463
  }).join(`
238463
238464
  `) : " (no additional flags)";
238464
238465
  return [
238465
- `Usage: ${commandName} ${toolName2} <action> [--flags]`,
238466
- "",
238467
- actionLines,
238466
+ `Usage: ${commandName} ${toolName2}${actionless ? "" : " <action>"} [--flags]`,
238468
238467
  "",
238468
+ ...actionLines ? [actionLines, ""] : [],
238469
238469
  "Flags:",
238470
238470
  argLines
238471
238471
  ].join(`
@@ -238764,6 +238764,7 @@ function resolveSupaCloudContext(env = process.env, cwd = process.cwd(), selecti
238764
238764
 
238765
238765
  // src/shared/execution-policy.ts
238766
238766
  var ACTION_POLICY = {
238767
+ deploy: { write: ["deploy"] },
238767
238768
  project: {
238768
238769
  read: ["get", "endpoints", "health", "logs", "api_keys", "settings", "tasks", "task_detail", "task_stats", "dlq", "background_settings"],
238769
238770
  write: ["pause", "restore", "task_cancel", "task_retry", "update_background_settings"],
@@ -238850,6 +238851,8 @@ function declaredMode(moduleName, action) {
238850
238851
  return;
238851
238852
  }
238852
238853
  function executionMode(moduleName, action, args) {
238854
+ if (moduleName === "deploy" && args.dry_run === true)
238855
+ return "read";
238853
238856
  if (moduleName === "database" && ["push_migrations", "baseline_migrations"].includes(action) && args.dry_run === true)
238854
238857
  return "read";
238855
238858
  if (moduleName === "supabase" && action === "push" && args.dry_run === true)
@@ -238857,7 +238860,7 @@ function executionMode(moduleName, action, args) {
238857
238860
  return declaredMode(moduleName, action);
238858
238861
  }
238859
238862
  function authorizeExecution(moduleName, args, authorization) {
238860
- const action = typeof args.action === "string" ? args.action : "";
238863
+ const action = typeof args.action === "string" ? args.action : moduleName === "deploy" ? "deploy" : "";
238861
238864
  if (!action)
238862
238865
  return;
238863
238866
  const mode = executionMode(moduleName, action, args);
@@ -249451,10 +249454,1166 @@ function registerReleaseTools(server2, http, options = {}) {
249451
249454
  });
249452
249455
  });
249453
249456
  }
249457
+
249458
+ // src/shared/tools/deploy-tools.ts
249459
+ import { access, lstat, mkdtemp, opendir, readFile as readFile2, rm, writeFile as writeFile3 } from "node:fs/promises";
249460
+ import { createHash as createHash4 } from "node:crypto";
249461
+ import { tmpdir as tmpdir2 } from "node:os";
249462
+ import { basename as basename4, dirname as dirname4, join as join9, relative as relative4, resolve as resolve10, sep as sep4 } from "node:path";
249463
+ import { spawn as spawn3 } from "node:child_process";
249464
+
249465
+ // node_modules/fflate/esm/index.mjs
249466
+ import { createRequire as createRequire2 } from "module";
249467
+ var require2 = createRequire2("/");
249468
+ var _a;
249469
+ var Worker;
249470
+ var isMarkedAsUntransferable;
249471
+ try {
249472
+ _a = require2("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
249473
+ } catch (e) {}
249474
+ var u8 = Uint8Array;
249475
+ var u16 = Uint16Array;
249476
+ var i32 = Int32Array;
249477
+ var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]);
249478
+ var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]);
249479
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
249480
+ var freb = function(eb, start) {
249481
+ var b = new u16(31);
249482
+ for (var i = 0;i < 31; ++i) {
249483
+ b[i] = start += 1 << eb[i - 1];
249484
+ }
249485
+ var r = new i32(b[30]);
249486
+ for (var i = 1;i < 30; ++i) {
249487
+ for (var j = b[i];j < b[i + 1]; ++j) {
249488
+ r[j] = j - b[i] << 5 | i;
249489
+ }
249490
+ }
249491
+ return { b, r };
249492
+ };
249493
+ var _a = freb(fleb, 2);
249494
+ var fl = _a.b;
249495
+ var revfl = _a.r;
249496
+ fl[28] = 258, revfl[258] = 28;
249497
+ var _b = freb(fdeb, 0);
249498
+ var fd = _b.b;
249499
+ var revfd = _b.r;
249500
+ var rev = new u16(32768);
249501
+ for (i = 0;i < 32768; ++i) {
249502
+ x = (i & 43690) >> 1 | (i & 21845) << 1;
249503
+ x = (x & 52428) >> 2 | (x & 13107) << 2;
249504
+ x = (x & 61680) >> 4 | (x & 3855) << 4;
249505
+ rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
249506
+ }
249507
+ var x;
249508
+ var i;
249509
+ var hMap = function(cd, mb, r) {
249510
+ var s = cd.length;
249511
+ var i2 = 0;
249512
+ var l = new u16(mb);
249513
+ for (;i2 < s; ++i2) {
249514
+ if (cd[i2])
249515
+ ++l[cd[i2] - 1];
249516
+ }
249517
+ var le = new u16(mb);
249518
+ for (i2 = 1;i2 < mb; ++i2) {
249519
+ le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
249520
+ }
249521
+ var co;
249522
+ if (r) {
249523
+ co = new u16(1 << mb);
249524
+ var rvb = 15 - mb;
249525
+ for (i2 = 0;i2 < s; ++i2) {
249526
+ if (cd[i2]) {
249527
+ var sv = i2 << 4 | cd[i2];
249528
+ var r_1 = mb - cd[i2];
249529
+ var v = le[cd[i2] - 1]++ << r_1;
249530
+ for (var m = v | (1 << r_1) - 1;v <= m; ++v) {
249531
+ co[rev[v] >> rvb] = sv;
249532
+ }
249533
+ }
249534
+ }
249535
+ } else {
249536
+ co = new u16(s);
249537
+ for (i2 = 0;i2 < s; ++i2) {
249538
+ if (cd[i2]) {
249539
+ co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
249540
+ }
249541
+ }
249542
+ }
249543
+ return co;
249544
+ };
249545
+ var flt = new u8(288);
249546
+ for (i = 0;i < 144; ++i)
249547
+ flt[i] = 8;
249548
+ var i;
249549
+ for (i = 144;i < 256; ++i)
249550
+ flt[i] = 9;
249551
+ var i;
249552
+ for (i = 256;i < 280; ++i)
249553
+ flt[i] = 7;
249554
+ var i;
249555
+ for (i = 280;i < 288; ++i)
249556
+ flt[i] = 8;
249557
+ var i;
249558
+ var fdt = new u8(32);
249559
+ for (i = 0;i < 32; ++i)
249560
+ fdt[i] = 5;
249561
+ var i;
249562
+ var flm = /* @__PURE__ */ hMap(flt, 9, 0);
249563
+ var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
249564
+ var shft = function(p) {
249565
+ return (p + 7) / 8 | 0;
249566
+ };
249567
+ var slc = function(v, s, e) {
249568
+ if (s == null || s < 0)
249569
+ s = 0;
249570
+ if (e == null || e > v.length)
249571
+ e = v.length;
249572
+ return new u8(v.subarray(s, e));
249573
+ };
249574
+ var ec = [
249575
+ "unexpected EOF",
249576
+ "invalid block type",
249577
+ "invalid length/literal",
249578
+ "invalid distance",
249579
+ "stream finished",
249580
+ "no stream handler",
249581
+ ,
249582
+ "no callback",
249583
+ "invalid UTF-8 data",
249584
+ "extra field too long",
249585
+ "date not in range 1980-2099",
249586
+ "filename too long",
249587
+ "stream finishing",
249588
+ "invalid zip data"
249589
+ ];
249590
+ var err = function(ind, msg, nt) {
249591
+ var e = new Error(msg || ec[ind]);
249592
+ e.code = ind;
249593
+ if (Error.captureStackTrace)
249594
+ Error.captureStackTrace(e, err);
249595
+ if (!nt)
249596
+ throw e;
249597
+ return e;
249598
+ };
249599
+ var wbits = function(d, p, v) {
249600
+ v <<= p & 7;
249601
+ var o = p / 8 | 0;
249602
+ d[o] |= v;
249603
+ d[o + 1] |= v >> 8;
249604
+ };
249605
+ var wbits16 = function(d, p, v) {
249606
+ v <<= p & 7;
249607
+ var o = p / 8 | 0;
249608
+ d[o] |= v;
249609
+ d[o + 1] |= v >> 8;
249610
+ d[o + 2] |= v >> 16;
249611
+ };
249612
+ var hTree = function(d, mb) {
249613
+ var t = [];
249614
+ for (var i2 = 0;i2 < d.length; ++i2) {
249615
+ if (d[i2])
249616
+ t.push({ s: i2, f: d[i2] });
249617
+ }
249618
+ var s = t.length;
249619
+ var t2 = t.slice();
249620
+ if (!s)
249621
+ return { t: et, l: 0 };
249622
+ if (s == 1) {
249623
+ var v = new u8(t[0].s + 1);
249624
+ v[t[0].s] = 1;
249625
+ return { t: v, l: 1 };
249626
+ }
249627
+ t.sort(function(a, b) {
249628
+ return a.f - b.f;
249629
+ });
249630
+ t.push({ s: -1, f: 25001 });
249631
+ var l = t[0], r = t[1], i0 = 0, i1 = 1, i22 = 2;
249632
+ t[0] = { s: -1, f: l.f + r.f, l, r };
249633
+ while (i1 != s - 1) {
249634
+ l = t[t[i0].f < t[i22].f ? i0++ : i22++];
249635
+ r = t[i0 != i1 && t[i0].f < t[i22].f ? i0++ : i22++];
249636
+ t[i1++] = { s: -1, f: l.f + r.f, l, r };
249637
+ }
249638
+ var maxSym = t2[0].s;
249639
+ for (var i2 = 1;i2 < s; ++i2) {
249640
+ if (t2[i2].s > maxSym)
249641
+ maxSym = t2[i2].s;
249642
+ }
249643
+ var tr = new u16(maxSym + 1);
249644
+ var mbt = ln(t[i1 - 1], tr, 0);
249645
+ if (mbt > mb) {
249646
+ var i2 = 0, dt = 0;
249647
+ var lft = mbt - mb, cst = 1 << lft;
249648
+ t2.sort(function(a, b) {
249649
+ return tr[b.s] - tr[a.s] || a.f - b.f;
249650
+ });
249651
+ for (;i2 < s; ++i2) {
249652
+ var i2_1 = t2[i2].s;
249653
+ if (tr[i2_1] > mb) {
249654
+ dt += cst - (1 << mbt - tr[i2_1]);
249655
+ tr[i2_1] = mb;
249656
+ } else
249657
+ break;
249658
+ }
249659
+ dt >>= lft;
249660
+ while (dt > 0) {
249661
+ var i2_2 = t2[i2].s;
249662
+ if (tr[i2_2] < mb)
249663
+ dt -= 1 << mb - tr[i2_2]++ - 1;
249664
+ else
249665
+ ++i2;
249666
+ }
249667
+ for (;i2 >= 0 && dt; --i2) {
249668
+ var i2_3 = t2[i2].s;
249669
+ if (tr[i2_3] == mb) {
249670
+ --tr[i2_3];
249671
+ ++dt;
249672
+ }
249673
+ }
249674
+ mbt = mb;
249675
+ }
249676
+ return { t: new u8(tr), l: mbt };
249677
+ };
249678
+ var ln = function(n, l, d) {
249679
+ return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
249680
+ };
249681
+ var lc = function(c) {
249682
+ var s = c.length;
249683
+ while (s && !c[--s])
249684
+ ;
249685
+ var cl = new u16(++s);
249686
+ var cli = 0, cln = c[0], cls = 1;
249687
+ var w = function(v) {
249688
+ cl[cli++] = v;
249689
+ };
249690
+ for (var i2 = 1;i2 <= s; ++i2) {
249691
+ if (c[i2] == cln && i2 != s)
249692
+ ++cls;
249693
+ else {
249694
+ if (!cln && cls > 2) {
249695
+ for (;cls > 138; cls -= 138)
249696
+ w(32754);
249697
+ if (cls > 2) {
249698
+ w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
249699
+ cls = 0;
249700
+ }
249701
+ } else if (cls > 3) {
249702
+ w(cln), --cls;
249703
+ for (;cls > 6; cls -= 6)
249704
+ w(8304);
249705
+ if (cls > 2)
249706
+ w(cls - 3 << 5 | 8208), cls = 0;
249707
+ }
249708
+ while (cls--)
249709
+ w(cln);
249710
+ cls = 1;
249711
+ cln = c[i2];
249712
+ }
249713
+ }
249714
+ return { c: cl.subarray(0, cli), n: s };
249715
+ };
249716
+ var clen = function(cf, cl) {
249717
+ var l = 0;
249718
+ for (var i2 = 0;i2 < cl.length; ++i2)
249719
+ l += cf[i2] * cl[i2];
249720
+ return l;
249721
+ };
249722
+ var wfblk = function(out, pos, dat) {
249723
+ var s = dat.length;
249724
+ var o = shft(pos + 2);
249725
+ out[o] = s & 255;
249726
+ out[o + 1] = s >> 8;
249727
+ out[o + 2] = out[o] ^ 255;
249728
+ out[o + 3] = out[o + 1] ^ 255;
249729
+ for (var i2 = 0;i2 < s; ++i2)
249730
+ out[o + i2 + 4] = dat[i2];
249731
+ return (o + 4 + s) * 8;
249732
+ };
249733
+ var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
249734
+ wbits(out, p++, final);
249735
+ ++lf[256];
249736
+ var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
249737
+ var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
249738
+ var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
249739
+ var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
249740
+ var lcfreq = new u16(19);
249741
+ for (var i2 = 0;i2 < lclt.length; ++i2)
249742
+ ++lcfreq[lclt[i2] & 31];
249743
+ for (var i2 = 0;i2 < lcdt.length; ++i2)
249744
+ ++lcfreq[lcdt[i2] & 31];
249745
+ var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
249746
+ var nlcc = 19;
249747
+ for (;nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
249748
+ ;
249749
+ var flen = bl + 5 << 3;
249750
+ var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
249751
+ var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
249752
+ if (bs >= 0 && flen <= ftlen && flen <= dtlen)
249753
+ return wfblk(out, p, dat.subarray(bs, bs + bl));
249754
+ var lm, ll, dm, dl;
249755
+ wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
249756
+ if (dtlen < ftlen) {
249757
+ lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
249758
+ var llm = hMap(lct, mlcb, 0);
249759
+ wbits(out, p, nlc - 257);
249760
+ wbits(out, p + 5, ndc - 1);
249761
+ wbits(out, p + 10, nlcc - 4);
249762
+ p += 14;
249763
+ for (var i2 = 0;i2 < nlcc; ++i2)
249764
+ wbits(out, p + 3 * i2, lct[clim[i2]]);
249765
+ p += 3 * nlcc;
249766
+ var lcts = [lclt, lcdt];
249767
+ for (var it = 0;it < 2; ++it) {
249768
+ var clct = lcts[it];
249769
+ for (var i2 = 0;i2 < clct.length; ++i2) {
249770
+ var len = clct[i2] & 31;
249771
+ wbits(out, p, llm[len]), p += lct[len];
249772
+ if (len > 15)
249773
+ wbits(out, p, clct[i2] >> 5 & 127), p += clct[i2] >> 12;
249774
+ }
249775
+ }
249776
+ } else {
249777
+ lm = flm, ll = flt, dm = fdm, dl = fdt;
249778
+ }
249779
+ for (var i2 = 0;i2 < li; ++i2) {
249780
+ var sym = syms[i2];
249781
+ if (sym > 255) {
249782
+ var len = sym >> 18 & 31;
249783
+ wbits16(out, p, lm[len + 257]), p += ll[len + 257];
249784
+ if (len > 7)
249785
+ wbits(out, p, sym >> 23 & 31), p += fleb[len];
249786
+ var dst = sym & 31;
249787
+ wbits16(out, p, dm[dst]), p += dl[dst];
249788
+ if (dst > 3)
249789
+ wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
249790
+ } else {
249791
+ wbits16(out, p, lm[sym]), p += ll[sym];
249792
+ }
249793
+ }
249794
+ wbits16(out, p, lm[256]);
249795
+ return p + ll[256];
249796
+ };
249797
+ var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
249798
+ var et = /* @__PURE__ */ new u8(0);
249799
+ var dflt = function(dat, lvl, plvl, pre, post, st) {
249800
+ var s = st.z || dat.length;
249801
+ var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
249802
+ var w = o.subarray(pre, o.length - post);
249803
+ var lst = st.l;
249804
+ var pos = (st.r || 0) & 7;
249805
+ if (lvl) {
249806
+ if (pos)
249807
+ w[0] = st.r >> 3;
249808
+ var opt = deo[lvl - 1];
249809
+ var n = opt >> 13, c = opt & 8191;
249810
+ var msk_1 = (1 << plvl) - 1;
249811
+ var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
249812
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
249813
+ var hsh = function(i3) {
249814
+ return (dat[i3] ^ dat[i3 + 1] << bs1_1 ^ dat[i3 + 2] << bs2_1) & msk_1;
249815
+ };
249816
+ var syms = new i32(25000);
249817
+ var lf = new u16(288), df = new u16(32);
249818
+ var lc_1 = 0, eb = 0, i2 = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
249819
+ for (;i2 + 2 < s; ++i2) {
249820
+ var hv = hsh(i2);
249821
+ var imod = i2 & 32767, pimod = head[hv];
249822
+ prev[imod] = pimod;
249823
+ head[hv] = imod;
249824
+ if (wi <= i2) {
249825
+ var rem = s - i2;
249826
+ if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
249827
+ pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
249828
+ li = lc_1 = eb = 0, bs = i2;
249829
+ for (var j = 0;j < 286; ++j)
249830
+ lf[j] = 0;
249831
+ for (var j = 0;j < 30; ++j)
249832
+ df[j] = 0;
249833
+ }
249834
+ var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
249835
+ if (rem > 2 && hv == hsh(i2 - dif)) {
249836
+ var maxn = Math.min(n, rem) - 1;
249837
+ var maxd = Math.min(32767, i2);
249838
+ var ml = Math.min(258, rem);
249839
+ while (dif <= maxd && --ch_1 && imod != pimod) {
249840
+ if (dat[i2 + l] == dat[i2 + l - dif]) {
249841
+ var nl = 0;
249842
+ for (;nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
249843
+ ;
249844
+ if (nl > l) {
249845
+ l = nl, d = dif;
249846
+ if (nl > maxn)
249847
+ break;
249848
+ var mmd = Math.min(dif, nl - 2);
249849
+ var md = 0;
249850
+ for (var j = 0;j < mmd; ++j) {
249851
+ var ti = i2 - dif + j & 32767;
249852
+ var pti = prev[ti];
249853
+ var cd = ti - pti & 32767;
249854
+ if (cd > md)
249855
+ md = cd, pimod = ti;
249856
+ }
249857
+ }
249858
+ }
249859
+ imod = pimod, pimod = prev[imod];
249860
+ dif += imod - pimod & 32767;
249861
+ }
249862
+ }
249863
+ if (d) {
249864
+ syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
249865
+ var lin = revfl[l] & 31, din = revfd[d] & 31;
249866
+ eb += fleb[lin] + fdeb[din];
249867
+ ++lf[257 + lin];
249868
+ ++df[din];
249869
+ wi = i2 + l;
249870
+ ++lc_1;
249871
+ } else {
249872
+ syms[li++] = dat[i2];
249873
+ ++lf[dat[i2]];
249874
+ }
249875
+ }
249876
+ }
249877
+ for (i2 = Math.max(i2, wi);i2 < s; ++i2) {
249878
+ syms[li++] = dat[i2];
249879
+ ++lf[dat[i2]];
249880
+ }
249881
+ pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
249882
+ if (!lst) {
249883
+ st.r = pos & 7 | w[pos / 8 | 0] << 3;
249884
+ pos -= 7;
249885
+ st.h = head, st.p = prev, st.i = i2, st.w = wi;
249886
+ }
249887
+ } else {
249888
+ for (var i2 = st.w || 0;i2 < s + lst; i2 += 65535) {
249889
+ var e = i2 + 65535;
249890
+ if (e >= s) {
249891
+ w[pos / 8 | 0] = lst;
249892
+ e = s;
249893
+ }
249894
+ pos = wfblk(w, pos + 1, dat.subarray(i2, e));
249895
+ }
249896
+ st.i = s;
249897
+ }
249898
+ return slc(o, 0, pre + shft(pos) + post);
249899
+ };
249900
+ var crct = /* @__PURE__ */ function() {
249901
+ var t = new Int32Array(256);
249902
+ for (var i2 = 0;i2 < 256; ++i2) {
249903
+ var c = i2, k = 9;
249904
+ while (--k)
249905
+ c = (c & 1 && -306674912) ^ c >>> 1;
249906
+ t[i2] = c;
249907
+ }
249908
+ return t;
249909
+ }();
249910
+ var crc = function() {
249911
+ var c = -1;
249912
+ return {
249913
+ p: function(d) {
249914
+ var cr = c;
249915
+ for (var i2 = 0;i2 < d.length; ++i2)
249916
+ cr = crct[cr & 255 ^ d[i2]] ^ cr >>> 8;
249917
+ c = cr;
249918
+ },
249919
+ d: function() {
249920
+ return ~c;
249921
+ }
249922
+ };
249923
+ };
249924
+ var dopt = function(dat, opt, pre, post, st) {
249925
+ if (!st) {
249926
+ st = { l: 1 };
249927
+ if (opt.dictionary) {
249928
+ var dict = opt.dictionary.subarray(-32768);
249929
+ var newDat = new u8(dict.length + dat.length);
249930
+ newDat.set(dict);
249931
+ newDat.set(dat, dict.length);
249932
+ dat = newDat;
249933
+ st.w = dict.length;
249934
+ }
249935
+ }
249936
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
249937
+ };
249938
+ var mrg = function(a, b) {
249939
+ var o = {};
249940
+ for (var k in a)
249941
+ o[k] = a[k];
249942
+ for (var k in b)
249943
+ o[k] = b[k];
249944
+ return o;
249945
+ };
249946
+ var wbytes = function(d, b, v) {
249947
+ for (;v; ++b)
249948
+ d[b] = v, v >>>= 8;
249949
+ };
249950
+ function deflateSync(data, opts) {
249951
+ return dopt(data, opts || {}, 0, 0);
249952
+ }
249953
+ var fltn = function(d, p, t, o) {
249954
+ for (var k in d) {
249955
+ var val = d[k], n = p + k, op = o;
249956
+ if (Array.isArray(val))
249957
+ op = mrg(o, val[1]), val = val[0];
249958
+ if (ArrayBuffer.isView(val))
249959
+ t[n] = [val, op];
249960
+ else {
249961
+ t[n += "/"] = [new u8(0), op];
249962
+ fltn(val, n, t, o);
249963
+ }
249964
+ }
249965
+ };
249966
+ var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder;
249967
+ var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder;
249968
+ var tds = 0;
249969
+ try {
249970
+ td.decode(et, { stream: true });
249971
+ tds = 1;
249972
+ } catch (e) {}
249973
+ function strToU8(str, latin1) {
249974
+ if (latin1) {
249975
+ var ar_1 = new u8(str.length);
249976
+ for (var i2 = 0;i2 < str.length; ++i2)
249977
+ ar_1[i2] = str.charCodeAt(i2);
249978
+ return ar_1;
249979
+ }
249980
+ if (te)
249981
+ return te.encode(str);
249982
+ var l = str.length;
249983
+ var ar = new u8(str.length + (str.length >> 1));
249984
+ var ai = 0;
249985
+ var w = function(v) {
249986
+ ar[ai++] = v;
249987
+ };
249988
+ for (var i2 = 0;i2 < l; ++i2) {
249989
+ if (ai + 5 > ar.length) {
249990
+ var n = new u8(ai + 8 + (l - i2 << 1));
249991
+ n.set(ar);
249992
+ ar = n;
249993
+ }
249994
+ var c = str.charCodeAt(i2);
249995
+ if (c < 128 || latin1)
249996
+ w(c);
249997
+ else if (c < 2048)
249998
+ w(192 | c >> 6), w(128 | c & 63);
249999
+ else if (c > 55295 && c < 57344)
250000
+ c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i2) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
250001
+ else
250002
+ w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
250003
+ }
250004
+ return slc(ar, 0, ai);
250005
+ }
250006
+ var exfl = function(ex) {
250007
+ var le = 0;
250008
+ if (ex) {
250009
+ for (var k in ex) {
250010
+ var l = ex[k].length;
250011
+ if (l > 65535)
250012
+ err(9);
250013
+ le += l + 4;
250014
+ }
250015
+ }
250016
+ return le;
250017
+ };
250018
+ var wzh = function(d, b, f, fn, u, c, ce, co) {
250019
+ var fl2 = fn.length, ex = f.extra, col = co && co.length;
250020
+ var exl = exfl(ex);
250021
+ wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
250022
+ if (ce != null)
250023
+ d[b++] = 20, d[b++] = f.os;
250024
+ d[b] = 20, b += 2;
250025
+ d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
250026
+ d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
250027
+ var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
250028
+ if (y < 0 || y > 119)
250029
+ err(10);
250030
+ wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
250031
+ if (c != -1) {
250032
+ wbytes(d, b, f.crc);
250033
+ wbytes(d, b + 4, c < 0 ? -c - 2 : c);
250034
+ wbytes(d, b + 8, f.size);
250035
+ }
250036
+ wbytes(d, b + 12, fl2);
250037
+ wbytes(d, b + 14, exl), b += 16;
250038
+ if (ce != null) {
250039
+ wbytes(d, b, col);
250040
+ wbytes(d, b + 6, f.attrs);
250041
+ wbytes(d, b + 10, ce), b += 14;
250042
+ }
250043
+ d.set(fn, b);
250044
+ b += fl2;
250045
+ if (exl) {
250046
+ for (var k in ex) {
250047
+ var exf = ex[k], l = exf.length;
250048
+ wbytes(d, b, +k);
250049
+ wbytes(d, b + 2, l);
250050
+ d.set(exf, b + 4), b += 4 + l;
250051
+ }
250052
+ }
250053
+ if (col)
250054
+ d.set(co, b), b += col;
250055
+ return b;
250056
+ };
250057
+ var wzf = function(o, b, c, d, e) {
250058
+ wbytes(o, b, 101010256);
250059
+ wbytes(o, b + 8, c);
250060
+ wbytes(o, b + 10, c);
250061
+ wbytes(o, b + 12, d);
250062
+ wbytes(o, b + 16, e);
250063
+ };
250064
+ function zipSync(data, opts) {
250065
+ if (!opts)
250066
+ opts = {};
250067
+ var r = {};
250068
+ var files = [];
250069
+ fltn(data, "", r, opts);
250070
+ var o = 0;
250071
+ var tot = 0;
250072
+ for (var fn in r) {
250073
+ var _a2 = r[fn], file = _a2[0], p = _a2[1];
250074
+ var compression = p.level == 0 ? 0 : 8;
250075
+ var f = strToU8(fn), s = f.length;
250076
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
250077
+ var exl = exfl(p.extra);
250078
+ if (s > 65535)
250079
+ err(11);
250080
+ var d = compression ? deflateSync(file, p) : file, l = d.length;
250081
+ var c = crc();
250082
+ c.p(file);
250083
+ files.push(mrg(p, {
250084
+ size: file.length,
250085
+ crc: c.d(),
250086
+ c: d,
250087
+ f,
250088
+ m,
250089
+ u: s != fn.length || m && com.length != ms,
250090
+ o,
250091
+ compression
250092
+ }));
250093
+ o += 30 + s + exl + l;
250094
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
250095
+ }
250096
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
250097
+ for (var i2 = 0;i2 < files.length; ++i2) {
250098
+ var f = files[i2];
250099
+ wzh(out, f.o, f, f.f, f.u, f.c.length);
250100
+ var badd = 30 + f.f.length + exfl(f.extra);
250101
+ out.set(f.c, f.o + badd);
250102
+ wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
250103
+ }
250104
+ wzf(out, o, files.length, cdl, oe);
250105
+ return out;
250106
+ }
250107
+
250108
+ // src/shared/tools/deploy-tools.ts
250109
+ var FIXED_ZIP_MTIME = new Date("1980-01-01T00:00:00.000Z");
250110
+ var MAX_SOURCE_BYTES = 256 * 1024 * 1024;
250111
+ var deployToolSchema = {
250112
+ ref: optional(Type.String(), "Project ref (defaults to the linked project)"),
250113
+ target: optional(Type.String(), "Named deploy target from supacloud.json"),
250114
+ id: optional(Type.String(), "Frontend deployment ID (auto-selected when unambiguous)"),
250115
+ cwd: optional(Type.String(), "Project directory (default: current directory)"),
250116
+ build_command: optional(Type.String(), "Build command override"),
250117
+ output_dir: optional(Type.String(), "Build output directory override"),
250118
+ skip_build: optional(Type.Boolean(), "Use an existing output directory without building"),
250119
+ dry_run: optional(Type.Boolean(), "Resolve and validate the deployment without building or publishing"),
250120
+ json: optional(Type.Boolean(), "Print only the final JSON result")
250121
+ };
250122
+ function record(candidate) {
250123
+ return candidate && typeof candidate === "object" && !Array.isArray(candidate) ? candidate : null;
250124
+ }
250125
+ function requiredString(candidate, field) {
250126
+ if (typeof candidate !== "string" || !candidate.trim()) {
250127
+ throw new Error(`Invalid frontend deployment response: missing ${field}`);
250128
+ }
250129
+ return candidate.trim();
250130
+ }
250131
+ function frontendDeployment(candidate) {
250132
+ const value = record(candidate);
250133
+ if (!value)
250134
+ throw new Error("Invalid frontend deployment response");
250135
+ return {
250136
+ id: requiredString(value.id, "id"),
250137
+ name: typeof value.name === "string" && value.name.trim() ? value.name.trim() : requiredString(value.id, "id"),
250138
+ framework: typeof value.framework === "string" ? value.framework.trim() : "static",
250139
+ buildCommand: typeof value.build_command === "string" ? value.build_command.trim() : "",
250140
+ outputDirectory: typeof value.output_dir === "string" ? value.output_dir.trim() : "",
250141
+ deploymentUrl: typeof value.deployment_url === "string" && value.deployment_url.trim() ? value.deployment_url.trim() : null
250142
+ };
250143
+ }
250144
+ async function readJson(path) {
250145
+ try {
250146
+ return JSON.parse(await readFile2(path, "utf8"));
250147
+ } catch (error) {
250148
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
250149
+ return null;
250150
+ throw new Error(`Invalid JSON file ${path}: ${error instanceof Error ? error.message : String(error)}`);
250151
+ }
250152
+ }
250153
+ async function findDeployConfigRoot(startDirectory) {
250154
+ let directory = resolve10(startDirectory);
250155
+ while (true) {
250156
+ if (await pathExists(join9(directory, "supacloud.json")))
250157
+ return directory;
250158
+ const parent = dirname4(directory);
250159
+ if (parent === directory)
250160
+ return resolve10(startDirectory);
250161
+ directory = parent;
250162
+ }
250163
+ }
250164
+ function optionalText(value, field) {
250165
+ if (value === undefined)
250166
+ return;
250167
+ if (typeof value !== "string" || !value.trim()) {
250168
+ throw new Error(`supacloud.json ${field} must be a non-empty string`);
250169
+ }
250170
+ return value.trim();
250171
+ }
250172
+ function optionalBoolean(value, field) {
250173
+ if (value === undefined)
250174
+ return;
250175
+ if (typeof value !== "boolean")
250176
+ throw new Error(`supacloud.json ${field} must be a boolean`);
250177
+ return value;
250178
+ }
250179
+ function deployTargetConfig(candidate, name) {
250180
+ const value = record(candidate);
250181
+ if (!value || value.type !== "frontend" && value.type !== "edge_function") {
250182
+ throw new Error(`supacloud.json targets.${name}.type must be 'frontend' or 'edge_function'`);
250183
+ }
250184
+ const framework = optionalText(value.framework, `targets.${name}.framework`);
250185
+ if (framework && !["fetch", "elysia", "hono", "sveltekit-function"].includes(framework)) {
250186
+ throw new Error(`supacloud.json targets.${name}.framework is invalid`);
250187
+ }
250188
+ return {
250189
+ type: value.type,
250190
+ root: optionalText(value.root, `targets.${name}.root`),
250191
+ id: optionalText(value.id, `targets.${name}.id`),
250192
+ slug: optionalText(value.slug, `targets.${name}.slug`),
250193
+ buildCommand: optionalText(value.buildCommand, `targets.${name}.buildCommand`),
250194
+ outputDirectory: optionalText(value.outputDirectory, `targets.${name}.outputDirectory`),
250195
+ bundleDirectory: optionalText(value.bundleDirectory, `targets.${name}.bundleDirectory`),
250196
+ entrypoint: optionalText(value.entrypoint, `targets.${name}.entrypoint`),
250197
+ verifyJwt: optionalBoolean(value.verifyJwt, `targets.${name}.verifyJwt`),
250198
+ minify: optionalBoolean(value.minify, `targets.${name}.minify`),
250199
+ framework
250200
+ };
250201
+ }
250202
+ async function readDeployConfig(configRoot) {
250203
+ const configPath = join9(configRoot, "supacloud.json");
250204
+ const candidate = await readJson(configPath);
250205
+ if (candidate === null)
250206
+ return {};
250207
+ const config = record(candidate);
250208
+ const frontend = record(config?.frontend);
250209
+ const targetValues = record(config?.targets);
250210
+ if (!config || config.frontend !== undefined && !frontend || config.targets !== undefined && !targetValues) {
250211
+ throw new Error("supacloud.json must contain object-valued 'frontend' or 'targets' configuration");
250212
+ }
250213
+ return {
250214
+ defaultTarget: optionalText(config.defaultTarget, "defaultTarget"),
250215
+ targets: targetValues ? Object.fromEntries(Object.entries(targetValues).map(([name, value]) => [name, deployTargetConfig(value, name)])) : undefined,
250216
+ frontend: frontend ? {
250217
+ id: optionalText(frontend.id, "frontend.id"),
250218
+ root: optionalText(frontend.root, "frontend.root"),
250219
+ buildCommand: optionalText(frontend.buildCommand, "frontend.buildCommand"),
250220
+ outputDirectory: optionalText(frontend.outputDirectory, "frontend.outputDirectory")
250221
+ } : undefined
250222
+ };
250223
+ }
250224
+ async function packageName(projectDirectory) {
250225
+ const candidate = record(await readJson(join9(projectDirectory, "package.json")));
250226
+ return typeof candidate?.name === "string" && candidate.name.trim() ? candidate.name.trim() : null;
250227
+ }
250228
+ async function pathExists(path) {
250229
+ return access(path).then(() => true, () => false);
250230
+ }
250231
+ async function defaultBuildCommand(projectDirectory, configRoot) {
250232
+ const packageJson = record(await readJson(join9(projectDirectory, "package.json")));
250233
+ const scripts = record(packageJson?.scripts);
250234
+ if (typeof scripts?.build !== "string" || !scripts.build.trim()) {
250235
+ throw new Error("No build command was configured and package.json has no build script");
250236
+ }
250237
+ let directory = projectDirectory;
250238
+ while (true) {
250239
+ if (await pathExists(join9(directory, "bun.lock")) || await pathExists(join9(directory, "bun.lockb")))
250240
+ return "bun run build";
250241
+ if (await pathExists(join9(directory, "pnpm-lock.yaml")))
250242
+ return "pnpm run build";
250243
+ if (await pathExists(join9(directory, "yarn.lock")))
250244
+ return "yarn build";
250245
+ if (directory === configRoot)
250246
+ break;
250247
+ const parent = dirname4(directory);
250248
+ if (parent === directory || !directory.startsWith(`${configRoot}${sep4}`))
250249
+ break;
250250
+ directory = parent;
250251
+ }
250252
+ return "npm run build";
250253
+ }
250254
+ function deploymentList(candidate) {
250255
+ const values = Array.isArray(candidate) ? candidate : Array.isArray(record(candidate)?.deployments) ? record(candidate)?.deployments : null;
250256
+ if (!values)
250257
+ throw new Error("Invalid frontend deployment list response");
250258
+ return values.map(frontendDeployment);
250259
+ }
250260
+ function selectDeployment(deployments, requestedId, projectName) {
250261
+ if (requestedId) {
250262
+ const selected = deployments.find((deployment) => deployment.id === requestedId);
250263
+ if (!selected)
250264
+ throw new Error(`Frontend deployment '${requestedId}' was not found`);
250265
+ return selected;
250266
+ }
250267
+ if (deployments.length === 1)
250268
+ return deployments[0];
250269
+ if (projectName) {
250270
+ const matches = deployments.filter((deployment) => deployment.id === projectName || deployment.name === projectName);
250271
+ if (matches.length === 1)
250272
+ return matches[0];
250273
+ }
250274
+ const ids = deployments.map((deployment) => deployment.id).sort().join(", ");
250275
+ throw new Error(deployments.length === 0 ? "No frontend deployments exist for this project" : `Multiple frontend deployments found (${ids}). Set frontend.id in supacloud.json or pass --id`);
250276
+ }
250277
+ function targetRoot(configRoot, target, name) {
250278
+ const root = resolve10(configRoot, target.root || (name === "frontend" ? "." : name));
250279
+ const prefix = `${resolve10(configRoot)}${sep4}`;
250280
+ if (root !== resolve10(configRoot) && !root.startsWith(prefix)) {
250281
+ throw new Error(`Deploy target '${name}' root must stay inside the repository root`);
250282
+ }
250283
+ return root;
250284
+ }
250285
+ function selectTarget(configRoot, invocationDirectory, config, requestedName) {
250286
+ const targets = config.targets ? Object.entries(config.targets) : [["frontend", {
250287
+ type: "frontend",
250288
+ root: config.frontend?.root,
250289
+ id: config.frontend?.id,
250290
+ buildCommand: config.frontend?.buildCommand,
250291
+ outputDirectory: config.frontend?.outputDirectory
250292
+ }]];
250293
+ if (targets.length === 0)
250294
+ throw new Error("supacloud.json defines no deploy targets");
250295
+ if (requestedName) {
250296
+ const selected = targets.find(([name]) => name === requestedName);
250297
+ if (!selected)
250298
+ throw new Error(`Deploy target '${requestedName}' was not found in supacloud.json`);
250299
+ return { name: selected[0], config: selected[1], root: targetRoot(configRoot, selected[1], selected[0]) };
250300
+ }
250301
+ const containing = targets.map(([name, target]) => ({ name, target, root: targetRoot(configRoot, target, name) })).filter((candidate) => invocationDirectory === candidate.root || invocationDirectory.startsWith(`${candidate.root}${sep4}`)).sort((left, right) => right.root.length - left.root.length);
250302
+ if (containing.length === 1 || containing.length > 1 && containing[0].root !== containing[1].root) {
250303
+ const selected = containing[0];
250304
+ return { name: selected.name, config: selected.target, root: selected.root };
250305
+ }
250306
+ if (config.defaultTarget) {
250307
+ const selected = targets.find(([name]) => name === config.defaultTarget);
250308
+ if (!selected)
250309
+ throw new Error(`supacloud.json defaultTarget '${config.defaultTarget}' was not found`);
250310
+ return { name: selected[0], config: selected[1], root: targetRoot(configRoot, selected[1], selected[0]) };
250311
+ }
250312
+ if (targets.length === 1) {
250313
+ const selected = targets[0];
250314
+ return { name: selected[0], config: selected[1], root: targetRoot(configRoot, selected[1], selected[0]) };
250315
+ }
250316
+ throw new Error(`Multiple deploy targets found (${targets.map(([name]) => name).sort().join(", ")}). Pass --target`);
250317
+ }
250318
+ function defaultOutputDirectory(framework) {
250319
+ switch (framework) {
250320
+ case "sveltekit-static":
250321
+ return "build";
250322
+ case "nextjs":
250323
+ return "out";
250324
+ case "static":
250325
+ return "dist";
250326
+ default:
250327
+ return "dist";
250328
+ }
250329
+ }
250330
+ function resolveInsideProject(projectDirectory, candidate, allowRoot = false) {
250331
+ const resolved = resolve10(projectDirectory, candidate);
250332
+ const projectRoot = resolve10(projectDirectory);
250333
+ const projectPrefix = `${projectRoot}${sep4}`;
250334
+ if (!allowRoot && resolved === projectRoot || resolved !== projectRoot && !resolved.startsWith(projectPrefix)) {
250335
+ throw new Error("Frontend output directory must stay inside the project directory");
250336
+ }
250337
+ return resolved;
250338
+ }
250339
+ async function runBuild(command, cwd) {
250340
+ await new Promise((resolvePromise, reject) => {
250341
+ const child = spawn3(command, { cwd, env: process.env, shell: true, stdio: "inherit" });
250342
+ child.once("error", reject);
250343
+ child.once("exit", (code, signal) => {
250344
+ if (code === 0)
250345
+ resolvePromise();
250346
+ else
250347
+ reject(new Error(`Build command failed (${signal ? `signal ${signal}` : `exit ${code ?? "unknown"}`}): ${command}`));
250348
+ });
250349
+ });
250350
+ }
250351
+ async function collectArchiveFiles(root) {
250352
+ const rootStat = await lstat(root).catch(() => null);
250353
+ if (!rootStat?.isDirectory() || rootStat.isSymbolicLink()) {
250354
+ throw new Error(`Frontend output directory does not exist or is not a regular directory: ${root}`);
250355
+ }
250356
+ const paths = [];
250357
+ const visit = async (directory) => {
250358
+ const entries = [];
250359
+ for await (const entry of await opendir(directory))
250360
+ entries.push(entry);
250361
+ entries.sort((left, right) => left.name.localeCompare(right.name, "en"));
250362
+ for (const entry of entries) {
250363
+ const path = join9(directory, entry.name);
250364
+ const stats = await lstat(path);
250365
+ if (stats.isSymbolicLink())
250366
+ throw new Error(`Frontend output cannot contain symbolic links: ${path}`);
250367
+ if (stats.isDirectory())
250368
+ await visit(path);
250369
+ else if (stats.isFile())
250370
+ paths.push(path);
250371
+ else
250372
+ throw new Error(`Frontend output contains an unsupported file type: ${path}`);
250373
+ }
250374
+ };
250375
+ await visit(root);
250376
+ if (paths.length === 0)
250377
+ throw new Error(`Frontend output directory is empty: ${root}`);
250378
+ let bytes = 0;
250379
+ const files = {};
250380
+ for (const path of paths) {
250381
+ const data = new Uint8Array(await readFile2(path));
250382
+ bytes += data.byteLength;
250383
+ if (bytes > MAX_SOURCE_BYTES)
250384
+ throw new Error(`Frontend output exceeds ${MAX_SOURCE_BYTES} bytes`);
250385
+ const archivePath = relative4(root, path).split(sep4).join("/");
250386
+ files[archivePath] = [data, { mtime: FIXED_ZIP_MTIME }];
250387
+ }
250388
+ return { files, bytes, count: paths.length };
250389
+ }
250390
+ async function createFrontendArchive(outputDirectory) {
250391
+ const collected = await collectArchiveFiles(outputDirectory);
250392
+ const temporaryDirectory = await mkdtemp(join9(tmpdir2(), "supacloud-deploy-"));
250393
+ const archivePath = join9(temporaryDirectory, `${basename4(outputDirectory)}.zip`);
250394
+ try {
250395
+ const archiveBytes = zipSync(collected.files, { level: 6, mtime: FIXED_ZIP_MTIME });
250396
+ await writeFile3(archivePath, archiveBytes);
250397
+ const sha256 = createHash4("sha256").update(archiveBytes).digest("hex");
250398
+ return {
250399
+ archivePath,
250400
+ sha256,
250401
+ sourceBytes: collected.bytes,
250402
+ fileCount: collected.count,
250403
+ cleanup: () => rm(temporaryDirectory, { recursive: true, force: true })
250404
+ };
250405
+ } catch (error) {
250406
+ await rm(temporaryDirectory, { recursive: true, force: true });
250407
+ throw error;
250408
+ }
250409
+ }
250410
+ function payload(response) {
250411
+ if (response.isError)
250412
+ throw new Error(response.content[0]?.text || "Deployment operation failed");
250413
+ const text = response.content.find((chunk) => chunk.type === "text")?.text;
250414
+ const parsed = text ? record(JSON.parse(text)) : null;
250415
+ if (!parsed)
250416
+ throw new Error("Deployment operation returned an invalid response");
250417
+ return parsed;
250418
+ }
250419
+ function phaseReporter(json) {
250420
+ const started = performance.now();
250421
+ return (phase, detail) => {
250422
+ if (!json)
250423
+ console.error(` ${phase.padEnd(10)} ${detail}`);
250424
+ return Math.round(performance.now() - started);
250425
+ };
250426
+ }
250427
+ function deployResponse(result, json) {
250428
+ if (json)
250429
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
250430
+ const lines = [
250431
+ result.unchanged === true ? "Already up to date." : `Deployed ${String(result.target || result.deployment_id || result.slug)}.`,
250432
+ result.url ? `URL: ${String(result.url)}` : null,
250433
+ result.release_id ? `Release: ${String(result.release_id)}` : null,
250434
+ result.active_version ? `Active version: ${String(result.active_version)}` : null,
250435
+ result.file_count ? `Files: ${String(result.file_count)}` : null,
250436
+ `Duration: ${(Number(result.duration_ms) / 1000).toFixed(1)}s`
250437
+ ].filter((line) => Boolean(line));
250438
+ return { content: [{ type: "text", text: lines.join(`
250439
+ `) }] };
250440
+ }
250441
+ function registerDeployTools(server2, http, options = {}) {
250442
+ server2.tool("deploy", "Build and publish the linked frontend with one command", deployToolSchema, async (args) => {
250443
+ const invocationDirectory = resolve10(String(args.cwd || options.cwd || process.cwd()));
250444
+ const projectRef2 = String(args.ref || options.projectRef || "").trim();
250445
+ if (!projectRef2)
250446
+ throw new Error("A linked project ref is required. Set SUPACLOUD_PROJECT_REF or pass --ref");
250447
+ const configRoot = await findDeployConfigRoot(invocationDirectory);
250448
+ const config = await readDeployConfig(configRoot);
250449
+ const target = selectTarget(configRoot, invocationDirectory, config, String(args.target || "").trim() || undefined);
250450
+ const projectDirectory = target.root;
250451
+ const targetState = await lstat(projectDirectory).catch(() => null);
250452
+ if (!targetState?.isDirectory() || targetState.isSymbolicLink()) {
250453
+ throw new Error(`Deploy target '${target.name}' root is not a regular directory: ${projectDirectory}`);
250454
+ }
250455
+ const requestedId = String(args.id || target.config.id || "").trim() || undefined;
250456
+ const report = phaseReporter(args.json === true);
250457
+ report("inspect", `${target.name} (${projectRef2})`);
250458
+ if (target.config.type === "edge_function") {
250459
+ if (!options.edgeFunctionDeploy)
250460
+ throw new Error("Edge Function deploy support is unavailable in this CLI context");
250461
+ const slug = target.config.slug || requestedId || target.name;
250462
+ const functionListResponse2 = await options.edgeFunctionDeploy({
250463
+ action: "list",
250464
+ ref: projectRef2
250465
+ });
250466
+ if (functionListResponse2.isError) {
250467
+ throw new Error(`Unable to read the current identity for Edge Function '${slug}'`);
250468
+ }
250469
+ const functionListText = functionListResponse2.content.find((chunk) => chunk.type === "text")?.text;
250470
+ if (!functionListText)
250471
+ throw new Error(`Unable to read the current identity for Edge Function '${slug}'`);
250472
+ const functions = projectedFunctionList(JSON.parse(functionListText));
250473
+ if (!functions)
250474
+ throw new Error(`Invalid current identity for Edge Function '${slug}'`);
250475
+ const current = functions?.find((candidate) => candidate.slug === slug);
250476
+ const activeVersion = current && typeof current.version === "number" ? String(current.version) : "absent";
250477
+ const activationId = current && typeof current.activation_id === "string" ? current.activation_id : "legacy";
250478
+ if (!activeVersion || !activationId)
250479
+ throw new Error(`Edge Function '${slug}' has an invalid active identity`);
250480
+ const buildCommand2 = String(args.build_command || target.config.buildCommand || "").trim() || (args.skip_build === true ? "" : await defaultBuildCommand(projectDirectory, configRoot));
250481
+ const bundleDirectory = resolveInsideProject(projectDirectory, String(args.output_dir || target.config.bundleDirectory || target.config.outputDirectory || "dist"), true);
250482
+ if (args.dry_run === true) {
250483
+ return { content: [{ type: "text", text: JSON.stringify({
250484
+ ok: true,
250485
+ dry_run: true,
250486
+ type: target.config.type,
250487
+ target: target.name,
250488
+ project_ref: projectRef2,
250489
+ slug,
250490
+ build_command: args.skip_build === true ? null : buildCommand2,
250491
+ bundle_directory: bundleDirectory,
250492
+ expected_active_version: activeVersion,
250493
+ expected_activation_id: activationId
250494
+ }, null, 2) }] };
250495
+ }
250496
+ if (args.skip_build !== true) {
250497
+ report("build", buildCommand2);
250498
+ await runBuild(buildCommand2, projectDirectory);
250499
+ } else {
250500
+ report("build", "skipped");
250501
+ }
250502
+ report("deploy", `edge function ${slug}`);
250503
+ const deployed = await options.edgeFunctionDeploy({
250504
+ action: "deploy_bundle",
250505
+ ref: projectRef2,
250506
+ slug,
250507
+ "bundle-dir": bundleDirectory,
250508
+ entrypoint: target.config.entrypoint || "index.ts",
250509
+ minify: target.config.minify,
250510
+ verify_jwt: target.config.verifyJwt,
250511
+ framework: target.config.framework,
250512
+ "expected-active-version": activeVersion,
250513
+ "expected-activation-id": activationId
250514
+ });
250515
+ if (deployed.isError)
250516
+ return deployed;
250517
+ const deployedText = deployed.content.find((chunk) => chunk.type === "text")?.text;
250518
+ const deployedPayload = deployedText ? record(JSON.parse(deployedText)) : null;
250519
+ const durationMs = report("done", slug);
250520
+ return deployResponse({
250521
+ ok: true,
250522
+ unchanged: false,
250523
+ type: target.config.type,
250524
+ target: target.name,
250525
+ project_ref: projectRef2,
250526
+ slug,
250527
+ active_version: deployedPayload?.active_version,
250528
+ activation_id: deployedPayload?.activation_id,
250529
+ duration_ms: durationMs
250530
+ }, args.json === true);
250531
+ }
250532
+ const listResponse2 = await http.get(`/v1/projects/${encodeURIComponent(projectRef2)}/frontend/deployments`);
250533
+ if (!listResponse2.ok)
250534
+ throw new Error(`Failed to list frontend deployments (HTTP ${listResponse2.status})`);
250535
+ const selected = selectDeployment(deploymentList(listResponse2.data), requestedId, await packageName(projectDirectory));
250536
+ const configuredBuildCommand = String(args.build_command || target.config.buildCommand || selected.buildCommand || "").trim();
250537
+ const buildCommand = configuredBuildCommand || (args.skip_build === true ? "" : await defaultBuildCommand(projectDirectory, configRoot));
250538
+ const configuredOutput = String(args.output_dir || target.config.outputDirectory || "").trim();
250539
+ const remoteOutput = selected.outputDirectory && selected.outputDirectory !== "." ? selected.outputDirectory : "";
250540
+ const outputDirectory = resolveInsideProject(projectDirectory, configuredOutput || remoteOutput || defaultOutputDirectory(selected.framework));
250541
+ if (args.dry_run === true) {
250542
+ return { content: [{ type: "text", text: JSON.stringify({
250543
+ ok: true,
250544
+ dry_run: true,
250545
+ project_ref: projectRef2,
250546
+ deployment_id: selected.id,
250547
+ build_command: args.skip_build === true ? null : buildCommand,
250548
+ output_directory: outputDirectory
250549
+ }, null, 2) }] };
250550
+ }
250551
+ if (args.skip_build !== true) {
250552
+ report("build", buildCommand);
250553
+ await runBuild(buildCommand, projectDirectory);
250554
+ } else {
250555
+ report("build", "skipped");
250556
+ }
250557
+ report("package", relative4(projectDirectory, outputDirectory) || ".");
250558
+ const archive = await createFrontendArchive(outputDirectory);
250559
+ try {
250560
+ const inventory = payload(await listFrontendReleases(http, projectRef2, selected.id, undefined, 100));
250561
+ const activeReleaseId = typeof inventory.active_release_id === "string" ? inventory.active_release_id : null;
250562
+ const activeActivationId = typeof inventory.active_activation_id === "string" ? inventory.active_activation_id : null;
250563
+ if (archive.sha256 === activeReleaseId) {
250564
+ const durationMs2 = report("done", "already current");
250565
+ return deployResponse({
250566
+ ok: true,
250567
+ unchanged: true,
250568
+ project_ref: projectRef2,
250569
+ deployment_id: selected.id,
250570
+ release_id: archive.sha256,
250571
+ url: selected.deploymentUrl,
250572
+ file_count: archive.fileCount,
250573
+ source_bytes: archive.sourceBytes,
250574
+ duration_ms: durationMs2
250575
+ }, args.json === true);
250576
+ }
250577
+ report("upload", `${archive.fileCount} files`);
250578
+ const uploaded = payload(await uploadFrontendRelease(http, projectRef2, selected.id, archive.archivePath));
250579
+ const release = record(uploaded.release);
250580
+ const releaseId = requiredString(release?.release_id, "release.release_id");
250581
+ if (releaseId !== archive.sha256)
250582
+ throw new Error("Uploaded release identity does not match the local archive");
250583
+ report("activate", releaseId.slice(0, 12));
250584
+ const mutationId = crypto.randomUUID();
250585
+ const activated = payload(await activateFrontendRelease(http, {
250586
+ projectRef: projectRef2,
250587
+ deploymentId: selected.id,
250588
+ releaseId,
250589
+ expectedActiveReleaseId: activeReleaseId || "absent",
250590
+ expectedActivationId: activeActivationId || "absent",
250591
+ mutationId
250592
+ }));
250593
+ const finalResponse = await http.get(`/v1/projects/${encodeURIComponent(projectRef2)}/frontend/deployments/${encodeURIComponent(selected.id)}`);
250594
+ const finalDeployment = finalResponse.ok ? frontendDeployment(finalResponse.data) : selected;
250595
+ const durationMs = report("done", finalDeployment.deploymentUrl || selected.id);
250596
+ return deployResponse({
250597
+ ok: true,
250598
+ unchanged: false,
250599
+ project_ref: projectRef2,
250600
+ deployment_id: selected.id,
250601
+ release_id: activated.active_release_id,
250602
+ activation_id: activated.activation_id,
250603
+ url: finalDeployment.deploymentUrl,
250604
+ file_count: archive.fileCount,
250605
+ source_bytes: archive.sourceBytes,
250606
+ duration_ms: durationMs
250607
+ }, args.json === true);
250608
+ } finally {
250609
+ await archive.cleanup();
250610
+ }
250611
+ });
250612
+ }
249454
250613
  // package.json
249455
250614
  var package_default = {
249456
250615
  name: "@supacloud/cli",
249457
- version: "0.38.0",
250616
+ version: "0.39.0",
249458
250617
  description: "Project-scoped CLI for SupaCloud users",
249459
250618
  type: "module",
249460
250619
  main: "./dist/index.js",
@@ -249487,7 +250646,8 @@ var package_default = {
249487
250646
  dependencies: {
249488
250647
  "@sinclair/typebox": "^0.34.52",
249489
250648
  "@supacloud/compiler": "^0.1.0",
249490
- "@supacloud/db": "^0.1.0"
250649
+ "@supacloud/db": "^0.1.0",
250650
+ fflate: "^0.8.3"
249491
250651
  },
249492
250652
  devDependencies: {
249493
250653
  "@types/bun": "^1.4.0",
@@ -249666,6 +250826,7 @@ function printHelp(context) {
249666
250826
 
249667
250827
  USAGE
249668
250828
 
250829
+ ${preferredCommand} [global flags] deploy [--flags]
249669
250830
  ${preferredCommand} [global flags] <module> <action> [--flags]
249670
250831
  ${preferredCommand} [global flags] status
249671
250832
  ${preferredCommand} --help
@@ -249700,6 +250861,9 @@ DEFAULT CONTEXT
249700
250861
  EXAMPLES
249701
250862
 
249702
250863
  ${preferredCommand} status
250864
+ ${preferredCommand} deploy
250865
+ ${preferredCommand} deploy --target web
250866
+ ${preferredCommand} deploy --target api
249703
250867
  ${preferredCommand} project get
249704
250868
  ${preferredCommand} project logs --log_type database
249705
250869
  ${preferredCommand} project task_stats
@@ -249852,6 +251016,16 @@ function createCliTools(context, confirmProduction) {
249852
251016
  };
249853
251017
  if (context.credentialScope !== "management" || !context.apiUrl || !context.apiToken) {
249854
251018
  registerContextAwareHelp();
251019
+ tools.deploy = {
251020
+ schema: deployToolSchema,
251021
+ callback: async () => ({
251022
+ isError: true,
251023
+ content: [{
251024
+ type: "text",
251025
+ text: `⚠️ Deploy requires Management API context. Run \`${preferredCommand} status\` to inspect current detection.`
251026
+ }]
251027
+ })
251028
+ };
249855
251029
  Object.assign(tools, captureTools((server2) => registerDatabaseTools(server2, undefined, {
249856
251030
  localOnly: true
249857
251031
  })));
@@ -249910,9 +251084,10 @@ function createCliTools(context, confirmProduction) {
249910
251084
  assign(captureTools((server2) => registerAuthTools(server2, http)));
249911
251085
  assign(captureTools((server2) => registerOAuthClientTools(server2, http)));
249912
251086
  assign(captureTools((server2) => registerStorageTools(server2, http)));
249913
- assign(captureTools((server2) => registerAdvancedTools(server2, http, process.env, {
251087
+ const advancedTools = captureTools((server2) => registerAdvancedTools(server2, http, process.env, {
249914
251088
  readOnly: context.readOnly
249915
- })));
251089
+ }));
251090
+ assign(advancedTools);
249916
251091
  assign(captureTools((server2) => registerScheduledFunctionTools(server2, http, process.env, {
249917
251092
  readOnly: context.readOnly
249918
251093
  })));
@@ -249923,6 +251098,11 @@ function createCliTools(context, confirmProduction) {
249923
251098
  applicationOrigin: context.inferredSupabaseUrl || undefined
249924
251099
  })));
249925
251100
  assign(captureTools((server2) => registerFrontendTools(server2, http)));
251101
+ assign(captureTools((server2) => registerDeployTools(server2, http, {
251102
+ projectRef: context.projectRef || undefined,
251103
+ cwd: process.cwd(),
251104
+ edgeFunctionDeploy: advancedTools.edge_functions?.callback
251105
+ })));
249926
251106
  assign(captureTools((server2) => registerGatewayTools(server2, http, {
249927
251107
  projectRef: context.projectRef || undefined
249928
251108
  })));
@@ -249944,7 +251124,8 @@ async function main() {
249944
251124
  }
249945
251125
  const globalOptions = parseGlobalOptions(rawArgs);
249946
251126
  const args = globalOptions.args;
249947
- const context = resolveSupaCloudContext(process.env, process.cwd(), {
251127
+ const contextDirectory = args[0] === "deploy" ? await findDeployConfigRoot(process.cwd()) : process.cwd();
251128
+ const context = resolveSupaCloudContext(process.env, contextDirectory, {
249948
251129
  environmentName: globalOptions.environmentName,
249949
251130
  envFile: globalOptions.envFile
249950
251131
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/cli",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Project-scoped CLI for SupaCloud users",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,7 +33,8 @@
33
33
  "dependencies": {
34
34
  "@sinclair/typebox": "^0.34.52",
35
35
  "@supacloud/compiler": "^0.1.0",
36
- "@supacloud/db": "^0.1.0"
36
+ "@supacloud/db": "^0.1.0",
37
+ "fflate": "^0.8.3"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/bun": "^1.4.0",