@backifydev/cli 0.3.1 → 0.3.2
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.
- package/dist/index.js +850 -34
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,14 +1,782 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/functions.ts
|
|
4
|
+
import { build } from "esbuild";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/fflate/esm/index.mjs
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
var require2 = createRequire("/");
|
|
9
|
+
var _a;
|
|
10
|
+
var Worker;
|
|
11
|
+
var isMarkedAsUntransferable;
|
|
12
|
+
try {
|
|
13
|
+
_a = require2("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
}
|
|
16
|
+
var u8 = Uint8Array;
|
|
17
|
+
var u16 = Uint16Array;
|
|
18
|
+
var i32 = Int32Array;
|
|
19
|
+
var fleb = new u8([
|
|
20
|
+
0,
|
|
21
|
+
0,
|
|
22
|
+
0,
|
|
23
|
+
0,
|
|
24
|
+
0,
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
1,
|
|
29
|
+
1,
|
|
30
|
+
1,
|
|
31
|
+
1,
|
|
32
|
+
2,
|
|
33
|
+
2,
|
|
34
|
+
2,
|
|
35
|
+
2,
|
|
36
|
+
3,
|
|
37
|
+
3,
|
|
38
|
+
3,
|
|
39
|
+
3,
|
|
40
|
+
4,
|
|
41
|
+
4,
|
|
42
|
+
4,
|
|
43
|
+
4,
|
|
44
|
+
5,
|
|
45
|
+
5,
|
|
46
|
+
5,
|
|
47
|
+
5,
|
|
48
|
+
0,
|
|
49
|
+
/* unused */
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
/* impossible */
|
|
53
|
+
0
|
|
54
|
+
]);
|
|
55
|
+
var fdeb = new u8([
|
|
56
|
+
0,
|
|
57
|
+
0,
|
|
58
|
+
0,
|
|
59
|
+
0,
|
|
60
|
+
1,
|
|
61
|
+
1,
|
|
62
|
+
2,
|
|
63
|
+
2,
|
|
64
|
+
3,
|
|
65
|
+
3,
|
|
66
|
+
4,
|
|
67
|
+
4,
|
|
68
|
+
5,
|
|
69
|
+
5,
|
|
70
|
+
6,
|
|
71
|
+
6,
|
|
72
|
+
7,
|
|
73
|
+
7,
|
|
74
|
+
8,
|
|
75
|
+
8,
|
|
76
|
+
9,
|
|
77
|
+
9,
|
|
78
|
+
10,
|
|
79
|
+
10,
|
|
80
|
+
11,
|
|
81
|
+
11,
|
|
82
|
+
12,
|
|
83
|
+
12,
|
|
84
|
+
13,
|
|
85
|
+
13,
|
|
86
|
+
/* unused */
|
|
87
|
+
0,
|
|
88
|
+
0
|
|
89
|
+
]);
|
|
90
|
+
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
91
|
+
var freb = function(eb, start) {
|
|
92
|
+
var b = new u16(31);
|
|
93
|
+
for (var i = 0; i < 31; ++i) {
|
|
94
|
+
b[i] = start += 1 << eb[i - 1];
|
|
95
|
+
}
|
|
96
|
+
var r = new i32(b[30]);
|
|
97
|
+
for (var i = 1; i < 30; ++i) {
|
|
98
|
+
for (var j = b[i]; j < b[i + 1]; ++j) {
|
|
99
|
+
r[j] = j - b[i] << 5 | i;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { b, r };
|
|
103
|
+
};
|
|
104
|
+
var _a = freb(fleb, 2);
|
|
105
|
+
var fl = _a.b;
|
|
106
|
+
var revfl = _a.r;
|
|
107
|
+
fl[28] = 258, revfl[258] = 28;
|
|
108
|
+
var _b = freb(fdeb, 0);
|
|
109
|
+
var fd = _b.b;
|
|
110
|
+
var revfd = _b.r;
|
|
111
|
+
var rev = new u16(32768);
|
|
112
|
+
for (i = 0; i < 32768; ++i) {
|
|
113
|
+
x = (i & 43690) >> 1 | (i & 21845) << 1;
|
|
114
|
+
x = (x & 52428) >> 2 | (x & 13107) << 2;
|
|
115
|
+
x = (x & 61680) >> 4 | (x & 3855) << 4;
|
|
116
|
+
rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
|
|
117
|
+
}
|
|
118
|
+
var x;
|
|
119
|
+
var i;
|
|
120
|
+
var hMap = (function(cd, mb, r) {
|
|
121
|
+
var s = cd.length;
|
|
122
|
+
var i = 0;
|
|
123
|
+
var l = new u16(mb);
|
|
124
|
+
for (; i < s; ++i) {
|
|
125
|
+
if (cd[i])
|
|
126
|
+
++l[cd[i] - 1];
|
|
127
|
+
}
|
|
128
|
+
var le = new u16(mb);
|
|
129
|
+
for (i = 1; i < mb; ++i) {
|
|
130
|
+
le[i] = le[i - 1] + l[i - 1] << 1;
|
|
131
|
+
}
|
|
132
|
+
var co;
|
|
133
|
+
if (r) {
|
|
134
|
+
co = new u16(1 << mb);
|
|
135
|
+
var rvb = 15 - mb;
|
|
136
|
+
for (i = 0; i < s; ++i) {
|
|
137
|
+
if (cd[i]) {
|
|
138
|
+
var sv = i << 4 | cd[i];
|
|
139
|
+
var r_1 = mb - cd[i];
|
|
140
|
+
var v = le[cd[i] - 1]++ << r_1;
|
|
141
|
+
for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
|
|
142
|
+
co[rev[v] >> rvb] = sv;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
co = new u16(s);
|
|
148
|
+
for (i = 0; i < s; ++i) {
|
|
149
|
+
if (cd[i]) {
|
|
150
|
+
co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return co;
|
|
155
|
+
});
|
|
156
|
+
var flt = new u8(288);
|
|
157
|
+
for (i = 0; i < 144; ++i)
|
|
158
|
+
flt[i] = 8;
|
|
159
|
+
var i;
|
|
160
|
+
for (i = 144; i < 256; ++i)
|
|
161
|
+
flt[i] = 9;
|
|
162
|
+
var i;
|
|
163
|
+
for (i = 256; i < 280; ++i)
|
|
164
|
+
flt[i] = 7;
|
|
165
|
+
var i;
|
|
166
|
+
for (i = 280; i < 288; ++i)
|
|
167
|
+
flt[i] = 8;
|
|
168
|
+
var i;
|
|
169
|
+
var fdt = new u8(32);
|
|
170
|
+
for (i = 0; i < 32; ++i)
|
|
171
|
+
fdt[i] = 5;
|
|
172
|
+
var i;
|
|
173
|
+
var flm = /* @__PURE__ */ hMap(flt, 9, 0);
|
|
174
|
+
var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
|
|
175
|
+
var shft = function(p) {
|
|
176
|
+
return (p + 7) / 8 | 0;
|
|
177
|
+
};
|
|
178
|
+
var slc = function(v, s, e) {
|
|
179
|
+
if (s == null || s < 0)
|
|
180
|
+
s = 0;
|
|
181
|
+
if (e == null || e > v.length)
|
|
182
|
+
e = v.length;
|
|
183
|
+
return new u8(v.subarray(s, e));
|
|
184
|
+
};
|
|
185
|
+
var ec = [
|
|
186
|
+
"unexpected EOF",
|
|
187
|
+
"invalid block type",
|
|
188
|
+
"invalid length/literal",
|
|
189
|
+
"invalid distance",
|
|
190
|
+
"stream finished",
|
|
191
|
+
"no stream handler",
|
|
192
|
+
,
|
|
193
|
+
// determined by compression function
|
|
194
|
+
"no callback",
|
|
195
|
+
"invalid UTF-8 data",
|
|
196
|
+
"extra field too long",
|
|
197
|
+
"date not in range 1980-2099",
|
|
198
|
+
"filename too long",
|
|
199
|
+
"stream finishing",
|
|
200
|
+
"invalid zip data"
|
|
201
|
+
// determined by unknown compression method
|
|
202
|
+
];
|
|
203
|
+
var err = function(ind, msg, nt) {
|
|
204
|
+
var e = new Error(msg || ec[ind]);
|
|
205
|
+
e.code = ind;
|
|
206
|
+
if (Error.captureStackTrace)
|
|
207
|
+
Error.captureStackTrace(e, err);
|
|
208
|
+
if (!nt)
|
|
209
|
+
throw e;
|
|
210
|
+
return e;
|
|
211
|
+
};
|
|
212
|
+
var wbits = function(d, p, v) {
|
|
213
|
+
v <<= p & 7;
|
|
214
|
+
var o = p / 8 | 0;
|
|
215
|
+
d[o] |= v;
|
|
216
|
+
d[o + 1] |= v >> 8;
|
|
217
|
+
};
|
|
218
|
+
var wbits16 = function(d, p, v) {
|
|
219
|
+
v <<= p & 7;
|
|
220
|
+
var o = p / 8 | 0;
|
|
221
|
+
d[o] |= v;
|
|
222
|
+
d[o + 1] |= v >> 8;
|
|
223
|
+
d[o + 2] |= v >> 16;
|
|
224
|
+
};
|
|
225
|
+
var hTree = function(d, mb) {
|
|
226
|
+
var t = [];
|
|
227
|
+
for (var i = 0; i < d.length; ++i) {
|
|
228
|
+
if (d[i])
|
|
229
|
+
t.push({ s: i, f: d[i] });
|
|
230
|
+
}
|
|
231
|
+
var s = t.length;
|
|
232
|
+
var t2 = t.slice();
|
|
233
|
+
if (!s)
|
|
234
|
+
return { t: et, l: 0 };
|
|
235
|
+
if (s == 1) {
|
|
236
|
+
var v = new u8(t[0].s + 1);
|
|
237
|
+
v[t[0].s] = 1;
|
|
238
|
+
return { t: v, l: 1 };
|
|
239
|
+
}
|
|
240
|
+
t.sort(function(a, b) {
|
|
241
|
+
return a.f - b.f;
|
|
242
|
+
});
|
|
243
|
+
t.push({ s: -1, f: 25001 });
|
|
244
|
+
var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;
|
|
245
|
+
t[0] = { s: -1, f: l.f + r.f, l, r };
|
|
246
|
+
while (i1 != s - 1) {
|
|
247
|
+
l = t[t[i0].f < t[i2].f ? i0++ : i2++];
|
|
248
|
+
r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
|
|
249
|
+
t[i1++] = { s: -1, f: l.f + r.f, l, r };
|
|
250
|
+
}
|
|
251
|
+
var maxSym = t2[0].s;
|
|
252
|
+
for (var i = 1; i < s; ++i) {
|
|
253
|
+
if (t2[i].s > maxSym)
|
|
254
|
+
maxSym = t2[i].s;
|
|
255
|
+
}
|
|
256
|
+
var tr = new u16(maxSym + 1);
|
|
257
|
+
var mbt = ln(t[i1 - 1], tr, 0);
|
|
258
|
+
if (mbt > mb) {
|
|
259
|
+
var i = 0, dt = 0;
|
|
260
|
+
var lft = mbt - mb, cst = 1 << lft;
|
|
261
|
+
t2.sort(function(a, b) {
|
|
262
|
+
return tr[b.s] - tr[a.s] || a.f - b.f;
|
|
263
|
+
});
|
|
264
|
+
for (; i < s; ++i) {
|
|
265
|
+
var i2_1 = t2[i].s;
|
|
266
|
+
if (tr[i2_1] > mb) {
|
|
267
|
+
dt += cst - (1 << mbt - tr[i2_1]);
|
|
268
|
+
tr[i2_1] = mb;
|
|
269
|
+
} else
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
dt >>= lft;
|
|
273
|
+
while (dt > 0) {
|
|
274
|
+
var i2_2 = t2[i].s;
|
|
275
|
+
if (tr[i2_2] < mb)
|
|
276
|
+
dt -= 1 << mb - tr[i2_2]++ - 1;
|
|
277
|
+
else
|
|
278
|
+
++i;
|
|
279
|
+
}
|
|
280
|
+
for (; i >= 0 && dt; --i) {
|
|
281
|
+
var i2_3 = t2[i].s;
|
|
282
|
+
if (tr[i2_3] == mb) {
|
|
283
|
+
--tr[i2_3];
|
|
284
|
+
++dt;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
mbt = mb;
|
|
288
|
+
}
|
|
289
|
+
return { t: new u8(tr), l: mbt };
|
|
290
|
+
};
|
|
291
|
+
var ln = function(n, l, d) {
|
|
292
|
+
return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
|
|
293
|
+
};
|
|
294
|
+
var lc = function(c) {
|
|
295
|
+
var s = c.length;
|
|
296
|
+
while (s && !c[--s])
|
|
297
|
+
;
|
|
298
|
+
var cl = new u16(++s);
|
|
299
|
+
var cli = 0, cln = c[0], cls = 1;
|
|
300
|
+
var w = function(v) {
|
|
301
|
+
cl[cli++] = v;
|
|
302
|
+
};
|
|
303
|
+
for (var i = 1; i <= s; ++i) {
|
|
304
|
+
if (c[i] == cln && i != s)
|
|
305
|
+
++cls;
|
|
306
|
+
else {
|
|
307
|
+
if (!cln && cls > 2) {
|
|
308
|
+
for (; cls > 138; cls -= 138)
|
|
309
|
+
w(32754);
|
|
310
|
+
if (cls > 2) {
|
|
311
|
+
w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
|
|
312
|
+
cls = 0;
|
|
313
|
+
}
|
|
314
|
+
} else if (cls > 3) {
|
|
315
|
+
w(cln), --cls;
|
|
316
|
+
for (; cls > 6; cls -= 6)
|
|
317
|
+
w(8304);
|
|
318
|
+
if (cls > 2)
|
|
319
|
+
w(cls - 3 << 5 | 8208), cls = 0;
|
|
320
|
+
}
|
|
321
|
+
while (cls--)
|
|
322
|
+
w(cln);
|
|
323
|
+
cls = 1;
|
|
324
|
+
cln = c[i];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return { c: cl.subarray(0, cli), n: s };
|
|
328
|
+
};
|
|
329
|
+
var clen = function(cf, cl) {
|
|
330
|
+
var l = 0;
|
|
331
|
+
for (var i = 0; i < cl.length; ++i)
|
|
332
|
+
l += cf[i] * cl[i];
|
|
333
|
+
return l;
|
|
334
|
+
};
|
|
335
|
+
var wfblk = function(out, pos, dat) {
|
|
336
|
+
var s = dat.length;
|
|
337
|
+
var o = shft(pos + 2);
|
|
338
|
+
out[o] = s & 255;
|
|
339
|
+
out[o + 1] = s >> 8;
|
|
340
|
+
out[o + 2] = out[o] ^ 255;
|
|
341
|
+
out[o + 3] = out[o + 1] ^ 255;
|
|
342
|
+
for (var i = 0; i < s; ++i)
|
|
343
|
+
out[o + i + 4] = dat[i];
|
|
344
|
+
return (o + 4 + s) * 8;
|
|
345
|
+
};
|
|
346
|
+
var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
|
|
347
|
+
wbits(out, p++, final);
|
|
348
|
+
++lf[256];
|
|
349
|
+
var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
|
|
350
|
+
var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
|
|
351
|
+
var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
|
|
352
|
+
var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
|
|
353
|
+
var lcfreq = new u16(19);
|
|
354
|
+
for (var i = 0; i < lclt.length; ++i)
|
|
355
|
+
++lcfreq[lclt[i] & 31];
|
|
356
|
+
for (var i = 0; i < lcdt.length; ++i)
|
|
357
|
+
++lcfreq[lcdt[i] & 31];
|
|
358
|
+
var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
|
|
359
|
+
var nlcc = 19;
|
|
360
|
+
for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
|
|
361
|
+
;
|
|
362
|
+
var flen = bl + 5 << 3;
|
|
363
|
+
var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
|
|
364
|
+
var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
|
|
365
|
+
if (bs >= 0 && flen <= ftlen && flen <= dtlen)
|
|
366
|
+
return wfblk(out, p, dat.subarray(bs, bs + bl));
|
|
367
|
+
var lm, ll, dm, dl;
|
|
368
|
+
wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
|
|
369
|
+
if (dtlen < ftlen) {
|
|
370
|
+
lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
|
|
371
|
+
var llm = hMap(lct, mlcb, 0);
|
|
372
|
+
wbits(out, p, nlc - 257);
|
|
373
|
+
wbits(out, p + 5, ndc - 1);
|
|
374
|
+
wbits(out, p + 10, nlcc - 4);
|
|
375
|
+
p += 14;
|
|
376
|
+
for (var i = 0; i < nlcc; ++i)
|
|
377
|
+
wbits(out, p + 3 * i, lct[clim[i]]);
|
|
378
|
+
p += 3 * nlcc;
|
|
379
|
+
var lcts = [lclt, lcdt];
|
|
380
|
+
for (var it = 0; it < 2; ++it) {
|
|
381
|
+
var clct = lcts[it];
|
|
382
|
+
for (var i = 0; i < clct.length; ++i) {
|
|
383
|
+
var len = clct[i] & 31;
|
|
384
|
+
wbits(out, p, llm[len]), p += lct[len];
|
|
385
|
+
if (len > 15)
|
|
386
|
+
wbits(out, p, clct[i] >> 5 & 127), p += clct[i] >> 12;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
lm = flm, ll = flt, dm = fdm, dl = fdt;
|
|
391
|
+
}
|
|
392
|
+
for (var i = 0; i < li; ++i) {
|
|
393
|
+
var sym = syms[i];
|
|
394
|
+
if (sym > 255) {
|
|
395
|
+
var len = sym >> 18 & 31;
|
|
396
|
+
wbits16(out, p, lm[len + 257]), p += ll[len + 257];
|
|
397
|
+
if (len > 7)
|
|
398
|
+
wbits(out, p, sym >> 23 & 31), p += fleb[len];
|
|
399
|
+
var dst = sym & 31;
|
|
400
|
+
wbits16(out, p, dm[dst]), p += dl[dst];
|
|
401
|
+
if (dst > 3)
|
|
402
|
+
wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
|
|
403
|
+
} else {
|
|
404
|
+
wbits16(out, p, lm[sym]), p += ll[sym];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
wbits16(out, p, lm[256]);
|
|
408
|
+
return p + ll[256];
|
|
409
|
+
};
|
|
410
|
+
var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
|
|
411
|
+
var et = /* @__PURE__ */ new u8(0);
|
|
412
|
+
var dflt = function(dat, lvl, plvl, pre, post, st) {
|
|
413
|
+
var s = st.z || dat.length;
|
|
414
|
+
var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7e3)) + post);
|
|
415
|
+
var w = o.subarray(pre, o.length - post);
|
|
416
|
+
var lst = st.l;
|
|
417
|
+
var pos = (st.r || 0) & 7;
|
|
418
|
+
if (lvl) {
|
|
419
|
+
if (pos)
|
|
420
|
+
w[0] = st.r >> 3;
|
|
421
|
+
var opt = deo[lvl - 1];
|
|
422
|
+
var n = opt >> 13, c = opt & 8191;
|
|
423
|
+
var msk_1 = (1 << plvl) - 1;
|
|
424
|
+
var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
|
|
425
|
+
var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
|
|
426
|
+
var hsh = function(i2) {
|
|
427
|
+
return (dat[i2] ^ dat[i2 + 1] << bs1_1 ^ dat[i2 + 2] << bs2_1) & msk_1;
|
|
428
|
+
};
|
|
429
|
+
var syms = new i32(25e3);
|
|
430
|
+
var lf = new u16(288), df = new u16(32);
|
|
431
|
+
var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
|
|
432
|
+
for (; i + 2 < s; ++i) {
|
|
433
|
+
var hv = hsh(i);
|
|
434
|
+
var imod = i & 32767, pimod = head[hv];
|
|
435
|
+
prev[imod] = pimod;
|
|
436
|
+
head[hv] = imod;
|
|
437
|
+
if (wi <= i) {
|
|
438
|
+
var rem = s - i;
|
|
439
|
+
if ((lc_1 > 7e3 || li > 24576) && (rem > 423 || !lst)) {
|
|
440
|
+
pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
441
|
+
li = lc_1 = eb = 0, bs = i;
|
|
442
|
+
for (var j = 0; j < 286; ++j)
|
|
443
|
+
lf[j] = 0;
|
|
444
|
+
for (var j = 0; j < 30; ++j)
|
|
445
|
+
df[j] = 0;
|
|
446
|
+
}
|
|
447
|
+
var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
|
|
448
|
+
if (rem > 2 && hv == hsh(i - dif)) {
|
|
449
|
+
var maxn = Math.min(n, rem) - 1;
|
|
450
|
+
var maxd = Math.min(32767, i);
|
|
451
|
+
var ml = Math.min(258, rem);
|
|
452
|
+
while (dif <= maxd && --ch_1 && imod != pimod) {
|
|
453
|
+
if (dat[i + l] == dat[i + l - dif]) {
|
|
454
|
+
var nl = 0;
|
|
455
|
+
for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)
|
|
456
|
+
;
|
|
457
|
+
if (nl > l) {
|
|
458
|
+
l = nl, d = dif;
|
|
459
|
+
if (nl > maxn)
|
|
460
|
+
break;
|
|
461
|
+
var mmd = Math.min(dif, nl - 2);
|
|
462
|
+
var md = 0;
|
|
463
|
+
for (var j = 0; j < mmd; ++j) {
|
|
464
|
+
var ti = i - dif + j & 32767;
|
|
465
|
+
var pti = prev[ti];
|
|
466
|
+
var cd = ti - pti & 32767;
|
|
467
|
+
if (cd > md)
|
|
468
|
+
md = cd, pimod = ti;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
imod = pimod, pimod = prev[imod];
|
|
473
|
+
dif += imod - pimod & 32767;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (d) {
|
|
477
|
+
syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
|
|
478
|
+
var lin = revfl[l] & 31, din = revfd[d] & 31;
|
|
479
|
+
eb += fleb[lin] + fdeb[din];
|
|
480
|
+
++lf[257 + lin];
|
|
481
|
+
++df[din];
|
|
482
|
+
wi = i + l;
|
|
483
|
+
++lc_1;
|
|
484
|
+
} else {
|
|
485
|
+
syms[li++] = dat[i];
|
|
486
|
+
++lf[dat[i]];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for (i = Math.max(i, wi); i < s; ++i) {
|
|
491
|
+
syms[li++] = dat[i];
|
|
492
|
+
++lf[dat[i]];
|
|
493
|
+
}
|
|
494
|
+
pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
495
|
+
if (!lst) {
|
|
496
|
+
st.r = pos & 7 | w[pos / 8 | 0] << 3;
|
|
497
|
+
pos -= 7;
|
|
498
|
+
st.h = head, st.p = prev, st.i = i, st.w = wi;
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
for (var i = st.w || 0; i < s + lst; i += 65535) {
|
|
502
|
+
var e = i + 65535;
|
|
503
|
+
if (e >= s) {
|
|
504
|
+
w[pos / 8 | 0] = lst;
|
|
505
|
+
e = s;
|
|
506
|
+
}
|
|
507
|
+
pos = wfblk(w, pos + 1, dat.subarray(i, e));
|
|
508
|
+
}
|
|
509
|
+
st.i = s;
|
|
510
|
+
}
|
|
511
|
+
return slc(o, 0, pre + shft(pos) + post);
|
|
512
|
+
};
|
|
513
|
+
var crct = /* @__PURE__ */ (function() {
|
|
514
|
+
var t = new Int32Array(256);
|
|
515
|
+
for (var i = 0; i < 256; ++i) {
|
|
516
|
+
var c = i, k = 9;
|
|
517
|
+
while (--k)
|
|
518
|
+
c = (c & 1 && -306674912) ^ c >>> 1;
|
|
519
|
+
t[i] = c;
|
|
520
|
+
}
|
|
521
|
+
return t;
|
|
522
|
+
})();
|
|
523
|
+
var crc = function() {
|
|
524
|
+
var c = -1;
|
|
525
|
+
return {
|
|
526
|
+
p: function(d) {
|
|
527
|
+
var cr = c;
|
|
528
|
+
for (var i = 0; i < d.length; ++i)
|
|
529
|
+
cr = crct[cr & 255 ^ d[i]] ^ cr >>> 8;
|
|
530
|
+
c = cr;
|
|
531
|
+
},
|
|
532
|
+
d: function() {
|
|
533
|
+
return ~c;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
var dopt = function(dat, opt, pre, post, st) {
|
|
538
|
+
if (!st) {
|
|
539
|
+
st = { l: 1 };
|
|
540
|
+
if (opt.dictionary) {
|
|
541
|
+
var dict = opt.dictionary.subarray(-32768);
|
|
542
|
+
var newDat = new u8(dict.length + dat.length);
|
|
543
|
+
newDat.set(dict);
|
|
544
|
+
newDat.set(dat, dict.length);
|
|
545
|
+
dat = newDat;
|
|
546
|
+
st.w = dict.length;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
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);
|
|
550
|
+
};
|
|
551
|
+
var mrg = function(a, b) {
|
|
552
|
+
var o = {};
|
|
553
|
+
for (var k in a)
|
|
554
|
+
o[k] = a[k];
|
|
555
|
+
for (var k in b)
|
|
556
|
+
o[k] = b[k];
|
|
557
|
+
return o;
|
|
558
|
+
};
|
|
559
|
+
var wbytes = function(d, b, v) {
|
|
560
|
+
for (; v; ++b)
|
|
561
|
+
d[b] = v, v >>>= 8;
|
|
562
|
+
};
|
|
563
|
+
function deflateSync(data, opts) {
|
|
564
|
+
return dopt(data, opts || {}, 0, 0);
|
|
565
|
+
}
|
|
566
|
+
var fltn = function(d, p, t, o) {
|
|
567
|
+
for (var k in d) {
|
|
568
|
+
var val = d[k], n = p + k, op = o;
|
|
569
|
+
if (Array.isArray(val))
|
|
570
|
+
op = mrg(o, val[1]), val = val[0];
|
|
571
|
+
if (ArrayBuffer.isView(val))
|
|
572
|
+
t[n] = [val, op];
|
|
573
|
+
else {
|
|
574
|
+
t[n += "/"] = [new u8(0), op];
|
|
575
|
+
fltn(val, n, t, o);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
|
|
580
|
+
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
|
|
581
|
+
var tds = 0;
|
|
582
|
+
try {
|
|
583
|
+
td.decode(et, { stream: true });
|
|
584
|
+
tds = 1;
|
|
585
|
+
} catch (e) {
|
|
586
|
+
}
|
|
587
|
+
function strToU8(str, latin1) {
|
|
588
|
+
if (latin1) {
|
|
589
|
+
var ar_1 = new u8(str.length);
|
|
590
|
+
for (var i = 0; i < str.length; ++i)
|
|
591
|
+
ar_1[i] = str.charCodeAt(i);
|
|
592
|
+
return ar_1;
|
|
593
|
+
}
|
|
594
|
+
if (te)
|
|
595
|
+
return te.encode(str);
|
|
596
|
+
var l = str.length;
|
|
597
|
+
var ar = new u8(str.length + (str.length >> 1));
|
|
598
|
+
var ai = 0;
|
|
599
|
+
var w = function(v) {
|
|
600
|
+
ar[ai++] = v;
|
|
601
|
+
};
|
|
602
|
+
for (var i = 0; i < l; ++i) {
|
|
603
|
+
if (ai + 5 > ar.length) {
|
|
604
|
+
var n = new u8(ai + 8 + (l - i << 1));
|
|
605
|
+
n.set(ar);
|
|
606
|
+
ar = n;
|
|
607
|
+
}
|
|
608
|
+
var c = str.charCodeAt(i);
|
|
609
|
+
if (c < 128 || latin1)
|
|
610
|
+
w(c);
|
|
611
|
+
else if (c < 2048)
|
|
612
|
+
w(192 | c >> 6), w(128 | c & 63);
|
|
613
|
+
else if (c > 55295 && c < 57344)
|
|
614
|
+
c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
615
|
+
else
|
|
616
|
+
w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
617
|
+
}
|
|
618
|
+
return slc(ar, 0, ai);
|
|
619
|
+
}
|
|
620
|
+
var exfl = function(ex) {
|
|
621
|
+
var le = 0;
|
|
622
|
+
if (ex) {
|
|
623
|
+
for (var k in ex) {
|
|
624
|
+
var l = ex[k].length;
|
|
625
|
+
if (l > 65535)
|
|
626
|
+
err(9);
|
|
627
|
+
le += l + 4;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return le;
|
|
631
|
+
};
|
|
632
|
+
var wzh = function(d, b, f, fn, u, c, ce, co) {
|
|
633
|
+
var fl2 = fn.length, ex = f.extra, col = co && co.length;
|
|
634
|
+
var exl = exfl(ex);
|
|
635
|
+
wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
|
|
636
|
+
if (ce != null)
|
|
637
|
+
d[b++] = 20, d[b++] = f.os;
|
|
638
|
+
d[b] = 20, b += 2;
|
|
639
|
+
d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
|
|
640
|
+
d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
|
|
641
|
+
var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
|
|
642
|
+
if (y < 0 || y > 119)
|
|
643
|
+
err(10);
|
|
644
|
+
wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
|
|
645
|
+
if (c != -1) {
|
|
646
|
+
wbytes(d, b, f.crc);
|
|
647
|
+
wbytes(d, b + 4, c < 0 ? -c - 2 : c);
|
|
648
|
+
wbytes(d, b + 8, f.size);
|
|
649
|
+
}
|
|
650
|
+
wbytes(d, b + 12, fl2);
|
|
651
|
+
wbytes(d, b + 14, exl), b += 16;
|
|
652
|
+
if (ce != null) {
|
|
653
|
+
wbytes(d, b, col);
|
|
654
|
+
wbytes(d, b + 6, f.attrs);
|
|
655
|
+
wbytes(d, b + 10, ce), b += 14;
|
|
656
|
+
}
|
|
657
|
+
d.set(fn, b);
|
|
658
|
+
b += fl2;
|
|
659
|
+
if (exl) {
|
|
660
|
+
for (var k in ex) {
|
|
661
|
+
var exf = ex[k], l = exf.length;
|
|
662
|
+
wbytes(d, b, +k);
|
|
663
|
+
wbytes(d, b + 2, l);
|
|
664
|
+
d.set(exf, b + 4), b += 4 + l;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (col)
|
|
668
|
+
d.set(co, b), b += col;
|
|
669
|
+
return b;
|
|
670
|
+
};
|
|
671
|
+
var wzf = function(o, b, c, d, e) {
|
|
672
|
+
wbytes(o, b, 101010256);
|
|
673
|
+
wbytes(o, b + 8, c);
|
|
674
|
+
wbytes(o, b + 10, c);
|
|
675
|
+
wbytes(o, b + 12, d);
|
|
676
|
+
wbytes(o, b + 16, e);
|
|
677
|
+
};
|
|
678
|
+
function zipSync(data, opts) {
|
|
679
|
+
if (!opts)
|
|
680
|
+
opts = {};
|
|
681
|
+
var r = {};
|
|
682
|
+
var files = [];
|
|
683
|
+
fltn(data, "", r, opts);
|
|
684
|
+
var o = 0;
|
|
685
|
+
var tot = 0;
|
|
686
|
+
for (var fn in r) {
|
|
687
|
+
var _a2 = r[fn], file = _a2[0], p = _a2[1];
|
|
688
|
+
var compression = p.level == 0 ? 0 : 8;
|
|
689
|
+
var f = strToU8(fn), s = f.length;
|
|
690
|
+
var com = p.comment, m = com && strToU8(com), ms = m && m.length;
|
|
691
|
+
var exl = exfl(p.extra);
|
|
692
|
+
if (s > 65535)
|
|
693
|
+
err(11);
|
|
694
|
+
var d = compression ? deflateSync(file, p) : file, l = d.length;
|
|
695
|
+
var c = crc();
|
|
696
|
+
c.p(file);
|
|
697
|
+
files.push(mrg(p, {
|
|
698
|
+
size: file.length,
|
|
699
|
+
crc: c.d(),
|
|
700
|
+
c: d,
|
|
701
|
+
f,
|
|
702
|
+
m,
|
|
703
|
+
u: s != fn.length || m && com.length != ms,
|
|
704
|
+
o,
|
|
705
|
+
compression
|
|
706
|
+
}));
|
|
707
|
+
o += 30 + s + exl + l;
|
|
708
|
+
tot += 76 + 2 * (s + exl) + (ms || 0) + l;
|
|
709
|
+
}
|
|
710
|
+
var out = new u8(tot + 22), oe = o, cdl = tot - o;
|
|
711
|
+
for (var i = 0; i < files.length; ++i) {
|
|
712
|
+
var f = files[i];
|
|
713
|
+
wzh(out, f.o, f, f.f, f.u, f.c.length);
|
|
714
|
+
var badd = 30 + f.f.length + exfl(f.extra);
|
|
715
|
+
out.set(f.c, f.o + badd);
|
|
716
|
+
wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
|
|
717
|
+
}
|
|
718
|
+
wzf(out, o, files.length, cdl, oe);
|
|
719
|
+
return out;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/functions.ts
|
|
723
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
724
|
+
import { dirname, resolve } from "node:path";
|
|
725
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
726
|
+
async function packageFunctions(entry, output) {
|
|
727
|
+
const entryPath = resolve(entry);
|
|
728
|
+
if (!existsSync(entryPath)) throw new Error("Function entrypoint does not exist: " + entryPath);
|
|
729
|
+
const require3 = createRequire2(import.meta.url);
|
|
730
|
+
const azureFunctions = require3.resolve("@azure/functions");
|
|
731
|
+
const result = await build({
|
|
732
|
+
stdin: {
|
|
733
|
+
contents: [
|
|
734
|
+
"import { app } from " + JSON.stringify(azureFunctions) + ";",
|
|
735
|
+
'import { createAzureFunctionHandler } from "@backifydev/sdk";',
|
|
736
|
+
"import * as declarations from " + JSON.stringify(entryPath) + ";",
|
|
737
|
+
"const registered = new Set();",
|
|
738
|
+
"for (const [exportName, definition] of Object.entries(declarations)) {",
|
|
739
|
+
" if (!definition || definition.__backify?.capability !== 'functions') continue;",
|
|
740
|
+
" const name = definition.name ?? exportName;",
|
|
741
|
+
" if (!/^[A-Za-z][A-Za-z0-9_-]{0,99}$/.test(name) || registered.has(name)) throw new Error('Invalid or duplicate function name: ' + name);",
|
|
742
|
+
" registered.add(name);",
|
|
743
|
+
" app.http(name, { methods: ['POST'], authLevel: 'function', handler: createAzureFunctionHandler(definition) });",
|
|
744
|
+
"}",
|
|
745
|
+
"if (!registered.size) throw new Error('Export at least one Backify function declaration');"
|
|
746
|
+
].join("\n"),
|
|
747
|
+
resolveDir: dirname(entryPath),
|
|
748
|
+
sourcefile: "backify-functions-host.ts",
|
|
749
|
+
loader: "ts"
|
|
750
|
+
},
|
|
751
|
+
bundle: true,
|
|
752
|
+
platform: "node",
|
|
753
|
+
target: "node22",
|
|
754
|
+
format: "cjs",
|
|
755
|
+
write: false,
|
|
756
|
+
external: ["@azure/functions-core"],
|
|
757
|
+
outfile: "index.cjs",
|
|
758
|
+
sourcemap: false
|
|
759
|
+
});
|
|
760
|
+
const archive = zipSync({
|
|
761
|
+
"index.cjs": result.outputFiles[0].contents,
|
|
762
|
+
"host.json": strToU8(JSON.stringify({ version: "2.0" })),
|
|
763
|
+
"package.json": strToU8(JSON.stringify({ name: "backify-functions", version: "1.0.0", main: "index.cjs", private: true }))
|
|
764
|
+
});
|
|
765
|
+
const outputPath = resolve(output);
|
|
766
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
767
|
+
writeFileSync(outputPath, archive);
|
|
768
|
+
return outputPath;
|
|
769
|
+
}
|
|
770
|
+
|
|
3
771
|
// src/development.ts
|
|
4
|
-
import { existsSync as
|
|
5
|
-
import { join as join3, resolve as
|
|
772
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, readdirSync as readdirSync2, writeFileSync as writeFileSync4, renameSync, rmSync } from "node:fs";
|
|
773
|
+
import { join as join3, resolve as resolve3 } from "node:path";
|
|
6
774
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
7
775
|
import { randomUUID } from "node:crypto";
|
|
8
776
|
|
|
9
777
|
// src/setup.ts
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { basename, dirname, join as join2, resolve } from "node:path";
|
|
778
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync } from "node:fs";
|
|
779
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
12
780
|
import { spawnSync } from "node:child_process";
|
|
13
781
|
|
|
14
782
|
// ../platform/dist/delivery.js
|
|
@@ -70,6 +838,20 @@ These instructions are an explicit agent workflow, not a universal chat intercep
|
|
|
70
838
|
var INSTRUCTION_VERSION = 3;
|
|
71
839
|
var SDK_PACKAGE = "@backifydev/sdk";
|
|
72
840
|
var DOCS_URL = "https://docs.backify.dev";
|
|
841
|
+
var MAIL_LIMITS = Object.freeze({
|
|
842
|
+
monthlyAttempts: 25,
|
|
843
|
+
maximumRecipients: 50,
|
|
844
|
+
maximumAttachments: 10,
|
|
845
|
+
maximumAttachmentBytes: 10 * 1024 * 1024,
|
|
846
|
+
maximumBodyBytes: 256 * 1024,
|
|
847
|
+
maximumSubjectLength: 998,
|
|
848
|
+
maximumAddressLength: 254,
|
|
849
|
+
maximumAttachmentFilenameLength: 255,
|
|
850
|
+
maximumAttachmentContentTypeLength: 127,
|
|
851
|
+
maximumIdempotencyKeyLength: 128,
|
|
852
|
+
duplicateWindowMilliseconds: 5 * 60 * 1e3,
|
|
853
|
+
maximumRequestBytes: 16e6
|
|
854
|
+
});
|
|
73
855
|
var capability = (name, imp, description, stateful = false, provisioner = name) => ({ name, import: imp, version: 1, stateful, provisioner, docs: `${DOCS_URL}/capabilities/${name}`, description, destructiveRemovalRequiresApproval: stateful });
|
|
74
856
|
var CAPABILITIES = [
|
|
75
857
|
capability("auth", "auth", "Application users, organizations, roles, and permissions"),
|
|
@@ -78,7 +860,8 @@ var CAPABILITIES = [
|
|
|
78
860
|
capability("functions", "functions", "Server function declarations"),
|
|
79
861
|
capability("jobs", "jobs", "Reliable background work", true),
|
|
80
862
|
capability("scheduler", "jobs.schedule", "Scheduled job declarations"),
|
|
81
|
-
capability("events", "events", "
|
|
863
|
+
capability("events", "events", "Inbound webhooks and governed outbound HTTP", true),
|
|
864
|
+
{ ...capability("mail", "mail", "Server-only mail.send: to accepts an address or address array; 25 attempts per application per UTC month shared by all environments; 50 total To/CC/BCC recipients; 10 attachments totaling 10 MiB decoded; 256 KiB combined text/HTML; 998-character subject. Identical sends without an explicit idempotency key are deduplicated for a rolling 5 minutes. sensitive: true never stores original subjects or bodies. Read the mail capability guide and mail.limits before implementing sends.", true), limits: MAIL_LIMITS },
|
|
82
865
|
capability("secrets", "secrets", "Server-side secret retrieval", true),
|
|
83
866
|
capability("http", "http", "Governed outbound HTTP"),
|
|
84
867
|
capability("ai", "ai", "Provider-independent generative AI"),
|
|
@@ -180,13 +963,13 @@ function validateConfig(value) {
|
|
|
180
963
|
var BACKIFY_SCHEMA = { $schema: "https://json-schema.org/draft/2020-12/schema", $id: `${DOCS_URL}/schema/backify.json`, type: "object", additionalProperties: false, required: ["$schema", "platform", "sdk", "appId", "instructionVersion", "docs", "instructions"], properties: { $schema: { const: `${DOCS_URL}/schema/backify.json` }, platform: { const: "backify" }, sdk: { const: SDK_PACKAGE }, appId: { type: "string", pattern: "^app_[A-Za-z0-9_-]+$" }, instructionVersion: { type: "integer", minimum: 1 }, docs: { type: "string", format: "uri" }, instructions: { type: "object", additionalProperties: false, required: ["preferBackifyCapabilities", "allowDirectCloudInfrastructure"], properties: { preferBackifyCapabilities: { const: true }, allowDirectCloudInfrastructure: { const: false } } } } };
|
|
181
964
|
|
|
182
965
|
// src/delivery.ts
|
|
183
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
966
|
+
import { existsSync as existsSync2, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
184
967
|
import { join } from "node:path";
|
|
185
968
|
import { createHash } from "node:crypto";
|
|
186
969
|
var previousGeneratedWorkflowHashes = /* @__PURE__ */ new Set(["6eb280ae7bdb14c390011686c41400f59c023304c3015d8440b7e80aaafa1c11", "545e03a1d5b996ade179e0e60ed5c86accdadc1982c1c25efd094e34f72f47ee"]);
|
|
187
970
|
function validateDeliveryInstructions(root) {
|
|
188
971
|
const path = join(root, "BACKIFY-WORKFLOW.md");
|
|
189
|
-
if (
|
|
972
|
+
if (existsSync2(path)) {
|
|
190
973
|
const existing = readFileSync(path, "utf8").replace(/\r\n/g, "\n");
|
|
191
974
|
if (existing !== deliveryInstructions && !previousGeneratedWorkflowHashes.has(createHash("sha256").update(existing).digest("hex"))) throw new Error("BACKIFY-WORKFLOW.md contains different instructions. Review it before initializing; it will not be overwritten.");
|
|
192
975
|
}
|
|
@@ -194,34 +977,34 @@ function validateDeliveryInstructions(root) {
|
|
|
194
977
|
function installDeliveryInstructions(root, instructionFiles2) {
|
|
195
978
|
validateDeliveryInstructions(root);
|
|
196
979
|
const path = join(root, "BACKIFY-WORKFLOW.md");
|
|
197
|
-
|
|
980
|
+
writeFileSync2(path, deliveryInstructions);
|
|
198
981
|
for (const relative of instructionFiles2) {
|
|
199
982
|
const instructionPath = join(root, relative), content = readFileSync(instructionPath, "utf8");
|
|
200
983
|
if (content.includes("## Backify delivery")) continue;
|
|
201
984
|
const link = relative.startsWith(".github") ? "../BACKIFY-WORKFLOW.md" : "BACKIFY-WORKFLOW.md";
|
|
202
|
-
|
|
985
|
+
writeFileSync2(instructionPath, content.trimEnd() + "\n\n## Backify delivery\n\nFor application delivery and recording each user request, follow [BACKIFY-WORKFLOW.md](" + link + ").\n");
|
|
203
986
|
}
|
|
204
987
|
}
|
|
205
988
|
|
|
206
989
|
// src/setup.ts
|
|
207
990
|
var instructionFiles = ["AGENTS.md", "CLAUDE.md", join2(".github", "copilot-instructions.md")];
|
|
208
991
|
function detectPackageManager(root = process.cwd()) {
|
|
209
|
-
for (const [file, name] of [["pnpm-lock.yaml", "pnpm"], ["yarn.lock", "yarn"], ["bun.lockb", "bun"], ["bun.lock", "bun"], ["package-lock.json", "npm"]]) if (
|
|
992
|
+
for (const [file, name] of [["pnpm-lock.yaml", "pnpm"], ["yarn.lock", "yarn"], ["bun.lockb", "bun"], ["bun.lock", "bun"], ["package-lock.json", "npm"]]) if (existsSync3(join2(root, file))) return name;
|
|
210
993
|
return "npm";
|
|
211
994
|
}
|
|
212
995
|
function updateInstructions(root = process.cwd()) {
|
|
213
996
|
const updates = instructionFiles.map((relative) => {
|
|
214
997
|
const path = join2(root, relative);
|
|
215
|
-
return { path, content: updateManagedInstructions(
|
|
998
|
+
return { path, content: updateManagedInstructions(existsSync3(path) ? readFileSync2(path, "utf8") : "") };
|
|
216
999
|
});
|
|
217
1000
|
for (const { path, content } of updates) {
|
|
218
|
-
|
|
219
|
-
|
|
1001
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
1002
|
+
writeFileSync3(path, content);
|
|
220
1003
|
}
|
|
221
1004
|
}
|
|
222
1005
|
function synchronize(root = process.cwd()) {
|
|
223
1006
|
const path = join2(root, "backify.json");
|
|
224
|
-
if (!
|
|
1007
|
+
if (!existsSync3(path)) throw new Error("backify.json is missing; run backify init --app app_xxxxx");
|
|
225
1008
|
const value = JSON.parse(readFileSync2(path, "utf8")), issues = validateConfig(value);
|
|
226
1009
|
if (issues.length) throw new Error(issues.join("; "));
|
|
227
1010
|
if (value.instructionVersion > INSTRUCTION_VERSION) throw new Error("This app uses newer instructions. Install a matching or newer CLI before syncing.");
|
|
@@ -229,10 +1012,10 @@ function synchronize(root = process.cwd()) {
|
|
|
229
1012
|
updateInstructions(root);
|
|
230
1013
|
installDeliveryInstructions(root, instructionFiles);
|
|
231
1014
|
value.instructionVersion = INSTRUCTION_VERSION;
|
|
232
|
-
|
|
1015
|
+
writeFileSync3(path, JSON.stringify(value, null, 2) + "\n");
|
|
233
1016
|
}
|
|
234
1017
|
function writeConfig(appId, root = process.cwd()) {
|
|
235
|
-
|
|
1018
|
+
writeFileSync3(join2(root, "backify.json"), JSON.stringify(createConfig(appId), null, 2) + "\n");
|
|
236
1019
|
}
|
|
237
1020
|
function sdkInstalled(root = process.cwd()) {
|
|
238
1021
|
try {
|
|
@@ -249,11 +1032,11 @@ function installSdk(root = process.cwd()) {
|
|
|
249
1032
|
}
|
|
250
1033
|
function ensurePackageManifest(root) {
|
|
251
1034
|
const path = join2(root, "package.json");
|
|
252
|
-
if (
|
|
1035
|
+
if (existsSync3(path)) return;
|
|
253
1036
|
const setupFiles = /* @__PURE__ */ new Set([".git", ".gitignore", ".github", "AGENTS.md", "CLAUDE.md", "README.md", "LICENSE", "backify.json"]);
|
|
254
1037
|
if (readdirSync(root).some((file) => !setupFiles.has(file))) throw new Error("package.json is missing. Run backify init from the existing application's JavaScript/TypeScript package directory, or start in an empty folder. See https://agent.backify.dev/");
|
|
255
|
-
const name = basename(
|
|
256
|
-
|
|
1038
|
+
const name = basename(resolve2(root)).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "backify-app";
|
|
1039
|
+
writeFileSync3(path, JSON.stringify({ name, version: "0.0.0", private: true, type: "module" }, null, 2) + "\n", { flag: "wx" });
|
|
257
1040
|
}
|
|
258
1041
|
function initialize(appId, root = process.cwd(), install = true) {
|
|
259
1042
|
if (!/^app_[A-Za-z0-9_-]+$/.test(appId)) throw new Error("Provide an application ID using --app app_xxxxx");
|
|
@@ -276,7 +1059,7 @@ function doctor(root = process.cwd()) {
|
|
|
276
1059
|
if (config && config.instructionVersion !== INSTRUCTION_VERSION) issues.push(`Repository instruction version ${config.instructionVersion}; CLI version ${INSTRUCTION_VERSION}. Use the matching CLI or run backify sync to upgrade.`);
|
|
277
1060
|
for (const relative of instructionFiles) {
|
|
278
1061
|
const path = join2(root, relative);
|
|
279
|
-
if (!
|
|
1062
|
+
if (!existsSync3(path)) {
|
|
280
1063
|
issues.push(`${relative} is missing`);
|
|
281
1064
|
continue;
|
|
282
1065
|
}
|
|
@@ -300,7 +1083,7 @@ function applicationGuid(appId) {
|
|
|
300
1083
|
return [value.slice(0, 8), value.slice(8, 12), value.slice(12, 16), value.slice(16, 20), value.slice(20)].join("-");
|
|
301
1084
|
}
|
|
302
1085
|
function projectApplication(root = process.cwd()) {
|
|
303
|
-
if (!
|
|
1086
|
+
if (!existsSync4(join3(root, "backify.json"))) throw new Error("Run backify connect --app <application-id>, then backify init.");
|
|
304
1087
|
return JSON.parse(readFileSync3(join3(root, "backify.json"), "utf8")).appId;
|
|
305
1088
|
}
|
|
306
1089
|
function apiAddress(value) {
|
|
@@ -329,7 +1112,7 @@ function apiClient(session, transport = fetch) {
|
|
|
329
1112
|
function saveUserConfig(path, config) {
|
|
330
1113
|
const temporary = path + "." + randomUUID() + ".tmp";
|
|
331
1114
|
try {
|
|
332
|
-
|
|
1115
|
+
writeFileSync4(temporary, JSON.stringify(config, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
333
1116
|
if (process.platform === "win32") {
|
|
334
1117
|
const account = [process.env.USERDOMAIN, process.env.USERNAME].filter(Boolean).join("\\");
|
|
335
1118
|
if (!account) throw new Error("Cannot identify the account to protect CLI credentials.");
|
|
@@ -404,23 +1187,23 @@ function localReport(runChecks, root = process.cwd()) {
|
|
|
404
1187
|
dirty = Boolean(git(["status", "--porcelain"], root));
|
|
405
1188
|
} catch {
|
|
406
1189
|
}
|
|
407
|
-
const outputDirectory = ["dist", "build", "out", "."].find((directory) =>
|
|
408
|
-
return { framework, sdkVersion: dependencies["@backifydev/sdk"] ?? null, branch, commitSha, dirty, buildCommand: pkg.scripts?.build ? manager + " run build" : null, outputDirectory, hasDockerfile:
|
|
1190
|
+
const outputDirectory = ["dist", "build", "out", "."].find((directory) => existsSync4(join3(root, directory, "index.html"))) ?? null;
|
|
1191
|
+
return { framework, sdkVersion: dependencies["@backifydev/sdk"] ?? null, branch, commitSha, dirty, buildCommand: pkg.scripts?.build ? manager + " run build" : null, outputDirectory, hasDockerfile: existsSync4(join3(root, "Dockerfile")), checks };
|
|
409
1192
|
}
|
|
410
1193
|
function matchesSource(release, commit) {
|
|
411
1194
|
return release?.commitSha === commit || release?.sourceCommitSha === commit;
|
|
412
1195
|
}
|
|
413
1196
|
async function waitForPreview(call2, prefix, commit, options = {}) {
|
|
414
1197
|
const deadline = Date.now() + (options.timeoutMs ?? 20 * 6e4);
|
|
415
|
-
const sleep = options.sleep ?? ((delay) => new Promise((
|
|
1198
|
+
const sleep = options.sleep ?? ((delay) => new Promise((resolve4) => setTimeout(resolve4, delay)));
|
|
416
1199
|
do {
|
|
417
1200
|
const deployments = await call2(prefix + "/deployments");
|
|
418
1201
|
const matching = deployments.find((release) => release.kind === "preview" && matchesSource(release, commit) && !options.previousDeploymentIds?.includes(release.id));
|
|
419
1202
|
if (matching?.status === "failed") throw new Error("Deployment of this source failed. Run backify status and inspect its deployment steps.");
|
|
420
1203
|
const overview = await call2(prefix + "/releases");
|
|
421
1204
|
if (matchesSource(overview.preview, commit) && overview.preview?.status === "succeeded" && overview.preview.healthResult === "healthy") return overview;
|
|
422
|
-
const
|
|
423
|
-
if ((options.previousBuildRunId === void 0 ||
|
|
1205
|
+
const build2 = await call2(prefix + "/developer/build?commitSha=" + commit);
|
|
1206
|
+
if ((options.previousBuildRunId === void 0 || build2.runId !== options.previousBuildRunId) && ["failure", "cancelled", "timed_out", "action_required", "startup_failure"].includes(build2.conclusion ?? "")) throw new Error("GitHub build " + build2.conclusion + ". " + (build2.url ?? "Run backify status for details."));
|
|
424
1207
|
await sleep(options.intervalMs ?? 4e3);
|
|
425
1208
|
} while (Date.now() < deadline);
|
|
426
1209
|
throw new Error("Timed out waiting for this commit's healthy preview. Run backify status; no production release was requested.");
|
|
@@ -432,7 +1215,7 @@ async function ship(call2, appId, options = {}) {
|
|
|
432
1215
|
if (!doctor(root).valid) throw new Error("Run backify doctor and fix project setup before shipping.");
|
|
433
1216
|
if (applicationGuid(projectApplication(root)) !== applicationGuid(appId)) throw new Error("Local application ID does not match the application being shipped.");
|
|
434
1217
|
const actualRoot = git(["rev-parse", "--show-toplevel"], root);
|
|
435
|
-
if (
|
|
1218
|
+
if (resolve3(actualRoot).toLowerCase() !== resolve3(root).toLowerCase()) throw new Error("Shipping currently requires the application at the repository root.");
|
|
436
1219
|
const origin = git(["remote", "get-url", "origin"], root);
|
|
437
1220
|
const pushOrigin = git(["remote", "get-url", "--push", "origin"], root);
|
|
438
1221
|
if (repositoryName(origin) !== status.repository.toLowerCase() || repositoryName(pushOrigin) !== status.repository.toLowerCase()) throw new Error("Local repository does not match this Backify application.");
|
|
@@ -482,24 +1265,24 @@ async function publishPreview(call2, prefix, overview, options = {}) {
|
|
|
482
1265
|
if (releases.live?.previewDeploymentId !== preview.id || releases.live.status !== "succeeded" || releases.live.healthResult !== "healthy") throw new Error("Production did not activate this healthy release. Run backify status.");
|
|
483
1266
|
return { status: "live", url: releases.live.url };
|
|
484
1267
|
}
|
|
485
|
-
await new Promise((
|
|
1268
|
+
await new Promise((resolve4) => setTimeout(resolve4, 4e3));
|
|
486
1269
|
} while (Date.now() < deadline);
|
|
487
1270
|
throw new Error("Publication is still pending. Run backify status; deployment success has not been verified.");
|
|
488
1271
|
}
|
|
489
1272
|
|
|
490
1273
|
// src/index.ts
|
|
491
|
-
import { readFileSync as readFileSync4, existsSync as
|
|
1274
|
+
import { readFileSync as readFileSync4, existsSync as existsSync5, rmSync as rmSync2 } from "node:fs";
|
|
492
1275
|
import { homedir } from "node:os";
|
|
493
1276
|
import { join as join4 } from "node:path";
|
|
494
1277
|
import { randomBytes } from "node:crypto";
|
|
495
1278
|
import { createServer } from "node:http";
|
|
496
1279
|
import { spawn } from "node:child_process";
|
|
497
1280
|
var configPath = join4(homedir(), ".backify.json");
|
|
498
|
-
var userConfig =
|
|
1281
|
+
var userConfig = existsSync5(configPath) ? JSON.parse(readFileSync4(configPath, "utf8")) : {};
|
|
499
1282
|
var [command, ...args] = process.argv.slice(2);
|
|
500
1283
|
async function call(path, init) {
|
|
501
1284
|
let appId = option("--app");
|
|
502
|
-
if (!appId &&
|
|
1285
|
+
if (!appId && existsSync5(join4(process.cwd(), "backify.json"))) appId = projectApplication();
|
|
503
1286
|
const session = appId ? userConfig.sessions?.["app_" + applicationGuid(appId).replaceAll("-", "")] : void 0;
|
|
504
1287
|
return apiClient(session ?? { token: userConfig.token ?? "", organizationId: userConfig.organizationId ?? "", apiUrl: process.env.BACKIFY_API_URL ?? userConfig.apiUrl ?? "https://api.backify.dev/api" })(path, init);
|
|
505
1288
|
}
|
|
@@ -544,7 +1327,7 @@ async function browserLogin() {
|
|
|
544
1327
|
});
|
|
545
1328
|
let resolveLogin = () => {
|
|
546
1329
|
};
|
|
547
|
-
const completed = new Promise((
|
|
1330
|
+
const completed = new Promise((resolve4) => resolveLogin = resolve4);
|
|
548
1331
|
server.listen(0, "127.0.0.1", () => {
|
|
549
1332
|
const address = server.address();
|
|
550
1333
|
if (!address || typeof address === "string") throw new Error("Could not start local login callback");
|
|
@@ -570,6 +1353,21 @@ async function browserLogin() {
|
|
|
570
1353
|
}
|
|
571
1354
|
async function main() {
|
|
572
1355
|
switch (command) {
|
|
1356
|
+
case "functions": {
|
|
1357
|
+
if (args[0] === "package") {
|
|
1358
|
+
const entry = option("--entry");
|
|
1359
|
+
if (!entry) throw new Error("Use backify functions package --entry <functions.ts> [--out functions.zip]");
|
|
1360
|
+
console.log(await packageFunctions(entry, option("--out") ?? "functions.zip"));
|
|
1361
|
+
} else if (args[0] === "deploy") {
|
|
1362
|
+
const appId = applicationGuid(option("--app") ?? projectApplication());
|
|
1363
|
+
const environmentId = option("--environment");
|
|
1364
|
+
const packagePath = option("--package");
|
|
1365
|
+
if (!environmentId || !packagePath || !args.includes("--confirm")) throw new Error("Use backify functions deploy --environment <environment-id> --package <functions.zip> --confirm. This replaces the complete function project.");
|
|
1366
|
+
await call("/apps/" + appId + "/functions/environments/" + applicationGuid(environmentId) + "/deploy?confirm=true", { method: "POST", headers: { "content-type": "application/zip" }, body: new Uint8Array(readFileSync4(packagePath)) });
|
|
1367
|
+
console.log("Functions deployed.");
|
|
1368
|
+
} else throw new Error("Use backify functions package or backify functions deploy");
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
573
1371
|
case "init":
|
|
574
1372
|
initialize(option("--app") ?? args.find((value) => !value.startsWith("-")) ?? "");
|
|
575
1373
|
console.log("Backify initialized. SDK, delivery instructions, and prompt history guidance are ready.");
|
|
@@ -669,6 +1467,24 @@ async function main() {
|
|
|
669
1467
|
console.log(await call("/apps/requests", { method: "POST", body: JSON.stringify({ workspaceId, name, slug, description, configuration }) }));
|
|
670
1468
|
break;
|
|
671
1469
|
}
|
|
1470
|
+
case "events": {
|
|
1471
|
+
const appId = applicationGuid(option("--app") ?? projectApplication());
|
|
1472
|
+
const prefix = "/apps/" + appId + "/events";
|
|
1473
|
+
if (args[0] === "environments") {
|
|
1474
|
+
console.log(JSON.stringify(await call(prefix + "/environments"), null, 2));
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
const environment = option("--environment");
|
|
1478
|
+
if (!environment || !/^[0-9a-f-]{36}$/i.test(environment)) throw new Error("Use backify events environments, then events inspect|test --environment <UUID> [--name <event> --payload <json-file>]");
|
|
1479
|
+
const path = prefix + "/environments/" + environment;
|
|
1480
|
+
if (args[0] === "inspect") console.log(JSON.stringify(await call(path), null, 2));
|
|
1481
|
+
else if (args[0] === "test") {
|
|
1482
|
+
const name = option("--name"), payload = option("--payload");
|
|
1483
|
+
if (!name || !payload) throw new Error("Specify --name and --payload <json-file>. Never include secrets in event payloads.");
|
|
1484
|
+
console.log(JSON.stringify(await call(path + "/test", { method: "POST", body: JSON.stringify({ name, payload: JSON.parse(readFileSync4(payload, "utf8")), idempotencyKey: option("--idempotency-key") }) }), null, 2));
|
|
1485
|
+
} else throw new Error("Use backify events environments|inspect|test");
|
|
1486
|
+
break;
|
|
1487
|
+
}
|
|
672
1488
|
case "apps":
|
|
673
1489
|
console.table(await call("/apps"));
|
|
674
1490
|
break;
|
|
@@ -676,7 +1492,7 @@ async function main() {
|
|
|
676
1492
|
console.log(await call("/apps/" + applicationGuid(args[0]) + "/deployments/preview", { method: "POST", body: JSON.stringify({ sourceRevision: args[1] ?? "latest" }) }));
|
|
677
1493
|
break;
|
|
678
1494
|
default:
|
|
679
|
-
console.log("backify connect | init | doctor | sync | login | logout | disconnect | status | report [--check] | prompt record --stdin --id <UUID> | ship [--preview-only] | request | apps | deploy");
|
|
1495
|
+
console.log("backify connect | init | doctor | sync | login | logout | disconnect | status | report [--check] | prompt record --stdin --id <UUID> | ship [--preview-only] | request | events environments|inspect|test | apps | deploy");
|
|
680
1496
|
}
|
|
681
1497
|
}
|
|
682
1498
|
main().catch((error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backifydev/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Command-line setup and diagnostics for Backify applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
14
|
"prebuild": "npm run build --workspace @backify/platform",
|
|
15
|
-
"build": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js",
|
|
15
|
+
"build": "esbuild src/index.ts --bundle --platform=node --format=esm --external:esbuild --outfile=dist/index.js",
|
|
16
16
|
"prepack": "npm run build",
|
|
17
17
|
"pretypecheck": "npm run build --workspace @backify/platform",
|
|
18
18
|
"typecheck": "tsc --noEmit",
|
|
@@ -32,10 +32,14 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=20"
|
|
34
34
|
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@azure/functions": "^4.7.2",
|
|
37
|
+
"esbuild": "^0.25.10",
|
|
38
|
+
"fflate": "^0.8.2"
|
|
39
|
+
},
|
|
35
40
|
"devDependencies": {
|
|
36
41
|
"@backify/platform": "*",
|
|
37
42
|
"@types/node": "^24.3.1",
|
|
38
|
-
"esbuild": "^0.25.10",
|
|
39
43
|
"typescript": "^5.9.2",
|
|
40
44
|
"vitest": "^4.1.11"
|
|
41
45
|
}
|