norc-cli 0.2.2 → 0.3.1
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 +2296 -607
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -1260,11 +1260,11 @@ var require_serializer = __commonJS({
|
|
|
1260
1260
|
var _a;
|
|
1261
1261
|
return buffer instanceof ArrayBuffer || ((_a = buffer === null || buffer === void 0 ? void 0 : buffer.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer";
|
|
1262
1262
|
}
|
|
1263
|
-
_pick(
|
|
1264
|
-
if (!
|
|
1263
|
+
_pick(obj2, keys) {
|
|
1264
|
+
if (!obj2 || typeof obj2 !== "object") {
|
|
1265
1265
|
return {};
|
|
1266
1266
|
}
|
|
1267
|
-
return Object.fromEntries(Object.entries(
|
|
1267
|
+
return Object.fromEntries(Object.entries(obj2).filter(([key]) => keys.includes(key)));
|
|
1268
1268
|
}
|
|
1269
1269
|
};
|
|
1270
1270
|
exports2.default = Serializer;
|
|
@@ -1416,14 +1416,14 @@ var require_transformers = __commonJS({
|
|
|
1416
1416
|
const closeBrace = value[lastIdx];
|
|
1417
1417
|
const openBrace = value[0];
|
|
1418
1418
|
if (openBrace === "{" && closeBrace === "}") {
|
|
1419
|
-
let
|
|
1419
|
+
let arr2;
|
|
1420
1420
|
const valTrim = value.slice(1, lastIdx);
|
|
1421
1421
|
try {
|
|
1422
|
-
|
|
1422
|
+
arr2 = JSON.parse("[" + valTrim + "]");
|
|
1423
1423
|
} catch (_) {
|
|
1424
|
-
|
|
1424
|
+
arr2 = valTrim ? valTrim.split(",") : [];
|
|
1425
1425
|
}
|
|
1426
|
-
return
|
|
1426
|
+
return arr2.map((val) => (0, exports2.convertCell)(type, val));
|
|
1427
1427
|
}
|
|
1428
1428
|
return value;
|
|
1429
1429
|
};
|
|
@@ -2079,14 +2079,14 @@ var require_phoenix_cjs = __commonJS({
|
|
|
2079
2079
|
return null;
|
|
2080
2080
|
}
|
|
2081
2081
|
}
|
|
2082
|
-
static serialize(
|
|
2082
|
+
static serialize(obj2, parentKey) {
|
|
2083
2083
|
let queryStr = [];
|
|
2084
|
-
for (var key in
|
|
2085
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
2084
|
+
for (var key in obj2) {
|
|
2085
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
2086
2086
|
continue;
|
|
2087
2087
|
}
|
|
2088
2088
|
let paramKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
2089
|
-
let paramVal =
|
|
2089
|
+
let paramVal = obj2[key];
|
|
2090
2090
|
if (typeof paramVal === "object") {
|
|
2091
2091
|
queryStr.push(this.serialize(paramVal, paramKey));
|
|
2092
2092
|
} else {
|
|
@@ -2454,16 +2454,16 @@ var require_phoenix_cjs = __commonJS({
|
|
|
2454
2454
|
* @param {Record<string, PresenceState>} obj
|
|
2455
2455
|
* @param {(key: string, obj: PresenceState) => T} func
|
|
2456
2456
|
*/
|
|
2457
|
-
static map(
|
|
2458
|
-
return Object.getOwnPropertyNames(
|
|
2457
|
+
static map(obj2, func) {
|
|
2458
|
+
return Object.getOwnPropertyNames(obj2).map((key) => func(key, obj2[key]));
|
|
2459
2459
|
}
|
|
2460
2460
|
/**
|
|
2461
2461
|
* @template T
|
|
2462
2462
|
* @param {T} obj
|
|
2463
2463
|
* @returns {T}
|
|
2464
2464
|
*/
|
|
2465
|
-
static clone(
|
|
2466
|
-
return JSON.parse(JSON.stringify(
|
|
2465
|
+
static clone(obj2) {
|
|
2466
|
+
return JSON.parse(JSON.stringify(obj2));
|
|
2467
2467
|
}
|
|
2468
2468
|
};
|
|
2469
2469
|
var serializer_default = {
|
|
@@ -3414,10 +3414,10 @@ var require_normalizeChannelError = __commonJS({
|
|
|
3414
3414
|
return new Error(reason);
|
|
3415
3415
|
}
|
|
3416
3416
|
if (reason && typeof reason === "object") {
|
|
3417
|
-
const
|
|
3418
|
-
if (typeof
|
|
3419
|
-
const detail = typeof
|
|
3420
|
-
return new Error(`socket closed: ${
|
|
3417
|
+
const obj2 = reason;
|
|
3418
|
+
if (typeof obj2.code === "number") {
|
|
3419
|
+
const detail = typeof obj2.reason === "string" && obj2.reason ? ` (${obj2.reason})` : "";
|
|
3420
|
+
return new Error(`socket closed: ${obj2.code}${detail}`, { cause: reason });
|
|
3421
3421
|
}
|
|
3422
3422
|
return new Error("channel error: transport failure", { cause: reason });
|
|
3423
3423
|
}
|
|
@@ -4184,8 +4184,8 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4184
4184
|
}
|
|
4185
4185
|
/** @internal */
|
|
4186
4186
|
_notThisChannelEvent(event, ref) {
|
|
4187
|
-
const { close, error, leave, join:
|
|
4188
|
-
const events = [close, error, leave,
|
|
4187
|
+
const { close, error, leave, join: join7 } = constants_1.CHANNEL_EVENTS;
|
|
4188
|
+
const events = [close, error, leave, join7];
|
|
4189
4189
|
return ref && events.includes(event) && ref !== this.joinPush.ref;
|
|
4190
4190
|
}
|
|
4191
4191
|
/** @internal */
|
|
@@ -5331,19 +5331,19 @@ var require_base64url = __commonJS({
|
|
|
5331
5331
|
throw new Error(`Invalid Base64-URL character "${String.fromCharCode(charCode)}"`);
|
|
5332
5332
|
}
|
|
5333
5333
|
}
|
|
5334
|
-
function stringToBase64URL(
|
|
5334
|
+
function stringToBase64URL(str2) {
|
|
5335
5335
|
const base64 = [];
|
|
5336
5336
|
const emitter = (char) => {
|
|
5337
5337
|
base64.push(char);
|
|
5338
5338
|
};
|
|
5339
5339
|
const state = { queue: 0, queuedBits: 0 };
|
|
5340
|
-
stringToUTF8(
|
|
5340
|
+
stringToUTF8(str2, (byte) => {
|
|
5341
5341
|
byteToBase64URL(byte, state, emitter);
|
|
5342
5342
|
});
|
|
5343
5343
|
byteToBase64URL(null, state, emitter);
|
|
5344
5344
|
return base64.join("");
|
|
5345
5345
|
}
|
|
5346
|
-
function stringFromBase64URL(
|
|
5346
|
+
function stringFromBase64URL(str2) {
|
|
5347
5347
|
const conv = [];
|
|
5348
5348
|
const utf8Emit = (codepoint) => {
|
|
5349
5349
|
conv.push(String.fromCodePoint(codepoint));
|
|
@@ -5356,8 +5356,8 @@ var require_base64url = __commonJS({
|
|
|
5356
5356
|
const byteEmit = (byte) => {
|
|
5357
5357
|
stringFromUTF8(byte, utf8State, utf8Emit);
|
|
5358
5358
|
};
|
|
5359
|
-
for (let i = 0; i <
|
|
5360
|
-
byteFromBase64URL(
|
|
5359
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
5360
|
+
byteFromBase64URL(str2.charCodeAt(i), b64State, byteEmit);
|
|
5361
5361
|
}
|
|
5362
5362
|
return conv.join("");
|
|
5363
5363
|
}
|
|
@@ -5383,12 +5383,12 @@ var require_base64url = __commonJS({
|
|
|
5383
5383
|
}
|
|
5384
5384
|
throw new Error(`Unrecognized Unicode codepoint: ${codepoint.toString(16)}`);
|
|
5385
5385
|
}
|
|
5386
|
-
function stringToUTF8(
|
|
5387
|
-
for (let i = 0; i <
|
|
5388
|
-
let codepoint =
|
|
5386
|
+
function stringToUTF8(str2, emit) {
|
|
5387
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
5388
|
+
let codepoint = str2.charCodeAt(i);
|
|
5389
5389
|
if (codepoint > 55295 && codepoint <= 56319) {
|
|
5390
5390
|
const highSurrogate = (codepoint - 55296) * 1024 & 65535;
|
|
5391
|
-
const lowSurrogate =
|
|
5391
|
+
const lowSurrogate = str2.charCodeAt(i + 1) - 56320 & 65535;
|
|
5392
5392
|
codepoint = (lowSurrogate | highSurrogate) + 65536;
|
|
5393
5393
|
i += 1;
|
|
5394
5394
|
}
|
|
@@ -5428,20 +5428,20 @@ var require_base64url = __commonJS({
|
|
|
5428
5428
|
}
|
|
5429
5429
|
}
|
|
5430
5430
|
}
|
|
5431
|
-
function base64UrlToUint8Array(
|
|
5431
|
+
function base64UrlToUint8Array(str2) {
|
|
5432
5432
|
const result = [];
|
|
5433
5433
|
const state = { queue: 0, queuedBits: 0 };
|
|
5434
5434
|
const onByte = (byte) => {
|
|
5435
5435
|
result.push(byte);
|
|
5436
5436
|
};
|
|
5437
|
-
for (let i = 0; i <
|
|
5438
|
-
byteFromBase64URL(
|
|
5437
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
5438
|
+
byteFromBase64URL(str2.charCodeAt(i), state, onByte);
|
|
5439
5439
|
}
|
|
5440
5440
|
return new Uint8Array(result);
|
|
5441
5441
|
}
|
|
5442
|
-
function stringToUint8Array(
|
|
5442
|
+
function stringToUint8Array(str2) {
|
|
5443
5443
|
const result = [];
|
|
5444
|
-
stringToUTF8(
|
|
5444
|
+
stringToUTF8(str2, (byte) => result.push(byte));
|
|
5445
5445
|
return new Uint8Array(result);
|
|
5446
5446
|
}
|
|
5447
5447
|
function bytesToBase64URL(bytes) {
|
|
@@ -5720,8 +5720,8 @@ var require_helpers = __commonJS({
|
|
|
5720
5720
|
}
|
|
5721
5721
|
}
|
|
5722
5722
|
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
5723
|
-
function validateUUID(
|
|
5724
|
-
if (!UUID_REGEX.test(
|
|
5723
|
+
function validateUUID(str2) {
|
|
5724
|
+
if (!UUID_REGEX.test(str2)) {
|
|
5725
5725
|
throw new Error("@supabase/auth-js: Expected parameter to be UUID but is not");
|
|
5726
5726
|
}
|
|
5727
5727
|
}
|
|
@@ -5773,8 +5773,8 @@ var require_helpers = __commonJS({
|
|
|
5773
5773
|
}
|
|
5774
5774
|
});
|
|
5775
5775
|
}
|
|
5776
|
-
function deepClone(
|
|
5777
|
-
return JSON.parse(JSON.stringify(
|
|
5776
|
+
function deepClone(obj2) {
|
|
5777
|
+
return JSON.parse(JSON.stringify(obj2));
|
|
5778
5778
|
}
|
|
5779
5779
|
}
|
|
5780
5780
|
});
|
|
@@ -7731,10 +7731,10 @@ var require_webauthn = __commonJS({
|
|
|
7731
7731
|
authenticatorAttachment: (_a = credentialWithAttachment.authenticatorAttachment) !== null && _a !== void 0 ? _a : void 0
|
|
7732
7732
|
};
|
|
7733
7733
|
}
|
|
7734
|
-
function isValidDomain(
|
|
7734
|
+
function isValidDomain(hostname3) {
|
|
7735
7735
|
return (
|
|
7736
7736
|
// Consider localhost valid as well since it's okay wrt Secure Contexts
|
|
7737
|
-
|
|
7737
|
+
hostname3 === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname3)
|
|
7738
7738
|
);
|
|
7739
7739
|
}
|
|
7740
7740
|
function browserSupportsWebAuthn() {
|
|
@@ -13438,9 +13438,9 @@ var require_bit_buffer = __commonJS({
|
|
|
13438
13438
|
const bufIndex = Math.floor(index / 8);
|
|
13439
13439
|
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
13440
13440
|
},
|
|
13441
|
-
put: function(
|
|
13441
|
+
put: function(num2, length) {
|
|
13442
13442
|
for (let i = 0; i < length; i++) {
|
|
13443
|
-
this.putBit((
|
|
13443
|
+
this.putBit((num2 >>> length - i - 1 & 1) === 1);
|
|
13444
13444
|
}
|
|
13445
13445
|
},
|
|
13446
13446
|
getLengthInBits: function() {
|
|
@@ -14173,14 +14173,14 @@ var require_regex = __commonJS({
|
|
|
14173
14173
|
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
14174
14174
|
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
14175
14175
|
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
14176
|
-
exports2.testKanji = function testKanji(
|
|
14177
|
-
return TEST_KANJI.test(
|
|
14176
|
+
exports2.testKanji = function testKanji(str2) {
|
|
14177
|
+
return TEST_KANJI.test(str2);
|
|
14178
14178
|
};
|
|
14179
|
-
exports2.testNumeric = function testNumeric(
|
|
14180
|
-
return TEST_NUMERIC.test(
|
|
14179
|
+
exports2.testNumeric = function testNumeric(str2) {
|
|
14180
|
+
return TEST_NUMERIC.test(str2);
|
|
14181
14181
|
};
|
|
14182
|
-
exports2.testAlphanumeric = function testAlphanumeric(
|
|
14183
|
-
return TEST_ALPHANUMERIC.test(
|
|
14182
|
+
exports2.testAlphanumeric = function testAlphanumeric(str2) {
|
|
14183
|
+
return TEST_ALPHANUMERIC.test(str2);
|
|
14184
14184
|
};
|
|
14185
14185
|
}
|
|
14186
14186
|
});
|
|
@@ -14674,13 +14674,13 @@ var require_segments = __commonJS({
|
|
|
14674
14674
|
var Regex = require_regex();
|
|
14675
14675
|
var Utils = require_utils();
|
|
14676
14676
|
var dijkstra = require_dijkstra();
|
|
14677
|
-
function getStringByteLength(
|
|
14678
|
-
return unescape(encodeURIComponent(
|
|
14677
|
+
function getStringByteLength(str2) {
|
|
14678
|
+
return unescape(encodeURIComponent(str2)).length;
|
|
14679
14679
|
}
|
|
14680
|
-
function getSegments(regex, mode,
|
|
14680
|
+
function getSegments(regex, mode, str2) {
|
|
14681
14681
|
const segments = [];
|
|
14682
14682
|
let result;
|
|
14683
|
-
while ((result = regex.exec(
|
|
14683
|
+
while ((result = regex.exec(str2)) !== null) {
|
|
14684
14684
|
segments.push({
|
|
14685
14685
|
data: result[0],
|
|
14686
14686
|
index: result.index,
|
|
@@ -14705,11 +14705,11 @@ var require_segments = __commonJS({
|
|
|
14705
14705
|
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
14706
14706
|
return segs.sort(function(s1, s2) {
|
|
14707
14707
|
return s1.index - s2.index;
|
|
14708
|
-
}).map(function(
|
|
14708
|
+
}).map(function(obj2) {
|
|
14709
14709
|
return {
|
|
14710
|
-
data:
|
|
14711
|
-
mode:
|
|
14712
|
-
length:
|
|
14710
|
+
data: obj2.data,
|
|
14711
|
+
mode: obj2.mode,
|
|
14712
|
+
length: obj2.length
|
|
14713
14713
|
};
|
|
14714
14714
|
});
|
|
14715
14715
|
}
|
|
@@ -15209,19 +15209,19 @@ var require_chunkstream = __commonJS({
|
|
|
15209
15209
|
ChunkStream.prototype._processRead = function(read) {
|
|
15210
15210
|
this._reads.shift();
|
|
15211
15211
|
let pos = 0;
|
|
15212
|
-
let
|
|
15212
|
+
let count2 = 0;
|
|
15213
15213
|
let data = Buffer.alloc(read.length);
|
|
15214
15214
|
while (pos < read.length) {
|
|
15215
|
-
let buf = this._buffers[
|
|
15215
|
+
let buf = this._buffers[count2++];
|
|
15216
15216
|
let len = Math.min(buf.length, read.length - pos);
|
|
15217
15217
|
buf.copy(data, pos, 0, len);
|
|
15218
15218
|
pos += len;
|
|
15219
15219
|
if (len !== buf.length) {
|
|
15220
|
-
this._buffers[--
|
|
15220
|
+
this._buffers[--count2] = buf.slice(len);
|
|
15221
15221
|
}
|
|
15222
15222
|
}
|
|
15223
|
-
if (
|
|
15224
|
-
this._buffers.splice(0,
|
|
15223
|
+
if (count2 > 0) {
|
|
15224
|
+
this._buffers.splice(0, count2);
|
|
15225
15225
|
}
|
|
15226
15226
|
this._buffered -= read.length;
|
|
15227
15227
|
read.func.call(this, data);
|
|
@@ -15953,12 +15953,12 @@ var require_bitmapper = __commonJS({
|
|
|
15953
15953
|
}
|
|
15954
15954
|
}
|
|
15955
15955
|
return {
|
|
15956
|
-
get: function(
|
|
15957
|
-
while (leftOver.length <
|
|
15956
|
+
get: function(count2) {
|
|
15957
|
+
while (leftOver.length < count2) {
|
|
15958
15958
|
split();
|
|
15959
15959
|
}
|
|
15960
|
-
let returner = leftOver.slice(0,
|
|
15961
|
-
leftOver = leftOver.slice(
|
|
15960
|
+
let returner = leftOver.slice(0, count2);
|
|
15961
|
+
leftOver = leftOver.slice(count2);
|
|
15962
15962
|
return returner;
|
|
15963
15963
|
},
|
|
15964
15964
|
resetAfterLine: function() {
|
|
@@ -17506,13 +17506,13 @@ var require_svg_tag = __commonJS({
|
|
|
17506
17506
|
var Utils = require_utils2();
|
|
17507
17507
|
function getColorAttrib(color, attrib) {
|
|
17508
17508
|
const alpha = color.a / 255;
|
|
17509
|
-
const
|
|
17510
|
-
return alpha < 1 ?
|
|
17509
|
+
const str2 = attrib + '="' + color.hex + '"';
|
|
17510
|
+
return alpha < 1 ? str2 + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str2;
|
|
17511
17511
|
}
|
|
17512
17512
|
function svgCmd(cmd, x, y) {
|
|
17513
|
-
let
|
|
17514
|
-
if (typeof y !== "undefined")
|
|
17515
|
-
return
|
|
17513
|
+
let str2 = cmd + x;
|
|
17514
|
+
if (typeof y !== "undefined") str2 += " " + y;
|
|
17515
|
+
return str2;
|
|
17516
17516
|
}
|
|
17517
17517
|
function qrToPath(data, size, margin) {
|
|
17518
17518
|
let path = "";
|
|
@@ -18611,16 +18611,16 @@ var require_luxon = __commonJS({
|
|
|
18611
18611
|
this.rtf = getCachedRTF(intl, opts);
|
|
18612
18612
|
}
|
|
18613
18613
|
}
|
|
18614
|
-
format(
|
|
18614
|
+
format(count2, unit) {
|
|
18615
18615
|
if (this.rtf) {
|
|
18616
|
-
return this.rtf.format(
|
|
18616
|
+
return this.rtf.format(count2, unit);
|
|
18617
18617
|
} else {
|
|
18618
|
-
return formatRelativeTime(unit,
|
|
18618
|
+
return formatRelativeTime(unit, count2, this.opts.numeric, this.opts.style !== "long");
|
|
18619
18619
|
}
|
|
18620
18620
|
}
|
|
18621
|
-
formatToParts(
|
|
18621
|
+
formatToParts(count2, unit) {
|
|
18622
18622
|
if (this.rtf) {
|
|
18623
|
-
return this.rtf.formatToParts(
|
|
18623
|
+
return this.rtf.formatToParts(count2, unit);
|
|
18624
18624
|
} else {
|
|
18625
18625
|
return [];
|
|
18626
18626
|
}
|
|
@@ -19040,14 +19040,14 @@ var require_luxon = __commonJS({
|
|
|
19040
19040
|
tibt: [3872, 3881]
|
|
19041
19041
|
};
|
|
19042
19042
|
var hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split("");
|
|
19043
|
-
function parseDigits(
|
|
19044
|
-
let value = parseInt(
|
|
19043
|
+
function parseDigits(str2) {
|
|
19044
|
+
let value = parseInt(str2, 10);
|
|
19045
19045
|
if (isNaN(value)) {
|
|
19046
19046
|
value = "";
|
|
19047
|
-
for (let i = 0; i <
|
|
19048
|
-
const code =
|
|
19049
|
-
if (
|
|
19050
|
-
value += hanidecChars.indexOf(
|
|
19047
|
+
for (let i = 0; i < str2.length; i++) {
|
|
19048
|
+
const code = str2.charCodeAt(i);
|
|
19049
|
+
if (str2[i].search(numberingSystems.hanidec) !== -1) {
|
|
19050
|
+
value += hanidecChars.indexOf(str2[i]);
|
|
19051
19051
|
} else {
|
|
19052
19052
|
for (const key in numberingSystemsUTF16) {
|
|
19053
19053
|
const [min, max] = numberingSystemsUTF16[key];
|
|
@@ -19350,19 +19350,19 @@ var require_luxon = __commonJS({
|
|
|
19350
19350
|
...timeObject(ordinalData)
|
|
19351
19351
|
};
|
|
19352
19352
|
}
|
|
19353
|
-
function usesLocalWeekValues(
|
|
19354
|
-
const hasLocaleWeekData = !isUndefined(
|
|
19353
|
+
function usesLocalWeekValues(obj2, loc) {
|
|
19354
|
+
const hasLocaleWeekData = !isUndefined(obj2.localWeekday) || !isUndefined(obj2.localWeekNumber) || !isUndefined(obj2.localWeekYear);
|
|
19355
19355
|
if (hasLocaleWeekData) {
|
|
19356
|
-
const hasIsoWeekData = !isUndefined(
|
|
19356
|
+
const hasIsoWeekData = !isUndefined(obj2.weekday) || !isUndefined(obj2.weekNumber) || !isUndefined(obj2.weekYear);
|
|
19357
19357
|
if (hasIsoWeekData) {
|
|
19358
19358
|
throw new ConflictingSpecificationError("Cannot mix locale-based week fields with ISO-based week fields");
|
|
19359
19359
|
}
|
|
19360
|
-
if (!isUndefined(
|
|
19361
|
-
if (!isUndefined(
|
|
19362
|
-
if (!isUndefined(
|
|
19363
|
-
delete
|
|
19364
|
-
delete
|
|
19365
|
-
delete
|
|
19360
|
+
if (!isUndefined(obj2.localWeekday)) obj2.weekday = obj2.localWeekday;
|
|
19361
|
+
if (!isUndefined(obj2.localWeekNumber)) obj2.weekNumber = obj2.localWeekNumber;
|
|
19362
|
+
if (!isUndefined(obj2.localWeekYear)) obj2.weekYear = obj2.localWeekYear;
|
|
19363
|
+
delete obj2.localWeekday;
|
|
19364
|
+
delete obj2.localWeekNumber;
|
|
19365
|
+
delete obj2.localWeekYear;
|
|
19366
19366
|
return {
|
|
19367
19367
|
minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
|
|
19368
19368
|
startOfWeek: loc.getStartOfWeek()
|
|
@@ -19374,41 +19374,41 @@ var require_luxon = __commonJS({
|
|
|
19374
19374
|
};
|
|
19375
19375
|
}
|
|
19376
19376
|
}
|
|
19377
|
-
function hasInvalidWeekData(
|
|
19378
|
-
const validYear = isInteger(
|
|
19377
|
+
function hasInvalidWeekData(obj2, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
19378
|
+
const validYear = isInteger(obj2.weekYear), validWeek = integerBetween(obj2.weekNumber, 1, weeksInWeekYear(obj2.weekYear, minDaysInFirstWeek, startOfWeek)), validWeekday = integerBetween(obj2.weekday, 1, 7);
|
|
19379
19379
|
if (!validYear) {
|
|
19380
|
-
return unitOutOfRange("weekYear",
|
|
19380
|
+
return unitOutOfRange("weekYear", obj2.weekYear);
|
|
19381
19381
|
} else if (!validWeek) {
|
|
19382
|
-
return unitOutOfRange("week",
|
|
19382
|
+
return unitOutOfRange("week", obj2.weekNumber);
|
|
19383
19383
|
} else if (!validWeekday) {
|
|
19384
|
-
return unitOutOfRange("weekday",
|
|
19384
|
+
return unitOutOfRange("weekday", obj2.weekday);
|
|
19385
19385
|
} else return false;
|
|
19386
19386
|
}
|
|
19387
|
-
function hasInvalidOrdinalData(
|
|
19388
|
-
const validYear = isInteger(
|
|
19387
|
+
function hasInvalidOrdinalData(obj2) {
|
|
19388
|
+
const validYear = isInteger(obj2.year), validOrdinal = integerBetween(obj2.ordinal, 1, daysInYear(obj2.year));
|
|
19389
19389
|
if (!validYear) {
|
|
19390
|
-
return unitOutOfRange("year",
|
|
19390
|
+
return unitOutOfRange("year", obj2.year);
|
|
19391
19391
|
} else if (!validOrdinal) {
|
|
19392
|
-
return unitOutOfRange("ordinal",
|
|
19392
|
+
return unitOutOfRange("ordinal", obj2.ordinal);
|
|
19393
19393
|
} else return false;
|
|
19394
19394
|
}
|
|
19395
|
-
function hasInvalidGregorianData(
|
|
19396
|
-
const validYear = isInteger(
|
|
19395
|
+
function hasInvalidGregorianData(obj2) {
|
|
19396
|
+
const validYear = isInteger(obj2.year), validMonth = integerBetween(obj2.month, 1, 12), validDay = integerBetween(obj2.day, 1, daysInMonth(obj2.year, obj2.month));
|
|
19397
19397
|
if (!validYear) {
|
|
19398
|
-
return unitOutOfRange("year",
|
|
19398
|
+
return unitOutOfRange("year", obj2.year);
|
|
19399
19399
|
} else if (!validMonth) {
|
|
19400
|
-
return unitOutOfRange("month",
|
|
19400
|
+
return unitOutOfRange("month", obj2.month);
|
|
19401
19401
|
} else if (!validDay) {
|
|
19402
|
-
return unitOutOfRange("day",
|
|
19402
|
+
return unitOutOfRange("day", obj2.day);
|
|
19403
19403
|
} else return false;
|
|
19404
19404
|
}
|
|
19405
|
-
function hasInvalidTimeData(
|
|
19405
|
+
function hasInvalidTimeData(obj2) {
|
|
19406
19406
|
const {
|
|
19407
19407
|
hour,
|
|
19408
19408
|
minute,
|
|
19409
19409
|
second,
|
|
19410
19410
|
millisecond
|
|
19411
|
-
} =
|
|
19411
|
+
} = obj2;
|
|
19412
19412
|
const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0, validMinute = integerBetween(minute, 0, 59), validSecond = integerBetween(second, 0, 59), validMillisecond = integerBetween(millisecond, 0, 999);
|
|
19413
19413
|
if (!validHour) {
|
|
19414
19414
|
return unitOutOfRange("hour", hour);
|
|
@@ -19452,11 +19452,11 @@ var require_luxon = __commonJS({
|
|
|
19452
19452
|
function maybeArray(thing) {
|
|
19453
19453
|
return Array.isArray(thing) ? thing : [thing];
|
|
19454
19454
|
}
|
|
19455
|
-
function bestBy(
|
|
19456
|
-
if (
|
|
19455
|
+
function bestBy(arr2, by, compare) {
|
|
19456
|
+
if (arr2.length === 0) {
|
|
19457
19457
|
return void 0;
|
|
19458
19458
|
}
|
|
19459
|
-
return
|
|
19459
|
+
return arr2.reduce((best, next) => {
|
|
19460
19460
|
const pair = [by(next), next];
|
|
19461
19461
|
if (!best) {
|
|
19462
19462
|
return pair;
|
|
@@ -19467,14 +19467,14 @@ var require_luxon = __commonJS({
|
|
|
19467
19467
|
}
|
|
19468
19468
|
}, null)[1];
|
|
19469
19469
|
}
|
|
19470
|
-
function pick(
|
|
19470
|
+
function pick(obj2, keys) {
|
|
19471
19471
|
return keys.reduce((a, k) => {
|
|
19472
|
-
a[k] =
|
|
19472
|
+
a[k] = obj2[k];
|
|
19473
19473
|
return a;
|
|
19474
19474
|
}, {});
|
|
19475
19475
|
}
|
|
19476
|
-
function hasOwnProperty(
|
|
19477
|
-
return Object.prototype.hasOwnProperty.call(
|
|
19476
|
+
function hasOwnProperty(obj2, prop) {
|
|
19477
|
+
return Object.prototype.hasOwnProperty.call(obj2, prop);
|
|
19478
19478
|
}
|
|
19479
19479
|
function validateWeekSettings(settings) {
|
|
19480
19480
|
if (settings == null) {
|
|
@@ -19561,11 +19561,11 @@ var require_luxon = __commonJS({
|
|
|
19561
19561
|
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
|
|
19562
19562
|
}
|
|
19563
19563
|
}
|
|
19564
|
-
function objToLocalTS(
|
|
19565
|
-
let d = Date.UTC(
|
|
19566
|
-
if (
|
|
19564
|
+
function objToLocalTS(obj2) {
|
|
19565
|
+
let d = Date.UTC(obj2.year, obj2.month - 1, obj2.day, obj2.hour, obj2.minute, obj2.second, obj2.millisecond);
|
|
19566
|
+
if (obj2.year < 100 && obj2.year >= 0) {
|
|
19567
19567
|
d = new Date(d);
|
|
19568
|
-
d.setUTCFullYear(
|
|
19568
|
+
d.setUTCFullYear(obj2.year, obj2.month - 1, obj2.day);
|
|
19569
19569
|
}
|
|
19570
19570
|
return +d;
|
|
19571
19571
|
}
|
|
@@ -19615,11 +19615,11 @@ var require_luxon = __commonJS({
|
|
|
19615
19615
|
if (typeof value === "boolean" || value === "" || !Number.isFinite(numericValue)) throw new InvalidArgumentError(`Invalid unit value ${value}`);
|
|
19616
19616
|
return numericValue;
|
|
19617
19617
|
}
|
|
19618
|
-
function normalizeObject(
|
|
19618
|
+
function normalizeObject(obj2, normalizer) {
|
|
19619
19619
|
const normalized = {};
|
|
19620
|
-
for (const u in
|
|
19621
|
-
if (hasOwnProperty(
|
|
19622
|
-
const v =
|
|
19620
|
+
for (const u in obj2) {
|
|
19621
|
+
if (hasOwnProperty(obj2, u)) {
|
|
19622
|
+
const v = obj2[u];
|
|
19623
19623
|
if (v === void 0 || v === null) continue;
|
|
19624
19624
|
normalized[normalizer(u)] = asNumber(v);
|
|
19625
19625
|
}
|
|
@@ -19639,8 +19639,8 @@ var require_luxon = __commonJS({
|
|
|
19639
19639
|
throw new RangeError(`Value format ${format} is out of range for property format`);
|
|
19640
19640
|
}
|
|
19641
19641
|
}
|
|
19642
|
-
function timeObject(
|
|
19643
|
-
return pick(
|
|
19642
|
+
function timeObject(obj2) {
|
|
19643
|
+
return pick(obj2, ["hour", "minute", "second", "millisecond"]);
|
|
19644
19644
|
}
|
|
19645
19645
|
var monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
19646
19646
|
var monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
@@ -19706,7 +19706,7 @@ var require_luxon = __commonJS({
|
|
|
19706
19706
|
function eraForDateTime(dt, length) {
|
|
19707
19707
|
return eras(length)[dt.year < 0 ? 0 : 1];
|
|
19708
19708
|
}
|
|
19709
|
-
function formatRelativeTime(unit,
|
|
19709
|
+
function formatRelativeTime(unit, count2, numeric = "always", narrow = false) {
|
|
19710
19710
|
const units = {
|
|
19711
19711
|
years: ["year", "yr."],
|
|
19712
19712
|
quarters: ["quarter", "qtr."],
|
|
@@ -19720,7 +19720,7 @@ var require_luxon = __commonJS({
|
|
|
19720
19720
|
const lastable = ["hours", "minutes", "seconds"].indexOf(unit) === -1;
|
|
19721
19721
|
if (numeric === "auto" && lastable) {
|
|
19722
19722
|
const isDay = unit === "days";
|
|
19723
|
-
switch (
|
|
19723
|
+
switch (count2) {
|
|
19724
19724
|
case 1:
|
|
19725
19725
|
return isDay ? "tomorrow" : `next ${units[unit][0]}`;
|
|
19726
19726
|
case -1:
|
|
@@ -19729,7 +19729,7 @@ var require_luxon = __commonJS({
|
|
|
19729
19729
|
return isDay ? "today" : `this ${units[unit][0]}`;
|
|
19730
19730
|
}
|
|
19731
19731
|
}
|
|
19732
|
-
const isInPast = Object.is(
|
|
19732
|
+
const isInPast = Object.is(count2, -0) || count2 < 0, fmtValue = Math.abs(count2), singular = fmtValue === 1, lilUnits = units[unit], fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit;
|
|
19733
19733
|
return isInPast ? `${fmtValue} ${fmtUnit} ago` : `in ${fmtValue} ${fmtUnit}`;
|
|
19734
19734
|
}
|
|
19735
19735
|
function stringifyTokens(splits, tokenToString) {
|
|
@@ -20205,7 +20205,7 @@ var require_luxon = __commonJS({
|
|
|
20205
20205
|
const [s2, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match2;
|
|
20206
20206
|
const hasNegativePrefix = s2[0] === "-";
|
|
20207
20207
|
const negativeSeconds = secondStr && secondStr[0] === "-";
|
|
20208
|
-
const maybeNegate = (
|
|
20208
|
+
const maybeNegate = (num2, force = false) => num2 !== void 0 && (force || num2 && hasNegativePrefix) ? -num2 : num2;
|
|
20209
20209
|
return [{
|
|
20210
20210
|
years: maybeNegate(parseFloating(yearStr)),
|
|
20211
20211
|
months: maybeNegate(parseFloating(monthStr)),
|
|
@@ -20477,9 +20477,9 @@ var require_luxon = __commonJS({
|
|
|
20477
20477
|
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
|
|
20478
20478
|
* @return {Duration}
|
|
20479
20479
|
*/
|
|
20480
|
-
static fromMillis(
|
|
20480
|
+
static fromMillis(count2, opts) {
|
|
20481
20481
|
return _Duration.fromObject({
|
|
20482
|
-
milliseconds:
|
|
20482
|
+
milliseconds: count2
|
|
20483
20483
|
}, opts);
|
|
20484
20484
|
}
|
|
20485
20485
|
/**
|
|
@@ -20502,12 +20502,12 @@ var require_luxon = __commonJS({
|
|
|
20502
20502
|
* @param {string} [opts.matrix=Object] - the custom conversion system to use
|
|
20503
20503
|
* @return {Duration}
|
|
20504
20504
|
*/
|
|
20505
|
-
static fromObject(
|
|
20506
|
-
if (
|
|
20507
|
-
throw new InvalidArgumentError(`Duration.fromObject: argument expected to be an object, got ${
|
|
20505
|
+
static fromObject(obj2, opts = {}) {
|
|
20506
|
+
if (obj2 == null || typeof obj2 !== "object") {
|
|
20507
|
+
throw new InvalidArgumentError(`Duration.fromObject: argument expected to be an object, got ${obj2 === null ? "null" : typeof obj2}`);
|
|
20508
20508
|
}
|
|
20509
20509
|
return new _Duration({
|
|
20510
|
-
values: normalizeObject(
|
|
20510
|
+
values: normalizeObject(obj2, _Duration.normalizeUnit),
|
|
20511
20511
|
loc: Locale.fromObject(opts),
|
|
20512
20512
|
conversionAccuracy: opts.conversionAccuracy,
|
|
20513
20513
|
matrix: opts.matrix
|
|
@@ -21576,8 +21576,8 @@ var require_luxon = __commonJS({
|
|
|
21576
21576
|
}, {
|
|
21577
21577
|
time: i.e,
|
|
21578
21578
|
type: "e"
|
|
21579
|
-
}]), flattened = Array.prototype.concat(...ends),
|
|
21580
|
-
for (const i of
|
|
21579
|
+
}]), flattened = Array.prototype.concat(...ends), arr2 = flattened.sort((a, b) => a.time - b.time);
|
|
21580
|
+
for (const i of arr2) {
|
|
21581
21581
|
currentCount += i.type === "s" ? 1 : -1;
|
|
21582
21582
|
if (currentCount === 1) {
|
|
21583
21583
|
start = i.time;
|
|
@@ -22474,8 +22474,8 @@ var require_luxon = __commonJS({
|
|
|
22474
22474
|
millisecond: d.getUTCMilliseconds()
|
|
22475
22475
|
};
|
|
22476
22476
|
}
|
|
22477
|
-
function objToTS(
|
|
22478
|
-
return fixOffset(objToLocalTS(
|
|
22477
|
+
function objToTS(obj2, offset2, zone) {
|
|
22478
|
+
return fixOffset(objToLocalTS(obj2), offset2, zone);
|
|
22479
22479
|
}
|
|
22480
22480
|
function adjustTime(inst, dur) {
|
|
22481
22481
|
const oPre = inst.o, year = inst.c.year + Math.trunc(dur.years), month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3, c = {
|
|
@@ -22681,25 +22681,25 @@ var require_luxon = __commonJS({
|
|
|
22681
22681
|
}
|
|
22682
22682
|
return offsetGuess;
|
|
22683
22683
|
}
|
|
22684
|
-
function quickDT(
|
|
22684
|
+
function quickDT(obj2, opts) {
|
|
22685
22685
|
const zone = normalizeZone(opts.zone, Settings.defaultZone);
|
|
22686
22686
|
if (!zone.isValid) {
|
|
22687
22687
|
return DateTime.invalid(unsupportedZone(zone));
|
|
22688
22688
|
}
|
|
22689
22689
|
const loc = Locale.fromObject(opts);
|
|
22690
22690
|
let ts, o;
|
|
22691
|
-
if (!isUndefined(
|
|
22691
|
+
if (!isUndefined(obj2.year)) {
|
|
22692
22692
|
for (const u of orderedUnits) {
|
|
22693
|
-
if (isUndefined(
|
|
22694
|
-
|
|
22693
|
+
if (isUndefined(obj2[u])) {
|
|
22694
|
+
obj2[u] = defaultUnitValues[u];
|
|
22695
22695
|
}
|
|
22696
22696
|
}
|
|
22697
|
-
const invalid = hasInvalidGregorianData(
|
|
22697
|
+
const invalid = hasInvalidGregorianData(obj2) || hasInvalidTimeData(obj2);
|
|
22698
22698
|
if (invalid) {
|
|
22699
22699
|
return DateTime.invalid(invalid);
|
|
22700
22700
|
}
|
|
22701
22701
|
const offsetProvis = guessOffsetForZone(zone);
|
|
22702
|
-
[ts, o] = objToTS(
|
|
22702
|
+
[ts, o] = objToTS(obj2, offsetProvis, zone);
|
|
22703
22703
|
} else {
|
|
22704
22704
|
ts = Settings.now();
|
|
22705
22705
|
}
|
|
@@ -22728,9 +22728,9 @@ var require_luxon = __commonJS({
|
|
|
22728
22728
|
return format(differ(opts.unit), opts.unit);
|
|
22729
22729
|
}
|
|
22730
22730
|
for (const unit of opts.units) {
|
|
22731
|
-
const
|
|
22732
|
-
if (Math.abs(
|
|
22733
|
-
return format(
|
|
22731
|
+
const count2 = differ(unit);
|
|
22732
|
+
if (Math.abs(count2) >= 1) {
|
|
22733
|
+
return format(count2, unit);
|
|
22734
22734
|
}
|
|
22735
22735
|
}
|
|
22736
22736
|
return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
|
|
@@ -22960,14 +22960,14 @@ var require_luxon = __commonJS({
|
|
|
22960
22960
|
* @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
|
|
22961
22961
|
* @return {DateTime}
|
|
22962
22962
|
*/
|
|
22963
|
-
static fromObject(
|
|
22964
|
-
|
|
22963
|
+
static fromObject(obj2, opts = {}) {
|
|
22964
|
+
obj2 = obj2 || {};
|
|
22965
22965
|
const zoneToUse = normalizeZone(opts.zone, Settings.defaultZone);
|
|
22966
22966
|
if (!zoneToUse.isValid) {
|
|
22967
22967
|
return _DateTime.invalid(unsupportedZone(zoneToUse));
|
|
22968
22968
|
}
|
|
22969
22969
|
const loc = Locale.fromObject(opts);
|
|
22970
|
-
const normalized = normalizeObject(
|
|
22970
|
+
const normalized = normalizeObject(obj2, normalizeUnitWithLocalWeeks);
|
|
22971
22971
|
const {
|
|
22972
22972
|
minDaysInFirstWeek,
|
|
22973
22973
|
startOfWeek
|
|
@@ -23014,7 +23014,7 @@ var require_luxon = __commonJS({
|
|
|
23014
23014
|
o: offsetFinal,
|
|
23015
23015
|
loc
|
|
23016
23016
|
});
|
|
23017
|
-
if (normalized.weekday && containsGregor &&
|
|
23017
|
+
if (normalized.weekday && containsGregor && obj2.weekday !== inst.weekday) {
|
|
23018
23018
|
return _DateTime.invalid("mismatched weekday", `you can't specify both a weekday of ${normalized.weekday} and a date of ${inst.toISO()}`);
|
|
23019
23019
|
}
|
|
23020
23020
|
if (!inst.isValid) {
|
|
@@ -24804,11 +24804,11 @@ var require_field_compactor = __commonJS({
|
|
|
24804
24804
|
results.push(currentItemRange);
|
|
24805
24805
|
}
|
|
24806
24806
|
}
|
|
24807
|
-
function compactField(
|
|
24807
|
+
function compactField(arr2) {
|
|
24808
24808
|
var results = [];
|
|
24809
24809
|
var currentRange = void 0;
|
|
24810
|
-
for (var i = 0; i <
|
|
24811
|
-
var currentItem =
|
|
24810
|
+
for (var i = 0; i < arr2.length; i++) {
|
|
24811
|
+
var currentItem = arr2[i];
|
|
24812
24812
|
if (typeof currentItem !== "number") {
|
|
24813
24813
|
finalizeCurrentRange(results, currentRange, buildRange(currentItem));
|
|
24814
24814
|
currentRange = void 0;
|
|
@@ -24842,8 +24842,8 @@ var require_field_stringify = __commonJS({
|
|
|
24842
24842
|
"../../node_modules/.pnpm/cron-parser@4.9.0/node_modules/cron-parser/lib/field_stringify.js"(exports2, module2) {
|
|
24843
24843
|
"use strict";
|
|
24844
24844
|
var compactField = require_field_compactor();
|
|
24845
|
-
function stringifyField(
|
|
24846
|
-
var ranges = compactField(
|
|
24845
|
+
function stringifyField(arr2, min, max) {
|
|
24846
|
+
var ranges = compactField(arr2);
|
|
24847
24847
|
if (ranges.length === 1) {
|
|
24848
24848
|
var singleRange = ranges[0];
|
|
24849
24849
|
var step = singleRange.step;
|
|
@@ -25107,7 +25107,7 @@ var require_expression = __commonJS({
|
|
|
25107
25107
|
if (field === "dayOfWeek" && max % 7 === 0) {
|
|
25108
25108
|
stack.push(0);
|
|
25109
25109
|
}
|
|
25110
|
-
for (var index = min,
|
|
25110
|
+
for (var index = min, count2 = max; index <= count2; index++) {
|
|
25111
25111
|
var exists = stack.indexOf(index) !== -1;
|
|
25112
25112
|
if (!exists && repeatIndex > 0 && repeatIndex % repeatInterval === 0) {
|
|
25113
25113
|
repeatIndex = 1;
|
|
@@ -25554,7 +25554,7 @@ var require_parser2 = __commonJS({
|
|
|
25554
25554
|
throw new Error("Invalid entry: " + entry);
|
|
25555
25555
|
}
|
|
25556
25556
|
};
|
|
25557
|
-
CronParser.parseExpression = function
|
|
25557
|
+
CronParser.parseExpression = function parseExpression(expression, options) {
|
|
25558
25558
|
return CronExpression.parse(expression, options);
|
|
25559
25559
|
};
|
|
25560
25560
|
CronParser.fieldsToExpression = function fieldsToExpression(fields, options) {
|
|
@@ -26062,7 +26062,7 @@ var require_anchors = __commonJS({
|
|
|
26062
26062
|
var require_applyReviver = __commonJS({
|
|
26063
26063
|
"../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/doc/applyReviver.js"(exports2) {
|
|
26064
26064
|
"use strict";
|
|
26065
|
-
function applyReviver(reviver,
|
|
26065
|
+
function applyReviver(reviver, obj2, key, val) {
|
|
26066
26066
|
if (val && typeof val === "object") {
|
|
26067
26067
|
if (Array.isArray(val)) {
|
|
26068
26068
|
for (let i = 0, len = val.length; i < len; ++i) {
|
|
@@ -26102,7 +26102,7 @@ var require_applyReviver = __commonJS({
|
|
|
26102
26102
|
}
|
|
26103
26103
|
}
|
|
26104
26104
|
}
|
|
26105
|
-
return reviver.call(
|
|
26105
|
+
return reviver.call(obj2, key, val);
|
|
26106
26106
|
}
|
|
26107
26107
|
exports2.applyReviver = applyReviver;
|
|
26108
26108
|
}
|
|
@@ -26170,8 +26170,8 @@ var require_Node = __commonJS({
|
|
|
26170
26170
|
};
|
|
26171
26171
|
const res = toJS.toJS(this, "", ctx);
|
|
26172
26172
|
if (typeof onAnchor === "function")
|
|
26173
|
-
for (const { count, res: res2 } of ctx.anchors.values())
|
|
26174
|
-
onAnchor(res2,
|
|
26173
|
+
for (const { count: count2, res: res2 } of ctx.anchors.values())
|
|
26174
|
+
onAnchor(res2, count2);
|
|
26175
26175
|
return typeof reviver === "function" ? applyReviver.applyReviver(reviver, { "": res }, "", res) : res;
|
|
26176
26176
|
}
|
|
26177
26177
|
};
|
|
@@ -26279,13 +26279,13 @@ var require_Alias = __commonJS({
|
|
|
26279
26279
|
const anchor = anchors2 && source && anchors2.get(source);
|
|
26280
26280
|
return anchor ? anchor.count * anchor.aliasCount : 0;
|
|
26281
26281
|
} else if (identity.isCollection(node)) {
|
|
26282
|
-
let
|
|
26282
|
+
let count2 = 0;
|
|
26283
26283
|
for (const item of node.items) {
|
|
26284
26284
|
const c = getAliasCount(doc, item, anchors2);
|
|
26285
|
-
if (c >
|
|
26286
|
-
|
|
26285
|
+
if (c > count2)
|
|
26286
|
+
count2 = c;
|
|
26287
26287
|
}
|
|
26288
|
-
return
|
|
26288
|
+
return count2;
|
|
26289
26289
|
} else if (identity.isPair(node)) {
|
|
26290
26290
|
const kc = getAliasCount(doc, node.key, anchors2);
|
|
26291
26291
|
const vc = getAliasCount(doc, node.value, anchors2);
|
|
@@ -26549,13 +26549,13 @@ var require_Collection = __commonJS({
|
|
|
26549
26549
|
var require_stringifyComment = __commonJS({
|
|
26550
26550
|
"../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/stringify/stringifyComment.js"(exports2) {
|
|
26551
26551
|
"use strict";
|
|
26552
|
-
var stringifyComment = (
|
|
26552
|
+
var stringifyComment = (str2) => str2.replace(/^(?!$)(?: $)?/gm, "#");
|
|
26553
26553
|
function indentComment(comment, indent) {
|
|
26554
26554
|
if (/^\n+$/.test(comment))
|
|
26555
26555
|
return comment.substring(1);
|
|
26556
26556
|
return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;
|
|
26557
26557
|
}
|
|
26558
|
-
var lineComment = (
|
|
26558
|
+
var lineComment = (str2, indent, comment) => str2.endsWith("\n") ? indentComment(comment, indent) : comment.includes("\n") ? "\n" + indentComment(comment, indent) : (str2.endsWith(" ") ? "" : " ") + comment;
|
|
26559
26559
|
exports2.indentComment = indentComment;
|
|
26560
26560
|
exports2.lineComment = lineComment;
|
|
26561
26561
|
exports2.stringifyComment = stringifyComment;
|
|
@@ -26709,16 +26709,16 @@ var require_stringifyString = __commonJS({
|
|
|
26709
26709
|
lineWidth: ctx.options.lineWidth,
|
|
26710
26710
|
minContentWidth: ctx.options.minContentWidth
|
|
26711
26711
|
});
|
|
26712
|
-
var containsDocumentMarker = (
|
|
26713
|
-
function lineLengthOverLimit(
|
|
26712
|
+
var containsDocumentMarker = (str2) => /^(%|---|\.\.\.)/m.test(str2);
|
|
26713
|
+
function lineLengthOverLimit(str2, lineWidth, indentLength) {
|
|
26714
26714
|
if (!lineWidth || lineWidth < 0)
|
|
26715
26715
|
return false;
|
|
26716
26716
|
const limit = lineWidth - indentLength;
|
|
26717
|
-
const strLen =
|
|
26717
|
+
const strLen = str2.length;
|
|
26718
26718
|
if (strLen <= limit)
|
|
26719
26719
|
return false;
|
|
26720
26720
|
for (let i = 0, start = 0; i < strLen; ++i) {
|
|
26721
|
-
if (
|
|
26721
|
+
if (str2[i] === "\n") {
|
|
26722
26722
|
if (i - start > limit)
|
|
26723
26723
|
return true;
|
|
26724
26724
|
start = i + 1;
|
|
@@ -26735,11 +26735,11 @@ var require_stringifyString = __commonJS({
|
|
|
26735
26735
|
const { implicitKey } = ctx;
|
|
26736
26736
|
const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
|
|
26737
26737
|
const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
|
|
26738
|
-
let
|
|
26738
|
+
let str2 = "";
|
|
26739
26739
|
let start = 0;
|
|
26740
26740
|
for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
|
|
26741
26741
|
if (ch === " " && json[i + 1] === "\\" && json[i + 2] === "n") {
|
|
26742
|
-
|
|
26742
|
+
str2 += json.slice(start, i) + "\\ ";
|
|
26743
26743
|
i += 1;
|
|
26744
26744
|
start = i;
|
|
26745
26745
|
ch = "\\";
|
|
@@ -26748,38 +26748,38 @@ var require_stringifyString = __commonJS({
|
|
|
26748
26748
|
switch (json[i + 1]) {
|
|
26749
26749
|
case "u":
|
|
26750
26750
|
{
|
|
26751
|
-
|
|
26751
|
+
str2 += json.slice(start, i);
|
|
26752
26752
|
const code = json.substr(i + 2, 4);
|
|
26753
26753
|
switch (code) {
|
|
26754
26754
|
case "0000":
|
|
26755
|
-
|
|
26755
|
+
str2 += "\\0";
|
|
26756
26756
|
break;
|
|
26757
26757
|
case "0007":
|
|
26758
|
-
|
|
26758
|
+
str2 += "\\a";
|
|
26759
26759
|
break;
|
|
26760
26760
|
case "000b":
|
|
26761
|
-
|
|
26761
|
+
str2 += "\\v";
|
|
26762
26762
|
break;
|
|
26763
26763
|
case "001b":
|
|
26764
|
-
|
|
26764
|
+
str2 += "\\e";
|
|
26765
26765
|
break;
|
|
26766
26766
|
case "0085":
|
|
26767
|
-
|
|
26767
|
+
str2 += "\\N";
|
|
26768
26768
|
break;
|
|
26769
26769
|
case "00a0":
|
|
26770
|
-
|
|
26770
|
+
str2 += "\\_";
|
|
26771
26771
|
break;
|
|
26772
26772
|
case "2028":
|
|
26773
|
-
|
|
26773
|
+
str2 += "\\L";
|
|
26774
26774
|
break;
|
|
26775
26775
|
case "2029":
|
|
26776
|
-
|
|
26776
|
+
str2 += "\\P";
|
|
26777
26777
|
break;
|
|
26778
26778
|
default:
|
|
26779
26779
|
if (code.substr(0, 2) === "00")
|
|
26780
|
-
|
|
26780
|
+
str2 += "\\x" + code.substr(2);
|
|
26781
26781
|
else
|
|
26782
|
-
|
|
26782
|
+
str2 += json.substr(i, 6);
|
|
26783
26783
|
}
|
|
26784
26784
|
i += 5;
|
|
26785
26785
|
start = i + 1;
|
|
@@ -26789,14 +26789,14 @@ var require_stringifyString = __commonJS({
|
|
|
26789
26789
|
if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
|
|
26790
26790
|
i += 1;
|
|
26791
26791
|
} else {
|
|
26792
|
-
|
|
26792
|
+
str2 += json.slice(start, i) + "\n\n";
|
|
26793
26793
|
while (json[i + 2] === "\\" && json[i + 3] === "n" && json[i + 4] !== '"') {
|
|
26794
|
-
|
|
26794
|
+
str2 += "\n";
|
|
26795
26795
|
i += 2;
|
|
26796
26796
|
}
|
|
26797
|
-
|
|
26797
|
+
str2 += indent;
|
|
26798
26798
|
if (json[i + 2] === " ")
|
|
26799
|
-
|
|
26799
|
+
str2 += "\\";
|
|
26800
26800
|
i += 1;
|
|
26801
26801
|
start = i + 1;
|
|
26802
26802
|
}
|
|
@@ -26805,8 +26805,8 @@ var require_stringifyString = __commonJS({
|
|
|
26805
26805
|
i += 1;
|
|
26806
26806
|
}
|
|
26807
26807
|
}
|
|
26808
|
-
|
|
26809
|
-
return implicitKey ?
|
|
26808
|
+
str2 = start ? str2 + json.slice(start) : json;
|
|
26809
|
+
return implicitKey ? str2 : foldFlowLines.foldFlowLines(str2, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
26810
26810
|
}
|
|
26811
26811
|
function singleQuotedString(value, ctx) {
|
|
26812
26812
|
if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value))
|
|
@@ -26934,15 +26934,15 @@ ${indent}${start}${value}${end}`;
|
|
|
26934
26934
|
return quotedString(value, ctx);
|
|
26935
26935
|
}
|
|
26936
26936
|
}
|
|
26937
|
-
const
|
|
26937
|
+
const str2 = value.replace(/\n+/g, `$&
|
|
26938
26938
|
${indent}`);
|
|
26939
26939
|
if (actualString) {
|
|
26940
|
-
const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(
|
|
26940
|
+
const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str2);
|
|
26941
26941
|
const { compat, tags } = ctx.doc.schema;
|
|
26942
26942
|
if (tags.some(test) || compat?.some(test))
|
|
26943
26943
|
return quotedString(value, ctx);
|
|
26944
26944
|
}
|
|
26945
|
-
return implicitKey ?
|
|
26945
|
+
return implicitKey ? str2 : foldFlowLines.foldFlowLines(str2, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
|
|
26946
26946
|
}
|
|
26947
26947
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
26948
26948
|
const { implicitKey, inFlow } = ctx;
|
|
@@ -27038,10 +27038,10 @@ var require_stringify = __commonJS({
|
|
|
27038
27038
|
return match.find((t) => t.format === item.format) ?? match[0];
|
|
27039
27039
|
}
|
|
27040
27040
|
let tagObj = void 0;
|
|
27041
|
-
let
|
|
27041
|
+
let obj2;
|
|
27042
27042
|
if (identity.isScalar(item)) {
|
|
27043
|
-
|
|
27044
|
-
let match = tags.filter((t) => t.identify?.(
|
|
27043
|
+
obj2 = item.value;
|
|
27044
|
+
let match = tags.filter((t) => t.identify?.(obj2));
|
|
27045
27045
|
if (match.length > 1) {
|
|
27046
27046
|
const testMatch = match.filter((t) => t.test);
|
|
27047
27047
|
if (testMatch.length > 0)
|
|
@@ -27049,11 +27049,11 @@ var require_stringify = __commonJS({
|
|
|
27049
27049
|
}
|
|
27050
27050
|
tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
|
|
27051
27051
|
} else {
|
|
27052
|
-
|
|
27053
|
-
tagObj = tags.find((t) => t.nodeClass &&
|
|
27052
|
+
obj2 = item;
|
|
27053
|
+
tagObj = tags.find((t) => t.nodeClass && obj2 instanceof t.nodeClass);
|
|
27054
27054
|
}
|
|
27055
27055
|
if (!tagObj) {
|
|
27056
|
-
const name =
|
|
27056
|
+
const name = obj2?.constructor?.name ?? (obj2 === null ? "null" : typeof obj2);
|
|
27057
27057
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
27058
27058
|
}
|
|
27059
27059
|
return tagObj;
|
|
@@ -27094,11 +27094,11 @@ var require_stringify = __commonJS({
|
|
|
27094
27094
|
const props = stringifyProps(node, tagObj, ctx);
|
|
27095
27095
|
if (props.length > 0)
|
|
27096
27096
|
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
27097
|
-
const
|
|
27097
|
+
const str2 = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
|
|
27098
27098
|
if (!props)
|
|
27099
|
-
return
|
|
27100
|
-
return identity.isScalar(node) ||
|
|
27101
|
-
${ctx.indent}${
|
|
27099
|
+
return str2;
|
|
27100
|
+
return identity.isScalar(node) || str2[0] === "{" || str2[0] === "[" ? `${props} ${str2}` : `${props}
|
|
27101
|
+
${ctx.indent}${str2}`;
|
|
27102
27102
|
}
|
|
27103
27103
|
exports2.createStringifyContext = createStringifyContext;
|
|
27104
27104
|
exports2.stringify = stringify;
|
|
@@ -27133,8 +27133,8 @@ var require_stringifyPair = __commonJS({
|
|
|
27133
27133
|
});
|
|
27134
27134
|
let keyCommentDone = false;
|
|
27135
27135
|
let chompKeep = false;
|
|
27136
|
-
let
|
|
27137
|
-
if (!explicitKey && !ctx.inFlow &&
|
|
27136
|
+
let str2 = stringify.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
|
|
27137
|
+
if (!explicitKey && !ctx.inFlow && str2.length > 1024) {
|
|
27138
27138
|
if (simpleKeys)
|
|
27139
27139
|
throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
|
|
27140
27140
|
explicitKey = true;
|
|
@@ -27143,27 +27143,27 @@ var require_stringifyPair = __commonJS({
|
|
|
27143
27143
|
if (allNullValues || value == null) {
|
|
27144
27144
|
if (keyCommentDone && onComment)
|
|
27145
27145
|
onComment();
|
|
27146
|
-
return
|
|
27146
|
+
return str2 === "" ? "?" : explicitKey ? `? ${str2}` : str2;
|
|
27147
27147
|
}
|
|
27148
27148
|
} else if (allNullValues && !simpleKeys || value == null && explicitKey) {
|
|
27149
|
-
|
|
27149
|
+
str2 = `? ${str2}`;
|
|
27150
27150
|
if (keyComment && !keyCommentDone) {
|
|
27151
|
-
|
|
27151
|
+
str2 += stringifyComment.lineComment(str2, ctx.indent, commentString(keyComment));
|
|
27152
27152
|
} else if (chompKeep && onChompKeep)
|
|
27153
27153
|
onChompKeep();
|
|
27154
|
-
return
|
|
27154
|
+
return str2;
|
|
27155
27155
|
}
|
|
27156
27156
|
if (keyCommentDone)
|
|
27157
27157
|
keyComment = null;
|
|
27158
27158
|
if (explicitKey) {
|
|
27159
27159
|
if (keyComment)
|
|
27160
|
-
|
|
27161
|
-
|
|
27160
|
+
str2 += stringifyComment.lineComment(str2, ctx.indent, commentString(keyComment));
|
|
27161
|
+
str2 = `? ${str2}
|
|
27162
27162
|
${indent}:`;
|
|
27163
27163
|
} else {
|
|
27164
|
-
|
|
27164
|
+
str2 = `${str2}:`;
|
|
27165
27165
|
if (keyComment)
|
|
27166
|
-
|
|
27166
|
+
str2 += stringifyComment.lineComment(str2, ctx.indent, commentString(keyComment));
|
|
27167
27167
|
}
|
|
27168
27168
|
let vsb, vcb, valueComment;
|
|
27169
27169
|
if (identity.isNode(value)) {
|
|
@@ -27179,7 +27179,7 @@ ${indent}:`;
|
|
|
27179
27179
|
}
|
|
27180
27180
|
ctx.implicitKey = false;
|
|
27181
27181
|
if (!explicitKey && !keyComment && identity.isScalar(value))
|
|
27182
|
-
ctx.indentAtStart =
|
|
27182
|
+
ctx.indentAtStart = str2.length + 1;
|
|
27183
27183
|
chompKeep = false;
|
|
27184
27184
|
if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && identity.isSeq(value) && !value.flow && !value.tag && !value.anchor) {
|
|
27185
27185
|
ctx.indent = ctx.indent.substring(2);
|
|
@@ -27223,16 +27223,16 @@ ${ctx.indent}`;
|
|
|
27223
27223
|
} else if (valueStr === "" || valueStr[0] === "\n") {
|
|
27224
27224
|
ws = "";
|
|
27225
27225
|
}
|
|
27226
|
-
|
|
27226
|
+
str2 += ws + valueStr;
|
|
27227
27227
|
if (ctx.inFlow) {
|
|
27228
27228
|
if (valueCommentDone && onComment)
|
|
27229
27229
|
onComment();
|
|
27230
27230
|
} else if (valueComment && !valueCommentDone) {
|
|
27231
|
-
|
|
27231
|
+
str2 += stringifyComment.lineComment(str2, ctx.indent, commentString(valueComment));
|
|
27232
27232
|
} else if (chompKeep && onChompKeep) {
|
|
27233
27233
|
onChompKeep();
|
|
27234
27234
|
}
|
|
27235
|
-
return
|
|
27235
|
+
return str2;
|
|
27236
27236
|
}
|
|
27237
27237
|
exports2.stringifyPair = stringifyPair;
|
|
27238
27238
|
}
|
|
@@ -27459,31 +27459,31 @@ var require_stringifyCollection = __commonJS({
|
|
|
27459
27459
|
}
|
|
27460
27460
|
}
|
|
27461
27461
|
chompKeep = false;
|
|
27462
|
-
let
|
|
27462
|
+
let str3 = stringify.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
|
|
27463
27463
|
if (comment2)
|
|
27464
|
-
|
|
27464
|
+
str3 += stringifyComment.lineComment(str3, itemIndent, commentString(comment2));
|
|
27465
27465
|
if (chompKeep && comment2)
|
|
27466
27466
|
chompKeep = false;
|
|
27467
|
-
lines.push(blockItemPrefix +
|
|
27467
|
+
lines.push(blockItemPrefix + str3);
|
|
27468
27468
|
}
|
|
27469
|
-
let
|
|
27469
|
+
let str2;
|
|
27470
27470
|
if (lines.length === 0) {
|
|
27471
|
-
|
|
27471
|
+
str2 = flowChars.start + flowChars.end;
|
|
27472
27472
|
} else {
|
|
27473
|
-
|
|
27473
|
+
str2 = lines[0];
|
|
27474
27474
|
for (let i = 1; i < lines.length; ++i) {
|
|
27475
27475
|
const line = lines[i];
|
|
27476
|
-
|
|
27476
|
+
str2 += line ? `
|
|
27477
27477
|
${indent}${line}` : "\n";
|
|
27478
27478
|
}
|
|
27479
27479
|
}
|
|
27480
27480
|
if (comment) {
|
|
27481
|
-
|
|
27481
|
+
str2 += "\n" + stringifyComment.indentComment(commentString(comment), indent);
|
|
27482
27482
|
if (onComment)
|
|
27483
27483
|
onComment();
|
|
27484
27484
|
} else if (chompKeep && onChompKeep)
|
|
27485
27485
|
onChompKeep();
|
|
27486
|
-
return
|
|
27486
|
+
return str2;
|
|
27487
27487
|
}
|
|
27488
27488
|
function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
27489
27489
|
const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
|
|
@@ -27526,21 +27526,21 @@ ${indent}${line}` : "\n";
|
|
|
27526
27526
|
}
|
|
27527
27527
|
if (comment)
|
|
27528
27528
|
reqNewline = true;
|
|
27529
|
-
let
|
|
27530
|
-
reqNewline || (reqNewline = lines.length > linesAtValue ||
|
|
27529
|
+
let str2 = stringify.stringify(item, itemCtx, () => comment = null);
|
|
27530
|
+
reqNewline || (reqNewline = lines.length > linesAtValue || str2.includes("\n"));
|
|
27531
27531
|
if (i < items.length - 1) {
|
|
27532
|
-
|
|
27532
|
+
str2 += ",";
|
|
27533
27533
|
} else if (ctx.options.trailingComma) {
|
|
27534
27534
|
if (ctx.options.lineWidth > 0) {
|
|
27535
|
-
reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (
|
|
27535
|
+
reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str2.length + 2) > ctx.options.lineWidth);
|
|
27536
27536
|
}
|
|
27537
27537
|
if (reqNewline) {
|
|
27538
|
-
|
|
27538
|
+
str2 += ",";
|
|
27539
27539
|
}
|
|
27540
27540
|
}
|
|
27541
27541
|
if (comment)
|
|
27542
|
-
|
|
27543
|
-
lines.push(
|
|
27542
|
+
str2 += stringifyComment.lineComment(str2, itemIndent, commentString(comment));
|
|
27543
|
+
lines.push(str2);
|
|
27544
27544
|
linesAtValue = lines.length;
|
|
27545
27545
|
}
|
|
27546
27546
|
const { start, end } = flowChars;
|
|
@@ -27552,11 +27552,11 @@ ${indent}${line}` : "\n";
|
|
|
27552
27552
|
reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
|
|
27553
27553
|
}
|
|
27554
27554
|
if (reqNewline) {
|
|
27555
|
-
let
|
|
27555
|
+
let str2 = start;
|
|
27556
27556
|
for (const line of lines)
|
|
27557
|
-
|
|
27557
|
+
str2 += line ? `
|
|
27558
27558
|
${indentStep}${indent}${line}` : "\n";
|
|
27559
|
-
return `${
|
|
27559
|
+
return `${str2}
|
|
27560
27560
|
${indent}${end}`;
|
|
27561
27561
|
} else {
|
|
27562
27562
|
return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
|
|
@@ -27609,23 +27609,23 @@ var require_YAMLMap = __commonJS({
|
|
|
27609
27609
|
* A generic collection parsing method that can be extended
|
|
27610
27610
|
* to other node classes that inherit from YAMLMap
|
|
27611
27611
|
*/
|
|
27612
|
-
static from(schema,
|
|
27612
|
+
static from(schema, obj2, ctx) {
|
|
27613
27613
|
const { keepUndefined, replacer } = ctx;
|
|
27614
27614
|
const map = new this(schema);
|
|
27615
27615
|
const add = (key, value) => {
|
|
27616
27616
|
if (typeof replacer === "function")
|
|
27617
|
-
value = replacer.call(
|
|
27617
|
+
value = replacer.call(obj2, key, value);
|
|
27618
27618
|
else if (Array.isArray(replacer) && !replacer.includes(key))
|
|
27619
27619
|
return;
|
|
27620
27620
|
if (value !== void 0 || keepUndefined)
|
|
27621
27621
|
map.items.push(Pair.createPair(key, value, ctx));
|
|
27622
27622
|
};
|
|
27623
|
-
if (
|
|
27624
|
-
for (const [key, value] of
|
|
27623
|
+
if (obj2 instanceof Map) {
|
|
27624
|
+
for (const [key, value] of obj2)
|
|
27625
27625
|
add(key, value);
|
|
27626
|
-
} else if (
|
|
27627
|
-
for (const key of Object.keys(
|
|
27628
|
-
add(key,
|
|
27626
|
+
} else if (obj2 && typeof obj2 === "object") {
|
|
27627
|
+
for (const key of Object.keys(obj2))
|
|
27628
|
+
add(key, obj2[key]);
|
|
27629
27629
|
}
|
|
27630
27630
|
if (typeof schema.sortMapEntries === "function") {
|
|
27631
27631
|
map.items.sort(schema.sortMapEntries);
|
|
@@ -27735,7 +27735,7 @@ var require_map = __commonJS({
|
|
|
27735
27735
|
onError("Expected a mapping for this tag");
|
|
27736
27736
|
return map2;
|
|
27737
27737
|
},
|
|
27738
|
-
createNode: (schema,
|
|
27738
|
+
createNode: (schema, obj2, ctx) => YAMLMap.YAMLMap.from(schema, obj2, ctx)
|
|
27739
27739
|
};
|
|
27740
27740
|
exports2.map = map;
|
|
27741
27741
|
}
|
|
@@ -27831,15 +27831,15 @@ var require_YAMLSeq = __commonJS({
|
|
|
27831
27831
|
onComment
|
|
27832
27832
|
});
|
|
27833
27833
|
}
|
|
27834
|
-
static from(schema,
|
|
27834
|
+
static from(schema, obj2, ctx) {
|
|
27835
27835
|
const { replacer } = ctx;
|
|
27836
27836
|
const seq = new this(schema);
|
|
27837
|
-
if (
|
|
27837
|
+
if (obj2 && Symbol.iterator in Object(obj2)) {
|
|
27838
27838
|
let i = 0;
|
|
27839
|
-
for (let it of
|
|
27839
|
+
for (let it of obj2) {
|
|
27840
27840
|
if (typeof replacer === "function") {
|
|
27841
|
-
const key =
|
|
27842
|
-
it = replacer.call(
|
|
27841
|
+
const key = obj2 instanceof Set ? it : String(i++);
|
|
27842
|
+
it = replacer.call(obj2, key, it);
|
|
27843
27843
|
}
|
|
27844
27844
|
seq.items.push(createNode.createNode(it, void 0, ctx));
|
|
27845
27845
|
}
|
|
@@ -27873,7 +27873,7 @@ var require_seq = __commonJS({
|
|
|
27873
27873
|
onError("Expected a sequence for this tag");
|
|
27874
27874
|
return seq2;
|
|
27875
27875
|
},
|
|
27876
|
-
createNode: (schema,
|
|
27876
|
+
createNode: (schema, obj2, ctx) => YAMLSeq.YAMLSeq.from(schema, obj2, ctx)
|
|
27877
27877
|
};
|
|
27878
27878
|
exports2.seq = seq;
|
|
27879
27879
|
}
|
|
@@ -27888,7 +27888,7 @@ var require_string = __commonJS({
|
|
|
27888
27888
|
identify: (value) => typeof value === "string",
|
|
27889
27889
|
default: true,
|
|
27890
27890
|
tag: "tag:yaml.org,2002:str",
|
|
27891
|
-
resolve: (
|
|
27891
|
+
resolve: (str2) => str2,
|
|
27892
27892
|
stringify(item, ctx, onComment, onChompKeep) {
|
|
27893
27893
|
ctx = Object.assign({ actualString: true }, ctx);
|
|
27894
27894
|
return stringifyString.stringifyString(item, ctx, onComment, onChompKeep);
|
|
@@ -27926,7 +27926,7 @@ var require_bool = __commonJS({
|
|
|
27926
27926
|
default: true,
|
|
27927
27927
|
tag: "tag:yaml.org,2002:bool",
|
|
27928
27928
|
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
27929
|
-
resolve: (
|
|
27929
|
+
resolve: (str2) => new Scalar.Scalar(str2[0] === "t" || str2[0] === "T"),
|
|
27930
27930
|
stringify({ source, value }, ctx) {
|
|
27931
27931
|
if (source && boolTag.test.test(source)) {
|
|
27932
27932
|
const sv = source[0] === "t" || source[0] === "T";
|
|
@@ -27947,9 +27947,9 @@ var require_stringifyNumber = __commonJS({
|
|
|
27947
27947
|
function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
27948
27948
|
if (typeof value === "bigint")
|
|
27949
27949
|
return String(value);
|
|
27950
|
-
const
|
|
27951
|
-
if (!isFinite(
|
|
27952
|
-
return isNaN(
|
|
27950
|
+
const num2 = typeof value === "number" ? value : Number(value);
|
|
27951
|
+
if (!isFinite(num2))
|
|
27952
|
+
return isNaN(num2) ? ".nan" : num2 < 0 ? "-.inf" : ".inf";
|
|
27953
27953
|
let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
|
|
27954
27954
|
if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
|
|
27955
27955
|
let i = n.indexOf(".");
|
|
@@ -27978,7 +27978,7 @@ var require_float = __commonJS({
|
|
|
27978
27978
|
default: true,
|
|
27979
27979
|
tag: "tag:yaml.org,2002:float",
|
|
27980
27980
|
test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
|
|
27981
|
-
resolve: (
|
|
27981
|
+
resolve: (str2) => str2.slice(-3).toLowerCase() === "nan" ? NaN : str2[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
27982
27982
|
stringify: stringifyNumber.stringifyNumber
|
|
27983
27983
|
};
|
|
27984
27984
|
var floatExp = {
|
|
@@ -27987,10 +27987,10 @@ var require_float = __commonJS({
|
|
|
27987
27987
|
tag: "tag:yaml.org,2002:float",
|
|
27988
27988
|
format: "EXP",
|
|
27989
27989
|
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
27990
|
-
resolve: (
|
|
27990
|
+
resolve: (str2) => parseFloat(str2),
|
|
27991
27991
|
stringify(node) {
|
|
27992
|
-
const
|
|
27993
|
-
return isFinite(
|
|
27992
|
+
const num2 = Number(node.value);
|
|
27993
|
+
return isFinite(num2) ? num2.toExponential() : stringifyNumber.stringifyNumber(node);
|
|
27994
27994
|
}
|
|
27995
27995
|
};
|
|
27996
27996
|
var float = {
|
|
@@ -27998,11 +27998,11 @@ var require_float = __commonJS({
|
|
|
27998
27998
|
default: true,
|
|
27999
27999
|
tag: "tag:yaml.org,2002:float",
|
|
28000
28000
|
test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
|
|
28001
|
-
resolve(
|
|
28002
|
-
const node = new Scalar.Scalar(parseFloat(
|
|
28003
|
-
const dot =
|
|
28004
|
-
if (dot !== -1 &&
|
|
28005
|
-
node.minFractionDigits =
|
|
28001
|
+
resolve(str2) {
|
|
28002
|
+
const node = new Scalar.Scalar(parseFloat(str2));
|
|
28003
|
+
const dot = str2.indexOf(".");
|
|
28004
|
+
if (dot !== -1 && str2[str2.length - 1] === "0")
|
|
28005
|
+
node.minFractionDigits = str2.length - dot - 1;
|
|
28006
28006
|
return node;
|
|
28007
28007
|
},
|
|
28008
28008
|
stringify: stringifyNumber.stringifyNumber
|
|
@@ -28019,7 +28019,7 @@ var require_int = __commonJS({
|
|
|
28019
28019
|
"use strict";
|
|
28020
28020
|
var stringifyNumber = require_stringifyNumber();
|
|
28021
28021
|
var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
|
|
28022
|
-
var intResolve = (
|
|
28022
|
+
var intResolve = (str2, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str2) : parseInt(str2.substring(offset), radix);
|
|
28023
28023
|
function intStringify(node, radix, prefix) {
|
|
28024
28024
|
const { value } = node;
|
|
28025
28025
|
if (intIdentify(value) && value >= 0)
|
|
@@ -28032,7 +28032,7 @@ var require_int = __commonJS({
|
|
|
28032
28032
|
tag: "tag:yaml.org,2002:int",
|
|
28033
28033
|
format: "OCT",
|
|
28034
28034
|
test: /^0o[0-7]+$/,
|
|
28035
|
-
resolve: (
|
|
28035
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 2, 8, opt),
|
|
28036
28036
|
stringify: (node) => intStringify(node, 8, "0o")
|
|
28037
28037
|
};
|
|
28038
28038
|
var int = {
|
|
@@ -28040,7 +28040,7 @@ var require_int = __commonJS({
|
|
|
28040
28040
|
default: true,
|
|
28041
28041
|
tag: "tag:yaml.org,2002:int",
|
|
28042
28042
|
test: /^[-+]?[0-9]+$/,
|
|
28043
|
-
resolve: (
|
|
28043
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 0, 10, opt),
|
|
28044
28044
|
stringify: stringifyNumber.stringifyNumber
|
|
28045
28045
|
};
|
|
28046
28046
|
var intHex = {
|
|
@@ -28049,7 +28049,7 @@ var require_int = __commonJS({
|
|
|
28049
28049
|
tag: "tag:yaml.org,2002:int",
|
|
28050
28050
|
format: "HEX",
|
|
28051
28051
|
test: /^0x[0-9a-fA-F]+$/,
|
|
28052
|
-
resolve: (
|
|
28052
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 2, 16, opt),
|
|
28053
28053
|
stringify: (node) => intStringify(node, 16, "0x")
|
|
28054
28054
|
};
|
|
28055
28055
|
exports2.int = int;
|
|
@@ -28102,7 +28102,7 @@ var require_schema2 = __commonJS({
|
|
|
28102
28102
|
identify: (value) => typeof value === "string",
|
|
28103
28103
|
default: true,
|
|
28104
28104
|
tag: "tag:yaml.org,2002:str",
|
|
28105
|
-
resolve: (
|
|
28105
|
+
resolve: (str2) => str2,
|
|
28106
28106
|
stringify: stringifyJSON
|
|
28107
28107
|
},
|
|
28108
28108
|
{
|
|
@@ -28119,7 +28119,7 @@ var require_schema2 = __commonJS({
|
|
|
28119
28119
|
default: true,
|
|
28120
28120
|
tag: "tag:yaml.org,2002:bool",
|
|
28121
28121
|
test: /^true$|^false$/,
|
|
28122
|
-
resolve: (
|
|
28122
|
+
resolve: (str2) => str2 === "true",
|
|
28123
28123
|
stringify: stringifyJSON
|
|
28124
28124
|
},
|
|
28125
28125
|
{
|
|
@@ -28127,7 +28127,7 @@ var require_schema2 = __commonJS({
|
|
|
28127
28127
|
default: true,
|
|
28128
28128
|
tag: "tag:yaml.org,2002:int",
|
|
28129
28129
|
test: /^-?(?:0|[1-9][0-9]*)$/,
|
|
28130
|
-
resolve: (
|
|
28130
|
+
resolve: (str2, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str2) : parseInt(str2, 10),
|
|
28131
28131
|
stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
|
|
28132
28132
|
},
|
|
28133
28133
|
{
|
|
@@ -28135,7 +28135,7 @@ var require_schema2 = __commonJS({
|
|
|
28135
28135
|
default: true,
|
|
28136
28136
|
tag: "tag:yaml.org,2002:float",
|
|
28137
28137
|
test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
|
|
28138
|
-
resolve: (
|
|
28138
|
+
resolve: (str2) => parseFloat(str2),
|
|
28139
28139
|
stringify: stringifyJSON
|
|
28140
28140
|
}
|
|
28141
28141
|
];
|
|
@@ -28143,9 +28143,9 @@ var require_schema2 = __commonJS({
|
|
|
28143
28143
|
default: true,
|
|
28144
28144
|
tag: "",
|
|
28145
28145
|
test: /^/,
|
|
28146
|
-
resolve(
|
|
28147
|
-
onError(`Unresolved plain scalar ${JSON.stringify(
|
|
28148
|
-
return
|
|
28146
|
+
resolve(str2, onError) {
|
|
28147
|
+
onError(`Unresolved plain scalar ${JSON.stringify(str2)}`);
|
|
28148
|
+
return str2;
|
|
28149
28149
|
}
|
|
28150
28150
|
};
|
|
28151
28151
|
var schema = [map.map, seq.seq].concat(jsonScalars, jsonError);
|
|
@@ -28177,10 +28177,10 @@ var require_binary = __commonJS({
|
|
|
28177
28177
|
if (typeof node_buffer.Buffer === "function") {
|
|
28178
28178
|
return node_buffer.Buffer.from(src, "base64");
|
|
28179
28179
|
} else if (typeof atob === "function") {
|
|
28180
|
-
const
|
|
28181
|
-
const buffer = new Uint8Array(
|
|
28182
|
-
for (let i = 0; i <
|
|
28183
|
-
buffer[i] =
|
|
28180
|
+
const str2 = atob(src.replace(/[\n\r]/g, ""));
|
|
28181
|
+
const buffer = new Uint8Array(str2.length);
|
|
28182
|
+
for (let i = 0; i < str2.length; ++i)
|
|
28183
|
+
buffer[i] = str2.charCodeAt(i);
|
|
28184
28184
|
return buffer;
|
|
28185
28185
|
} else {
|
|
28186
28186
|
onError("This environment does not support reading binary tags; either Buffer or atob is required");
|
|
@@ -28191,28 +28191,28 @@ var require_binary = __commonJS({
|
|
|
28191
28191
|
if (!value)
|
|
28192
28192
|
return "";
|
|
28193
28193
|
const buf = value;
|
|
28194
|
-
let
|
|
28194
|
+
let str2;
|
|
28195
28195
|
if (typeof node_buffer.Buffer === "function") {
|
|
28196
|
-
|
|
28196
|
+
str2 = buf instanceof node_buffer.Buffer ? buf.toString("base64") : node_buffer.Buffer.from(buf.buffer).toString("base64");
|
|
28197
28197
|
} else if (typeof btoa === "function") {
|
|
28198
28198
|
let s = "";
|
|
28199
28199
|
for (let i = 0; i < buf.length; ++i)
|
|
28200
28200
|
s += String.fromCharCode(buf[i]);
|
|
28201
|
-
|
|
28201
|
+
str2 = btoa(s);
|
|
28202
28202
|
} else {
|
|
28203
28203
|
throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
|
|
28204
28204
|
}
|
|
28205
28205
|
type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
|
|
28206
28206
|
if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
|
|
28207
28207
|
const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
|
|
28208
|
-
const n = Math.ceil(
|
|
28208
|
+
const n = Math.ceil(str2.length / lineWidth);
|
|
28209
28209
|
const lines = new Array(n);
|
|
28210
28210
|
for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
|
|
28211
|
-
lines[i] =
|
|
28211
|
+
lines[i] = str2.substr(o, lineWidth);
|
|
28212
28212
|
}
|
|
28213
|
-
|
|
28213
|
+
str2 = lines.join(type === Scalar.Scalar.BLOCK_LITERAL ? "\n" : " ");
|
|
28214
28214
|
}
|
|
28215
|
-
return stringifyString.stringifyString({ comment, type, value:
|
|
28215
|
+
return stringifyString.stringifyString({ comment, type, value: str2 }, ctx, onComment, onChompKeep);
|
|
28216
28216
|
}
|
|
28217
28217
|
};
|
|
28218
28218
|
exports2.binary = binary;
|
|
@@ -28418,7 +28418,7 @@ var require_float2 = __commonJS({
|
|
|
28418
28418
|
default: true,
|
|
28419
28419
|
tag: "tag:yaml.org,2002:float",
|
|
28420
28420
|
test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
|
|
28421
|
-
resolve: (
|
|
28421
|
+
resolve: (str2) => str2.slice(-3).toLowerCase() === "nan" ? NaN : str2[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
28422
28422
|
stringify: stringifyNumber.stringifyNumber
|
|
28423
28423
|
};
|
|
28424
28424
|
var floatExp = {
|
|
@@ -28427,10 +28427,10 @@ var require_float2 = __commonJS({
|
|
|
28427
28427
|
tag: "tag:yaml.org,2002:float",
|
|
28428
28428
|
format: "EXP",
|
|
28429
28429
|
test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
28430
|
-
resolve: (
|
|
28430
|
+
resolve: (str2) => parseFloat(str2.replace(/_/g, "")),
|
|
28431
28431
|
stringify(node) {
|
|
28432
|
-
const
|
|
28433
|
-
return isFinite(
|
|
28432
|
+
const num2 = Number(node.value);
|
|
28433
|
+
return isFinite(num2) ? num2.toExponential() : stringifyNumber.stringifyNumber(node);
|
|
28434
28434
|
}
|
|
28435
28435
|
};
|
|
28436
28436
|
var float = {
|
|
@@ -28438,11 +28438,11 @@ var require_float2 = __commonJS({
|
|
|
28438
28438
|
default: true,
|
|
28439
28439
|
tag: "tag:yaml.org,2002:float",
|
|
28440
28440
|
test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
|
|
28441
|
-
resolve(
|
|
28442
|
-
const node = new Scalar.Scalar(parseFloat(
|
|
28443
|
-
const dot =
|
|
28441
|
+
resolve(str2) {
|
|
28442
|
+
const node = new Scalar.Scalar(parseFloat(str2.replace(/_/g, "")));
|
|
28443
|
+
const dot = str2.indexOf(".");
|
|
28444
28444
|
if (dot !== -1) {
|
|
28445
|
-
const f =
|
|
28445
|
+
const f = str2.substring(dot + 1).replace(/_/g, "");
|
|
28446
28446
|
if (f[f.length - 1] === "0")
|
|
28447
28447
|
node.minFractionDigits = f.length;
|
|
28448
28448
|
}
|
|
@@ -28462,34 +28462,34 @@ var require_int2 = __commonJS({
|
|
|
28462
28462
|
"use strict";
|
|
28463
28463
|
var stringifyNumber = require_stringifyNumber();
|
|
28464
28464
|
var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
|
|
28465
|
-
function intResolve(
|
|
28466
|
-
const sign =
|
|
28465
|
+
function intResolve(str2, offset, radix, { intAsBigInt }) {
|
|
28466
|
+
const sign = str2[0];
|
|
28467
28467
|
if (sign === "-" || sign === "+")
|
|
28468
28468
|
offset += 1;
|
|
28469
|
-
|
|
28469
|
+
str2 = str2.substring(offset).replace(/_/g, "");
|
|
28470
28470
|
if (intAsBigInt) {
|
|
28471
28471
|
switch (radix) {
|
|
28472
28472
|
case 2:
|
|
28473
|
-
|
|
28473
|
+
str2 = `0b${str2}`;
|
|
28474
28474
|
break;
|
|
28475
28475
|
case 8:
|
|
28476
|
-
|
|
28476
|
+
str2 = `0o${str2}`;
|
|
28477
28477
|
break;
|
|
28478
28478
|
case 16:
|
|
28479
|
-
|
|
28479
|
+
str2 = `0x${str2}`;
|
|
28480
28480
|
break;
|
|
28481
28481
|
}
|
|
28482
|
-
const n2 = BigInt(
|
|
28482
|
+
const n2 = BigInt(str2);
|
|
28483
28483
|
return sign === "-" ? BigInt(-1) * n2 : n2;
|
|
28484
28484
|
}
|
|
28485
|
-
const n = parseInt(
|
|
28485
|
+
const n = parseInt(str2, radix);
|
|
28486
28486
|
return sign === "-" ? -1 * n : n;
|
|
28487
28487
|
}
|
|
28488
28488
|
function intStringify(node, radix, prefix) {
|
|
28489
28489
|
const { value } = node;
|
|
28490
28490
|
if (intIdentify(value)) {
|
|
28491
|
-
const
|
|
28492
|
-
return value < 0 ? "-" + prefix +
|
|
28491
|
+
const str2 = value.toString(radix);
|
|
28492
|
+
return value < 0 ? "-" + prefix + str2.substr(1) : prefix + str2;
|
|
28493
28493
|
}
|
|
28494
28494
|
return stringifyNumber.stringifyNumber(node);
|
|
28495
28495
|
}
|
|
@@ -28499,7 +28499,7 @@ var require_int2 = __commonJS({
|
|
|
28499
28499
|
tag: "tag:yaml.org,2002:int",
|
|
28500
28500
|
format: "BIN",
|
|
28501
28501
|
test: /^[-+]?0b[0-1_]+$/,
|
|
28502
|
-
resolve: (
|
|
28502
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 2, 2, opt),
|
|
28503
28503
|
stringify: (node) => intStringify(node, 2, "0b")
|
|
28504
28504
|
};
|
|
28505
28505
|
var intOct = {
|
|
@@ -28508,7 +28508,7 @@ var require_int2 = __commonJS({
|
|
|
28508
28508
|
tag: "tag:yaml.org,2002:int",
|
|
28509
28509
|
format: "OCT",
|
|
28510
28510
|
test: /^[-+]?0[0-7_]+$/,
|
|
28511
|
-
resolve: (
|
|
28511
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 1, 8, opt),
|
|
28512
28512
|
stringify: (node) => intStringify(node, 8, "0")
|
|
28513
28513
|
};
|
|
28514
28514
|
var int = {
|
|
@@ -28516,7 +28516,7 @@ var require_int2 = __commonJS({
|
|
|
28516
28516
|
default: true,
|
|
28517
28517
|
tag: "tag:yaml.org,2002:int",
|
|
28518
28518
|
test: /^[-+]?[0-9][0-9_]*$/,
|
|
28519
|
-
resolve: (
|
|
28519
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 0, 10, opt),
|
|
28520
28520
|
stringify: stringifyNumber.stringifyNumber
|
|
28521
28521
|
};
|
|
28522
28522
|
var intHex = {
|
|
@@ -28525,7 +28525,7 @@ var require_int2 = __commonJS({
|
|
|
28525
28525
|
tag: "tag:yaml.org,2002:int",
|
|
28526
28526
|
format: "HEX",
|
|
28527
28527
|
test: /^[-+]?0x[0-9a-fA-F_]+$/,
|
|
28528
|
-
resolve: (
|
|
28528
|
+
resolve: (str2, _onError, opt) => intResolve(str2, 2, 16, opt),
|
|
28529
28529
|
stringify: (node) => intStringify(node, 16, "0x")
|
|
28530
28530
|
};
|
|
28531
28531
|
exports2.int = int;
|
|
@@ -28590,18 +28590,18 @@ var require_set = __commonJS({
|
|
|
28590
28590
|
}
|
|
28591
28591
|
static from(schema, iterable, ctx) {
|
|
28592
28592
|
const { replacer } = ctx;
|
|
28593
|
-
const
|
|
28593
|
+
const set3 = new this(schema);
|
|
28594
28594
|
if (iterable && Symbol.iterator in Object(iterable))
|
|
28595
28595
|
for (let value of iterable) {
|
|
28596
28596
|
if (typeof replacer === "function")
|
|
28597
28597
|
value = replacer.call(iterable, value, value);
|
|
28598
|
-
|
|
28598
|
+
set3.items.push(Pair.createPair(value, null, ctx));
|
|
28599
28599
|
}
|
|
28600
|
-
return
|
|
28600
|
+
return set3;
|
|
28601
28601
|
}
|
|
28602
28602
|
};
|
|
28603
28603
|
YAMLSet.tag = "tag:yaml.org,2002:set";
|
|
28604
|
-
var
|
|
28604
|
+
var set2 = {
|
|
28605
28605
|
collection: "map",
|
|
28606
28606
|
identify: (value) => value instanceof Set,
|
|
28607
28607
|
nodeClass: YAMLSet,
|
|
@@ -28620,7 +28620,7 @@ var require_set = __commonJS({
|
|
|
28620
28620
|
}
|
|
28621
28621
|
};
|
|
28622
28622
|
exports2.YAMLSet = YAMLSet;
|
|
28623
|
-
exports2.set =
|
|
28623
|
+
exports2.set = set2;
|
|
28624
28624
|
}
|
|
28625
28625
|
});
|
|
28626
28626
|
|
|
@@ -28629,26 +28629,26 @@ var require_timestamp = __commonJS({
|
|
|
28629
28629
|
"../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js"(exports2) {
|
|
28630
28630
|
"use strict";
|
|
28631
28631
|
var stringifyNumber = require_stringifyNumber();
|
|
28632
|
-
function parseSexagesimal(
|
|
28633
|
-
const sign =
|
|
28634
|
-
const parts = sign === "-" || sign === "+" ?
|
|
28635
|
-
const
|
|
28636
|
-
const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 *
|
|
28637
|
-
return sign === "-" ?
|
|
28632
|
+
function parseSexagesimal(str2, asBigInt) {
|
|
28633
|
+
const sign = str2[0];
|
|
28634
|
+
const parts = sign === "-" || sign === "+" ? str2.substring(1) : str2;
|
|
28635
|
+
const num2 = (n) => asBigInt ? BigInt(n) : Number(n);
|
|
28636
|
+
const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num2(60) + num2(p), num2(0));
|
|
28637
|
+
return sign === "-" ? num2(-1) * res : res;
|
|
28638
28638
|
}
|
|
28639
28639
|
function stringifySexagesimal(node) {
|
|
28640
28640
|
let { value } = node;
|
|
28641
|
-
let
|
|
28641
|
+
let num2 = (n) => n;
|
|
28642
28642
|
if (typeof value === "bigint")
|
|
28643
|
-
|
|
28643
|
+
num2 = (n) => BigInt(n);
|
|
28644
28644
|
else if (isNaN(value) || !isFinite(value))
|
|
28645
28645
|
return stringifyNumber.stringifyNumber(node);
|
|
28646
28646
|
let sign = "";
|
|
28647
28647
|
if (value < 0) {
|
|
28648
28648
|
sign = "-";
|
|
28649
|
-
value *=
|
|
28649
|
+
value *= num2(-1);
|
|
28650
28650
|
}
|
|
28651
|
-
const _60 =
|
|
28651
|
+
const _60 = num2(60);
|
|
28652
28652
|
const parts = [value % _60];
|
|
28653
28653
|
if (value < 60) {
|
|
28654
28654
|
parts.unshift(0);
|
|
@@ -28668,7 +28668,7 @@ var require_timestamp = __commonJS({
|
|
|
28668
28668
|
tag: "tag:yaml.org,2002:int",
|
|
28669
28669
|
format: "TIME",
|
|
28670
28670
|
test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
|
|
28671
|
-
resolve: (
|
|
28671
|
+
resolve: (str2, _onError, { intAsBigInt }) => parseSexagesimal(str2, intAsBigInt),
|
|
28672
28672
|
stringify: stringifySexagesimal
|
|
28673
28673
|
};
|
|
28674
28674
|
var floatTime = {
|
|
@@ -28677,7 +28677,7 @@ var require_timestamp = __commonJS({
|
|
|
28677
28677
|
tag: "tag:yaml.org,2002:float",
|
|
28678
28678
|
format: "TIME",
|
|
28679
28679
|
test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
|
|
28680
|
-
resolve: (
|
|
28680
|
+
resolve: (str2) => parseSexagesimal(str2, false),
|
|
28681
28681
|
stringify: stringifySexagesimal
|
|
28682
28682
|
};
|
|
28683
28683
|
var timestamp = {
|
|
@@ -28688,8 +28688,8 @@ var require_timestamp = __commonJS({
|
|
|
28688
28688
|
// may be omitted altogether, resulting in a date format. In such a case, the time part is
|
|
28689
28689
|
// assumed to be 00:00:00Z (start of day, UTC).
|
|
28690
28690
|
test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
|
|
28691
|
-
resolve(
|
|
28692
|
-
const match =
|
|
28691
|
+
resolve(str2) {
|
|
28692
|
+
const match = str2.match(timestamp.test);
|
|
28693
28693
|
if (!match)
|
|
28694
28694
|
throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
|
|
28695
28695
|
const [, year, month, day, hour, minute, second] = match.map(Number);
|
|
@@ -28727,7 +28727,7 @@ var require_schema3 = __commonJS({
|
|
|
28727
28727
|
var merge = require_merge();
|
|
28728
28728
|
var omap = require_omap();
|
|
28729
28729
|
var pairs = require_pairs();
|
|
28730
|
-
var
|
|
28730
|
+
var set2 = require_set();
|
|
28731
28731
|
var timestamp = require_timestamp();
|
|
28732
28732
|
var schema = [
|
|
28733
28733
|
map.map,
|
|
@@ -28747,7 +28747,7 @@ var require_schema3 = __commonJS({
|
|
|
28747
28747
|
merge.merge,
|
|
28748
28748
|
omap.omap,
|
|
28749
28749
|
pairs.pairs,
|
|
28750
|
-
|
|
28750
|
+
set2.set,
|
|
28751
28751
|
timestamp.intTime,
|
|
28752
28752
|
timestamp.floatTime,
|
|
28753
28753
|
timestamp.timestamp
|
|
@@ -28774,7 +28774,7 @@ var require_tags = __commonJS({
|
|
|
28774
28774
|
var omap = require_omap();
|
|
28775
28775
|
var pairs = require_pairs();
|
|
28776
28776
|
var schema$2 = require_schema3();
|
|
28777
|
-
var
|
|
28777
|
+
var set2 = require_set();
|
|
28778
28778
|
var timestamp = require_timestamp();
|
|
28779
28779
|
var schemas = /* @__PURE__ */ new Map([
|
|
28780
28780
|
["core", schema.schema],
|
|
@@ -28800,7 +28800,7 @@ var require_tags = __commonJS({
|
|
|
28800
28800
|
omap: omap.omap,
|
|
28801
28801
|
pairs: pairs.pairs,
|
|
28802
28802
|
seq: seq.seq,
|
|
28803
|
-
set:
|
|
28803
|
+
set: set2.set,
|
|
28804
28804
|
timestamp: timestamp.timestamp
|
|
28805
28805
|
};
|
|
28806
28806
|
var coreKnownTags = {
|
|
@@ -28808,7 +28808,7 @@ var require_tags = __commonJS({
|
|
|
28808
28808
|
"tag:yaml.org,2002:merge": merge.merge,
|
|
28809
28809
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
28810
28810
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
28811
|
-
"tag:yaml.org,2002:set":
|
|
28811
|
+
"tag:yaml.org,2002:set": set2.set,
|
|
28812
28812
|
"tag:yaml.org,2002:timestamp": timestamp.timestamp
|
|
28813
28813
|
};
|
|
28814
28814
|
function getTags(customTags, schemaName, addMergeTag) {
|
|
@@ -29238,8 +29238,8 @@ var require_Document = __commonJS({
|
|
|
29238
29238
|
};
|
|
29239
29239
|
const res = toJS.toJS(this.contents, jsonArg ?? "", ctx);
|
|
29240
29240
|
if (typeof onAnchor === "function")
|
|
29241
|
-
for (const { count, res: res2 } of ctx.anchors.values())
|
|
29242
|
-
onAnchor(res2,
|
|
29241
|
+
for (const { count: count2, res: res2 } of ctx.anchors.values())
|
|
29242
|
+
onAnchor(res2, count2);
|
|
29243
29243
|
return typeof reviver === "function" ? applyReviver.applyReviver(reviver, { "": res }, "", res) : res;
|
|
29244
29244
|
}
|
|
29245
29245
|
/**
|
|
@@ -29316,12 +29316,12 @@ var require_errors2 = __commonJS({
|
|
|
29316
29316
|
lineStr = prev + lineStr;
|
|
29317
29317
|
}
|
|
29318
29318
|
if (/[^ ]/.test(lineStr)) {
|
|
29319
|
-
let
|
|
29319
|
+
let count2 = 1;
|
|
29320
29320
|
const end = error.linePos[1];
|
|
29321
29321
|
if (end?.line === line && end.col > col) {
|
|
29322
|
-
|
|
29322
|
+
count2 = Math.max(1, Math.min(end.col - col, 80 - ci));
|
|
29323
29323
|
}
|
|
29324
|
-
const pointer = " ".repeat(ci) + "^".repeat(
|
|
29324
|
+
const pointer = " ".repeat(ci) + "^".repeat(count2);
|
|
29325
29325
|
error.message += `:
|
|
29326
29326
|
|
|
29327
29327
|
${lineStr}
|
|
@@ -32933,9 +32933,9 @@ var require_dist = __commonJS({
|
|
|
32933
32933
|
});
|
|
32934
32934
|
|
|
32935
32935
|
// src/index.ts
|
|
32936
|
-
var
|
|
32937
|
-
var
|
|
32938
|
-
var
|
|
32936
|
+
var import_promises7 = require("node:readline/promises");
|
|
32937
|
+
var import_promises8 = require("node:fs/promises");
|
|
32938
|
+
var import_node_os9 = require("node:os");
|
|
32939
32939
|
|
|
32940
32940
|
// ../../node_modules/.pnpm/@supabase+supabase-js@2.108.2/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
32941
32941
|
var dist_exports = {};
|
|
@@ -33277,7 +33277,7 @@ ${cause.stack}`;
|
|
|
33277
33277
|
var _this2 = this;
|
|
33278
33278
|
let error = null;
|
|
33279
33279
|
let data = null;
|
|
33280
|
-
let
|
|
33280
|
+
let count2 = null;
|
|
33281
33281
|
let status = res.status;
|
|
33282
33282
|
let statusText = res.statusText;
|
|
33283
33283
|
if (res.ok) {
|
|
@@ -33303,7 +33303,7 @@ ${cause.stack}`;
|
|
|
33303
33303
|
}
|
|
33304
33304
|
const countHeader = (_this$headers$get2 = _this2.headers.get("Prefer")) === null || _this$headers$get2 === void 0 ? void 0 : _this$headers$get2.match(/count=(exact|planned|estimated)/);
|
|
33305
33305
|
const contentRange = (_res$headers$get2 = res.headers.get("content-range")) === null || _res$headers$get2 === void 0 ? void 0 : _res$headers$get2.split("/");
|
|
33306
|
-
if (countHeader && contentRange && contentRange.length > 1)
|
|
33306
|
+
if (countHeader && contentRange && contentRange.length > 1) count2 = parseInt(contentRange[1]);
|
|
33307
33307
|
if (_this2.isMaybeSingle && Array.isArray(data)) if (data.length > 1) {
|
|
33308
33308
|
error = {
|
|
33309
33309
|
code: "PGRST116",
|
|
@@ -33312,7 +33312,7 @@ ${cause.stack}`;
|
|
|
33312
33312
|
message: "JSON object requested, multiple (or no) rows returned"
|
|
33313
33313
|
};
|
|
33314
33314
|
data = null;
|
|
33315
|
-
|
|
33315
|
+
count2 = null;
|
|
33316
33316
|
status = 406;
|
|
33317
33317
|
statusText = "Not Acceptable";
|
|
33318
33318
|
} else if (data.length === 1) data = data[0];
|
|
@@ -33339,7 +33339,7 @@ ${cause.stack}`;
|
|
|
33339
33339
|
success: error === null,
|
|
33340
33340
|
error,
|
|
33341
33341
|
data,
|
|
33342
|
-
count,
|
|
33342
|
+
count: count2,
|
|
33343
33343
|
status,
|
|
33344
33344
|
statusText
|
|
33345
33345
|
};
|
|
@@ -36939,7 +36939,7 @@ var PostgrestQueryBuilder = class {
|
|
|
36939
36939
|
* ```
|
|
36940
36940
|
*/
|
|
36941
36941
|
select(columns, options) {
|
|
36942
|
-
const { head: head2 = false, count } = options !== null && options !== void 0 ? options : {};
|
|
36942
|
+
const { head: head2 = false, count: count2 } = options !== null && options !== void 0 ? options : {};
|
|
36943
36943
|
const method = head2 ? "HEAD" : "GET";
|
|
36944
36944
|
let quoted = false;
|
|
36945
36945
|
const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => {
|
|
@@ -36949,7 +36949,7 @@ var PostgrestQueryBuilder = class {
|
|
|
36949
36949
|
}).join("");
|
|
36950
36950
|
const { url, headers } = this.cloneRequestState();
|
|
36951
36951
|
url.searchParams.set("select", cleanedColumns);
|
|
36952
|
-
if (
|
|
36952
|
+
if (count2) headers.append("Prefer", `count=${count2}`);
|
|
36953
36953
|
return new PostgrestFilterBuilder({
|
|
36954
36954
|
method,
|
|
36955
36955
|
url,
|
|
@@ -37080,11 +37080,11 @@ var PostgrestQueryBuilder = class {
|
|
|
37080
37080
|
* }
|
|
37081
37081
|
* ```
|
|
37082
37082
|
*/
|
|
37083
|
-
insert(values, { count, defaultToNull = true } = {}) {
|
|
37083
|
+
insert(values, { count: count2, defaultToNull = true } = {}) {
|
|
37084
37084
|
var _this$fetch;
|
|
37085
37085
|
const method = "POST";
|
|
37086
37086
|
const { url, headers } = this.cloneRequestState();
|
|
37087
|
-
if (
|
|
37087
|
+
if (count2) headers.append("Prefer", `count=${count2}`);
|
|
37088
37088
|
if (!defaultToNull) headers.append("Prefer", `missing=default`);
|
|
37089
37089
|
if (Array.isArray(values)) {
|
|
37090
37090
|
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
|
|
@@ -37321,13 +37321,13 @@ var PostgrestQueryBuilder = class {
|
|
|
37321
37321
|
* }
|
|
37322
37322
|
* ```
|
|
37323
37323
|
*/
|
|
37324
|
-
upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true } = {}) {
|
|
37324
|
+
upsert(values, { onConflict, ignoreDuplicates = false, count: count2, defaultToNull = true } = {}) {
|
|
37325
37325
|
var _this$fetch2;
|
|
37326
37326
|
const method = "POST";
|
|
37327
37327
|
const { url, headers } = this.cloneRequestState();
|
|
37328
37328
|
headers.append("Prefer", `resolution=${ignoreDuplicates ? "ignore" : "merge"}-duplicates`);
|
|
37329
37329
|
if (onConflict !== void 0) url.searchParams.set("on_conflict", onConflict);
|
|
37330
|
-
if (
|
|
37330
|
+
if (count2) headers.append("Prefer", `count=${count2}`);
|
|
37331
37331
|
if (!defaultToNull) headers.append("Prefer", "missing=default");
|
|
37332
37332
|
if (Array.isArray(values)) {
|
|
37333
37333
|
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
|
|
@@ -37495,11 +37495,11 @@ var PostgrestQueryBuilder = class {
|
|
|
37495
37495
|
* }
|
|
37496
37496
|
* ```
|
|
37497
37497
|
*/
|
|
37498
|
-
update(values, { count } = {}) {
|
|
37498
|
+
update(values, { count: count2 } = {}) {
|
|
37499
37499
|
var _this$fetch3;
|
|
37500
37500
|
const method = "PATCH";
|
|
37501
37501
|
const { url, headers } = this.cloneRequestState();
|
|
37502
|
-
if (
|
|
37502
|
+
if (count2) headers.append("Prefer", `count=${count2}`);
|
|
37503
37503
|
return new PostgrestFilterBuilder({
|
|
37504
37504
|
method,
|
|
37505
37505
|
url,
|
|
@@ -37638,11 +37638,11 @@ var PostgrestQueryBuilder = class {
|
|
|
37638
37638
|
* }
|
|
37639
37639
|
* ```
|
|
37640
37640
|
*/
|
|
37641
|
-
delete({ count } = {}) {
|
|
37641
|
+
delete({ count: count2 } = {}) {
|
|
37642
37642
|
var _this$fetch4;
|
|
37643
37643
|
const method = "DELETE";
|
|
37644
37644
|
const { url, headers } = this.cloneRequestState();
|
|
37645
|
-
if (
|
|
37645
|
+
if (count2) headers.append("Prefer", `count=${count2}`);
|
|
37646
37646
|
return new PostgrestFilterBuilder({
|
|
37647
37647
|
method,
|
|
37648
37648
|
url,
|
|
@@ -37975,7 +37975,7 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37975
37975
|
* }
|
|
37976
37976
|
* ```
|
|
37977
37977
|
*/
|
|
37978
|
-
rpc(fn, args = {}, { head: head2 = false, get: get2 = false, count } = {}) {
|
|
37978
|
+
rpc(fn, args = {}, { head: head2 = false, get: get2 = false, count: count2 } = {}) {
|
|
37979
37979
|
var _this$fetch;
|
|
37980
37980
|
let method;
|
|
37981
37981
|
const url = new URL(`${this.url}/rpc/${fn}`);
|
|
@@ -37995,8 +37995,8 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37995
37995
|
body = args;
|
|
37996
37996
|
}
|
|
37997
37997
|
const headers = new Headers(this.headers);
|
|
37998
|
-
if (_hasObjectArg) headers.set("Prefer",
|
|
37999
|
-
else if (
|
|
37998
|
+
if (_hasObjectArg) headers.set("Prefer", count2 ? `count=${count2},return=minimal` : "return=minimal");
|
|
37999
|
+
else if (count2) headers.set("Prefer", `count=${count2}`);
|
|
38000
38000
|
return new PostgrestFilterBuilder({
|
|
38001
38001
|
method,
|
|
38002
38002
|
url,
|
|
@@ -41368,12 +41368,12 @@ function shouldPropagateToTarget(targetUrl, targets) {
|
|
|
41368
41368
|
}
|
|
41369
41369
|
return false;
|
|
41370
41370
|
}
|
|
41371
|
-
function matchStringTarget(
|
|
41372
|
-
if (target ===
|
|
41371
|
+
function matchStringTarget(hostname3, target) {
|
|
41372
|
+
if (target === hostname3) return true;
|
|
41373
41373
|
if (target.startsWith("*.")) {
|
|
41374
41374
|
const domain = target.slice(2);
|
|
41375
|
-
if (
|
|
41376
|
-
if (
|
|
41375
|
+
if (hostname3.endsWith(domain)) {
|
|
41376
|
+
if (hostname3 === domain || hostname3.endsWith("." + domain)) return true;
|
|
41377
41377
|
}
|
|
41378
41378
|
}
|
|
41379
41379
|
return false;
|
|
@@ -42126,6 +42126,9 @@ function isTemplateExample(lines, i) {
|
|
|
42126
42126
|
return entry.kind === "comment" && TEMPLATE_EXAMPLE_RE.test(entry.text) && prev?.kind === "comment" && TEMPLATE_LEAD_IN_RE.test(prev.text);
|
|
42127
42127
|
}
|
|
42128
42128
|
function parseCrontab(text) {
|
|
42129
|
+
return parseCrontabLines(text).map((l) => l.entry);
|
|
42130
|
+
}
|
|
42131
|
+
function parseCrontabLines(text) {
|
|
42129
42132
|
const lines = text.split("\n").map((l) => parseLine(l.replace(/\r$/, "")));
|
|
42130
42133
|
const out = [];
|
|
42131
42134
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -42136,14 +42139,14 @@ function parseCrontab(text) {
|
|
|
42136
42139
|
if (m && next) {
|
|
42137
42140
|
const ann = splitAnnotation(m[1]);
|
|
42138
42141
|
if (next.kind === "job") {
|
|
42139
|
-
out.push({ ...next, ...ann, enabled: true });
|
|
42142
|
+
out.push({ entry: { ...next, ...ann, enabled: true }, line: i + 1 });
|
|
42140
42143
|
i++;
|
|
42141
42144
|
continue;
|
|
42142
42145
|
}
|
|
42143
42146
|
if (next.kind === "comment") {
|
|
42144
42147
|
const disabled = parseDisabledJob(next.text);
|
|
42145
42148
|
if (disabled) {
|
|
42146
|
-
out.push({ kind: "job", ...disabled, ...ann, enabled: false });
|
|
42149
|
+
out.push({ entry: { kind: "job", ...disabled, ...ann, enabled: false }, line: i + 1 });
|
|
42147
42150
|
i++;
|
|
42148
42151
|
continue;
|
|
42149
42152
|
}
|
|
@@ -42153,11 +42156,11 @@ function parseCrontab(text) {
|
|
|
42153
42156
|
if (entry.kind === "comment" && !isTemplateExample(lines, i)) {
|
|
42154
42157
|
const disabled = parseDisabledJob(entry.text);
|
|
42155
42158
|
if (disabled) {
|
|
42156
|
-
out.push({ kind: "job", ...disabled, enabled: false });
|
|
42159
|
+
out.push({ entry: { kind: "job", ...disabled, enabled: false }, line: i });
|
|
42157
42160
|
continue;
|
|
42158
42161
|
}
|
|
42159
42162
|
}
|
|
42160
|
-
out.push(entry);
|
|
42163
|
+
out.push({ entry, line: i });
|
|
42161
42164
|
}
|
|
42162
42165
|
return out;
|
|
42163
42166
|
}
|
|
@@ -42203,14 +42206,22 @@ var norcBinary = "norc";
|
|
|
42203
42206
|
function setNorcBinary(path) {
|
|
42204
42207
|
norcBinary = path;
|
|
42205
42208
|
}
|
|
42206
|
-
|
|
42209
|
+
var ENV_NAME_RE = /^[A-Z_][A-Z0-9_]{0,127}$/;
|
|
42210
|
+
function normalizeEnvNames(names) {
|
|
42211
|
+
for (const n of names) if (!ENV_NAME_RE.test(n)) throw new Error(`invalid env name: ${JSON.stringify(n).slice(0, 40)}`);
|
|
42212
|
+
return [...new Set(names)].sort();
|
|
42213
|
+
}
|
|
42214
|
+
function wrapCommand(jobId, command, platform2 = "posix", envNames = []) {
|
|
42215
|
+
const names = normalizeEnvNames(envNames);
|
|
42207
42216
|
if (norcBinary === null) return command;
|
|
42208
|
-
const quote =
|
|
42217
|
+
const quote = platform2 === "windows" ? cmdQuote : shQuote;
|
|
42209
42218
|
const bin = SAFE_PATH.test(norcBinary) ? norcBinary : quote(norcBinary);
|
|
42210
|
-
|
|
42219
|
+
const env = names.length > 0 ? ` --env ${names.join(",")}` : "";
|
|
42220
|
+
return `${bin} run --job-id ${jobId}${env} -- ${quote(command)}`;
|
|
42211
42221
|
}
|
|
42212
42222
|
var BINARY_TOKEN = String.raw`(?:'(?:[^']|'\\'')*'|"(?:[^"\\]|\\.)*"|[^\s'"]+)`;
|
|
42213
|
-
var
|
|
42223
|
+
var ENV_LIST = String.raw`[A-Z_][A-Z0-9_]{0,127}(?:,[A-Z_][A-Z0-9_]{0,127})*`;
|
|
42224
|
+
var WRAPPED = new RegExp(String.raw`^${BINARY_TOKEN}\s+run\s+--job-id\s+(\S+)(?:\s+--env\s+(${ENV_LIST}))?\s+--\s+([\s\S]+)$`);
|
|
42214
42225
|
function unquote(s) {
|
|
42215
42226
|
if (s.length >= 2 && s.startsWith("'") && s.endsWith("'")) {
|
|
42216
42227
|
return s.slice(1, -1).replace(/'\\''/g, "'");
|
|
@@ -42220,9 +42231,23 @@ function unquote(s) {
|
|
|
42220
42231
|
}
|
|
42221
42232
|
return s;
|
|
42222
42233
|
}
|
|
42223
|
-
function unwrapCommand(
|
|
42224
|
-
const m = WRAPPED.exec(
|
|
42225
|
-
return m ? unquote(m[
|
|
42234
|
+
function unwrapCommand(wrapped2) {
|
|
42235
|
+
const m = WRAPPED.exec(wrapped2);
|
|
42236
|
+
return m ? unquote(m[3]) : wrapped2;
|
|
42237
|
+
}
|
|
42238
|
+
function wrappedJobId(wrapped2) {
|
|
42239
|
+
const m = WRAPPED.exec(wrapped2);
|
|
42240
|
+
return m ? m[1] : null;
|
|
42241
|
+
}
|
|
42242
|
+
var WRAPPED_PARTS = new RegExp(String.raw`^(${BINARY_TOKEN}\s+run\s+--job-id\s+\S+)(?:\s+--env\s+${ENV_LIST})?(\s+--\s+[\s\S]+)$`);
|
|
42243
|
+
function setEnvNames(wrapped2, envNames) {
|
|
42244
|
+
const names = normalizeEnvNames(envNames);
|
|
42245
|
+
const m = WRAPPED_PARTS.exec(wrapped2);
|
|
42246
|
+
return m ? `${m[1]}${names.length > 0 ? ` --env ${names.join(",")}` : ""}${m[2]}` : null;
|
|
42247
|
+
}
|
|
42248
|
+
function wrappedEnvNames(wrapped2) {
|
|
42249
|
+
const m = WRAPPED.exec(wrapped2);
|
|
42250
|
+
return m ? m[2] ? m[2].split(",") : [] : null;
|
|
42226
42251
|
}
|
|
42227
42252
|
|
|
42228
42253
|
// ../../packages/crontab/src/jobs.ts
|
|
@@ -42248,14 +42273,14 @@ function assertSafeJobs(jobs) {
|
|
|
42248
42273
|
if (val.length > MAX_FIELD) throw new Error(`job ${j.id}: ${field} exceeds ${MAX_FIELD} chars`);
|
|
42249
42274
|
}
|
|
42250
42275
|
}
|
|
42251
|
-
const
|
|
42276
|
+
const wrapped2 = new Map(jobs.map((j) => [j.id, wrapCommand(j.id, j.command, "posix", j.envNames ?? [])]));
|
|
42252
42277
|
const entries = parseCrontab(renderCrontab(jobs.map((j) => ({
|
|
42253
42278
|
kind: "job",
|
|
42254
42279
|
id: j.id,
|
|
42255
42280
|
name: j.name,
|
|
42256
42281
|
enabled: j.enabled,
|
|
42257
42282
|
schedule: j.schedule,
|
|
42258
|
-
command:
|
|
42283
|
+
command: wrapped2.get(j.id)
|
|
42259
42284
|
}))));
|
|
42260
42285
|
const got = entries.filter((e) => e.kind === "job" && e.id !== void 0);
|
|
42261
42286
|
if (got.length !== jobs.length) throw new Error("job set does not round-trip (line count mismatch)");
|
|
@@ -42263,21 +42288,38 @@ function assertSafeJobs(jobs) {
|
|
|
42263
42288
|
for (const e of got) {
|
|
42264
42289
|
if (e.kind !== "job") continue;
|
|
42265
42290
|
const j = byId.get(e.id);
|
|
42266
|
-
if (!j || e.schedule !== j.schedule || e.command !==
|
|
42291
|
+
if (!j || e.schedule !== j.schedule || e.command !== wrapped2.get(j.id) || e.name !== j.name || e.enabled !== j.enabled) {
|
|
42267
42292
|
throw new Error(`job ${e.id} does not round-trip`);
|
|
42268
42293
|
}
|
|
42269
42294
|
}
|
|
42270
42295
|
}
|
|
42271
42296
|
|
|
42272
42297
|
// ../../packages/crontab/src/projection.ts
|
|
42273
|
-
function
|
|
42298
|
+
function rewriteEnvNames(currentCrontab, names) {
|
|
42299
|
+
const lines = currentCrontab.split("\n");
|
|
42300
|
+
let changed = false;
|
|
42301
|
+
for (const { entry: e, line } of parseCrontabLines(currentCrontab)) {
|
|
42302
|
+
if (e.kind !== "job" || e.id === void 0 || !names.has(e.id) || wrappedJobId(e.command) !== e.id) continue;
|
|
42303
|
+
const live = wrappedEnvNames(e.command);
|
|
42304
|
+
const want = normalizeEnvNames(names.get(e.id));
|
|
42305
|
+
if (live.length === want.length && live.every((n, i) => n === want[i])) continue;
|
|
42306
|
+
const raw = lines[line];
|
|
42307
|
+
const cr = raw.endsWith("\r") ? "\r" : "";
|
|
42308
|
+
const body = cr ? raw.slice(0, -1) : raw;
|
|
42309
|
+
if (!body.endsWith(e.command)) continue;
|
|
42310
|
+
lines[line] = body.slice(0, body.length - e.command.length) + setEnvNames(e.command, want) + cr;
|
|
42311
|
+
changed = true;
|
|
42312
|
+
}
|
|
42313
|
+
return changed ? lines.join("\n") : currentCrontab;
|
|
42314
|
+
}
|
|
42315
|
+
function jobToEntry(job, liveNames = null) {
|
|
42274
42316
|
return {
|
|
42275
42317
|
kind: "job",
|
|
42276
42318
|
id: job.id,
|
|
42277
42319
|
name: job.name,
|
|
42278
42320
|
enabled: job.enabled,
|
|
42279
42321
|
schedule: job.schedule,
|
|
42280
|
-
command: wrapCommand(job.id, job.command)
|
|
42322
|
+
command: wrapCommand(job.id, job.command, "posix", job.envNames ?? liveNames ?? [])
|
|
42281
42323
|
};
|
|
42282
42324
|
}
|
|
42283
42325
|
function renderJobsToCrontab(currentCrontab, allJobs) {
|
|
@@ -42290,7 +42332,7 @@ function renderJobsToCrontab(currentCrontab, allJobs) {
|
|
|
42290
42332
|
if (entry.kind === "job" && entry.id !== void 0) {
|
|
42291
42333
|
const job = byId.get(entry.id);
|
|
42292
42334
|
if (!job || rendered.has(job.id)) continue;
|
|
42293
|
-
out.push(jobToEntry(job));
|
|
42335
|
+
out.push(jobToEntry(job, wrappedEnvNames(entry.command)));
|
|
42294
42336
|
rendered.add(job.id);
|
|
42295
42337
|
continue;
|
|
42296
42338
|
}
|
|
@@ -42320,6 +42362,12 @@ function tagUnmanagedInCrontab(currentCrontab, job, occurrence) {
|
|
|
42320
42362
|
return renderCrontab(out);
|
|
42321
42363
|
}
|
|
42322
42364
|
|
|
42365
|
+
// ../../packages/bridge/src/text-hash.ts
|
|
42366
|
+
async function sha256Hex(text) {
|
|
42367
|
+
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
42368
|
+
return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
42369
|
+
}
|
|
42370
|
+
|
|
42323
42371
|
// ../../packages/bridge/src/handler.ts
|
|
42324
42372
|
async function handleCommand(cmd, io) {
|
|
42325
42373
|
try {
|
|
@@ -42331,6 +42379,14 @@ async function handleCommand(cmd, io) {
|
|
|
42331
42379
|
const changedAt = io.changedAt?.(contents);
|
|
42332
42380
|
return changedAt && Object.keys(changedAt).length > 0 ? { type: "crontab", contents, changedAt } : { type: "crontab", contents };
|
|
42333
42381
|
}
|
|
42382
|
+
case "read_managed": {
|
|
42383
|
+
const contents = await io.read();
|
|
42384
|
+
const changedAt = io.changedAt?.(contents);
|
|
42385
|
+
const managed = renderCrontab(parseCrontab(contents).filter((e) => e.kind === "job" && e.id !== void 0));
|
|
42386
|
+
return changedAt && Object.keys(changedAt).length > 0 ? { type: "crontab", contents: managed, changedAt } : { type: "crontab", contents: managed };
|
|
42387
|
+
}
|
|
42388
|
+
case "crontab_hash":
|
|
42389
|
+
return { type: "crontab_hash", hash: await sha256Hex(await io.read()) };
|
|
42334
42390
|
case "list_jobs":
|
|
42335
42391
|
return { type: "jobs", jobs: jobsOf(parseCrontab(await io.read())) };
|
|
42336
42392
|
case "write_crontab": {
|
|
@@ -42402,17 +42458,70 @@ function withLineChanges(io, tracker) {
|
|
|
42402
42458
|
|
|
42403
42459
|
// ../../packages/entitlements/src/plans.ts
|
|
42404
42460
|
var FREE = ["byok_ai"];
|
|
42405
|
-
var PRO = [...FREE, "remote_ssh", "cross_device_sync", "alerts"];
|
|
42461
|
+
var PRO = [...FREE, "remote_ssh", "cross_device_sync", "alerts", "api_write", "run_monitoring"];
|
|
42406
42462
|
var POWER = [...PRO, "bulk_ops"];
|
|
42407
42463
|
var TEAM = [...POWER, "workspaces", "rbac", "audit_log"];
|
|
42464
|
+
var PLANS = {
|
|
42465
|
+
free: { machineLimit: 2, jobLimit: 15, envVarLimit: 5, historyDays: 7, capabilities: FREE },
|
|
42466
|
+
pro: { machineLimit: 5, jobLimit: 30, envVarLimit: 25, historyDays: 90, capabilities: PRO },
|
|
42467
|
+
power: { machineLimit: 25, jobLimit: 150, envVarLimit: 100, historyDays: 365, capabilities: POWER },
|
|
42468
|
+
team: { machineLimit: "custom", jobLimit: "custom", envVarLimit: "custom", historyDays: 365, capabilities: TEAM }
|
|
42469
|
+
};
|
|
42470
|
+
|
|
42471
|
+
// ../../packages/entitlements/src/can.ts
|
|
42472
|
+
function machineLimit(plan) {
|
|
42473
|
+
return PLANS[plan].machineLimit;
|
|
42474
|
+
}
|
|
42475
|
+
function jobLimit(plan) {
|
|
42476
|
+
return PLANS[plan].jobLimit;
|
|
42477
|
+
}
|
|
42478
|
+
function envVarLimit(plan) {
|
|
42479
|
+
return PLANS[plan].envVarLimit;
|
|
42480
|
+
}
|
|
42481
|
+
function withinEnvVarLimit(plan, currentCount) {
|
|
42482
|
+
const limit = envVarLimit(plan);
|
|
42483
|
+
return limit === "custom" ? true : currentCount < limit;
|
|
42484
|
+
}
|
|
42485
|
+
function envVarUsageLabel(plan, count2) {
|
|
42486
|
+
const limit = envVarLimit(plan);
|
|
42487
|
+
const noun = `variable${count2 === 1 ? "" : "s"}`;
|
|
42488
|
+
return limit === "custom" ? `${count2} ${noun}` : `${count2} of ${limit} variables used`;
|
|
42489
|
+
}
|
|
42490
|
+
function envVarLimitMessage(plan, count2) {
|
|
42491
|
+
const limit = envVarLimit(plan);
|
|
42492
|
+
if (limit === "custom" || withinEnvVarLimit(plan, count2)) return null;
|
|
42493
|
+
return `You've used all ${limit} variables on the ${plan.charAt(0).toUpperCase() + plan.slice(1)} plan. Upgrade to add more.`;
|
|
42494
|
+
}
|
|
42495
|
+
|
|
42496
|
+
// ../../packages/entitlements/src/trial.ts
|
|
42497
|
+
var TRIAL_PLAN = "pro";
|
|
42498
|
+
function toDate(v) {
|
|
42499
|
+
if (v == null) return null;
|
|
42500
|
+
const d = v instanceof Date ? v : new Date(v);
|
|
42501
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
42502
|
+
}
|
|
42503
|
+
function effectivePlan(plan, trialEndsAt, now = /* @__PURE__ */ new Date()) {
|
|
42504
|
+
const end = toDate(trialEndsAt);
|
|
42505
|
+
return plan === "free" && end !== null && end.getTime() > now.getTime() ? TRIAL_PLAN : plan;
|
|
42506
|
+
}
|
|
42408
42507
|
|
|
42409
42508
|
// ../../packages/bridge/src/pairing.ts
|
|
42410
42509
|
function formatPairingCode(raw) {
|
|
42411
42510
|
return `${raw.slice(0, 4)}-${raw.slice(4, 8)}`;
|
|
42412
42511
|
}
|
|
42512
|
+
var PAIR_RATE_LIMITED_MESSAGE = "Too many attempts. Wait 10 minutes and try again.";
|
|
42513
|
+
function isPairRateLimited(e) {
|
|
42514
|
+
return !!e && (e.code === "PT429" || /PAIR_RATE_LIMITED/.test(e.message ?? ""));
|
|
42515
|
+
}
|
|
42516
|
+
|
|
42517
|
+
// ../../packages/bridge/src/protocol.ts
|
|
42518
|
+
var FULL_READ_COMMANDS = ["read_crontab", "list_jobs"];
|
|
42413
42519
|
|
|
42414
42520
|
// ../../packages/bridge/src/transport.ts
|
|
42415
|
-
|
|
42521
|
+
function fullReadGate(consent, message = "device owner has not allowed remote crontab reads") {
|
|
42522
|
+
return async (type) => FULL_READ_COMMANDS.includes(type) && !await consent() ? message : null;
|
|
42523
|
+
}
|
|
42524
|
+
async function handleMessage(io, data, allow, authorize) {
|
|
42416
42525
|
let req;
|
|
42417
42526
|
try {
|
|
42418
42527
|
req = JSON.parse(data);
|
|
@@ -42423,12 +42532,14 @@ async function handleMessage(io, data, allow) {
|
|
|
42423
42532
|
if (allow && !allow.includes(req.command.type)) {
|
|
42424
42533
|
return JSON.stringify({ id: req.id, response: { type: "error", message: "command not allowed" } });
|
|
42425
42534
|
}
|
|
42535
|
+
const denied = await authorize?.(req.command.type).catch(() => "consent check failed");
|
|
42536
|
+
if (denied) return JSON.stringify({ id: req.id, response: { type: "error", message: denied } });
|
|
42426
42537
|
const reply = await handleRequest(req, io);
|
|
42427
42538
|
return JSON.stringify(reply);
|
|
42428
42539
|
}
|
|
42429
42540
|
function serveBridge(transport, io, opts) {
|
|
42430
42541
|
transport.onMessage(async (data, respond) => {
|
|
42431
|
-
const out = await handleMessage(io, data, opts?.allow);
|
|
42542
|
+
const out = await handleMessage(io, data, opts?.allow, opts?.authorize);
|
|
42432
42543
|
if (out !== null) (respond ?? ((o) => transport.send(o)))(out);
|
|
42433
42544
|
});
|
|
42434
42545
|
}
|
|
@@ -42453,23 +42564,35 @@ function backoffDelay(attempt, baseMs = 500, capMs = 3e4) {
|
|
|
42453
42564
|
|
|
42454
42565
|
// ../../packages/bridge/src/jwt.ts
|
|
42455
42566
|
function b64urlToBytes(s) {
|
|
42456
|
-
const
|
|
42457
|
-
const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") +
|
|
42567
|
+
const pad2 = s.length % 4 ? "=".repeat(4 - s.length % 4) : "";
|
|
42568
|
+
const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") + pad2);
|
|
42458
42569
|
const buf = new ArrayBuffer(bin.length);
|
|
42459
42570
|
const out = new Uint8Array(buf);
|
|
42460
42571
|
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
42461
42572
|
return out;
|
|
42462
42573
|
}
|
|
42463
|
-
async function verifyEs256Jwt(jwt,
|
|
42574
|
+
async function verifyEs256Jwt(jwt, trust) {
|
|
42464
42575
|
const parts = jwt.split(".");
|
|
42465
42576
|
if (parts.length !== 3) return { valid: false, payload: null };
|
|
42466
42577
|
const [h, p, s] = parts;
|
|
42578
|
+
let candidates = Array.isArray(trust) ? trust : [trust];
|
|
42579
|
+
if (Array.isArray(trust)) {
|
|
42580
|
+
try {
|
|
42581
|
+
const kid = JSON.parse(new TextDecoder().decode(b64urlToBytes(h))).kid;
|
|
42582
|
+
if (typeof kid === "string") candidates = candidates.filter((k) => k.kid === kid);
|
|
42583
|
+
} catch {
|
|
42584
|
+
return { valid: false, payload: null };
|
|
42585
|
+
}
|
|
42586
|
+
}
|
|
42467
42587
|
let valid = false;
|
|
42468
|
-
|
|
42469
|
-
|
|
42470
|
-
|
|
42471
|
-
|
|
42472
|
-
|
|
42588
|
+
for (const publicJwk of candidates) {
|
|
42589
|
+
try {
|
|
42590
|
+
const key = await crypto.subtle.importKey("jwk", publicJwk, { name: "ECDSA", namedCurve: "P-256" }, false, ["verify"]);
|
|
42591
|
+
valid = await crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, key, b64urlToBytes(s), new TextEncoder().encode(`${h}.${p}`));
|
|
42592
|
+
} catch {
|
|
42593
|
+
valid = false;
|
|
42594
|
+
}
|
|
42595
|
+
if (valid) break;
|
|
42473
42596
|
}
|
|
42474
42597
|
if (!valid) return { valid: false, payload: null };
|
|
42475
42598
|
try {
|
|
@@ -42506,10 +42629,21 @@ function extractRaw(payload) {
|
|
|
42506
42629
|
if (typeof baseHash !== "string" || !HEX64.test(baseHash)) return void 0;
|
|
42507
42630
|
return { baseHash };
|
|
42508
42631
|
}
|
|
42632
|
+
var MAX_LIFETIME_S = 60;
|
|
42633
|
+
var MAX_SKEW_S = 60;
|
|
42634
|
+
function lifetimeProblem(payload, nowSec) {
|
|
42635
|
+
const iat = payload.iat, exp = payload.exp;
|
|
42636
|
+
if (typeof iat !== "number" || typeof exp !== "number") return "missing iat/exp";
|
|
42637
|
+
if (iat > nowSec + MAX_SKEW_S) return "issued in the future";
|
|
42638
|
+
if (exp - iat > MAX_LIFETIME_S) return "lifetime too long";
|
|
42639
|
+
return null;
|
|
42640
|
+
}
|
|
42509
42641
|
async function verifyCapability(jws, opts) {
|
|
42510
42642
|
const { valid, payload } = await verifyEs256Jwt(jws, opts.publicJwk);
|
|
42511
42643
|
if (!valid || !payload) return { ok: false, reason: "bad signature" };
|
|
42512
42644
|
if (payload.aud !== "norc-device-write") return { ok: false, reason: "bad audience" };
|
|
42645
|
+
const lp = lifetimeProblem(payload, opts.nowSec);
|
|
42646
|
+
if (lp) return { ok: false, reason: lp };
|
|
42513
42647
|
if (payload.machine_id !== opts.machineId) return { ok: false, reason: "wrong machine" };
|
|
42514
42648
|
const exp = typeof payload.exp === "number" ? payload.exp : 0;
|
|
42515
42649
|
if (opts.nowSec > exp) return { ok: false, reason: "expired" };
|
|
@@ -42524,6 +42658,8 @@ async function verifyExecuteCapability(jws, opts) {
|
|
|
42524
42658
|
const { valid, payload } = await verifyEs256Jwt(jws, opts.publicJwk);
|
|
42525
42659
|
if (!valid || !payload) return { ok: false, reason: "bad signature" };
|
|
42526
42660
|
if (payload.aud !== "norc-device-execute") return { ok: false, reason: "bad audience" };
|
|
42661
|
+
const lp = lifetimeProblem(payload, opts.nowSec);
|
|
42662
|
+
if (lp) return { ok: false, reason: lp };
|
|
42527
42663
|
if (payload.machine_id !== opts.machineId) return { ok: false, reason: "wrong machine" };
|
|
42528
42664
|
if (payload.job_id !== opts.jobId) return { ok: false, reason: "wrong job" };
|
|
42529
42665
|
const exp = typeof payload.exp === "number" ? payload.exp : 0;
|
|
@@ -42533,12 +42669,6 @@ async function verifyExecuteCapability(jws, opts) {
|
|
|
42533
42669
|
return { ok: true, nonce, nonceExp: exp };
|
|
42534
42670
|
}
|
|
42535
42671
|
|
|
42536
|
-
// ../../packages/bridge/src/text-hash.ts
|
|
42537
|
-
async function sha256Hex(text) {
|
|
42538
|
-
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
42539
|
-
return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
42540
|
-
}
|
|
42541
|
-
|
|
42542
42672
|
// ../../packages/bridge/src/raw-guard.ts
|
|
42543
42673
|
var MAX_CRONTAB_BYTES = 65536;
|
|
42544
42674
|
var MAX_CRONTAB_LINES = 1e3;
|
|
@@ -42558,6 +42688,7 @@ function validateRawCrontab(contents) {
|
|
|
42558
42688
|
|
|
42559
42689
|
// ../../packages/bridge/src/write-intent.ts
|
|
42560
42690
|
async function handleWriteIntent(msg, d) {
|
|
42691
|
+
if (!msg.jobs.every((j) => typeof j.id === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(j.id))) return { applied: false, reason: "invalid job id" };
|
|
42561
42692
|
const intentHash = await canonicalJobsHash(msg.jobs);
|
|
42562
42693
|
const v = await verifyCapability(msg.capability, {
|
|
42563
42694
|
publicJwk: d.publicJwk,
|
|
@@ -42569,22 +42700,30 @@ async function handleWriteIntent(msg, d) {
|
|
|
42569
42700
|
});
|
|
42570
42701
|
if (!v.ok) return { applied: false, reason: v.reason };
|
|
42571
42702
|
if (v.raw) return { applied: false, reason: "raw capability not valid for job-set write" };
|
|
42572
|
-
if (!d.consentGranted()) {
|
|
42573
|
-
const granted = await d.requestConsent();
|
|
42574
|
-
if (!granted) return { applied: false, reason: "consent denied" };
|
|
42575
|
-
}
|
|
42576
42703
|
const now = new Date(d.nowSec() * 1e3).toISOString();
|
|
42577
|
-
|
|
42578
|
-
|
|
42704
|
+
let held = /* @__PURE__ */ new Set();
|
|
42705
|
+
if (d.heldJobIds) {
|
|
42706
|
+
try {
|
|
42707
|
+
held = await d.heldJobIds(msg.jobs);
|
|
42708
|
+
} catch {
|
|
42709
|
+
return { applied: false, reason: "could not check which jobs are held; retry" };
|
|
42710
|
+
}
|
|
42711
|
+
}
|
|
42712
|
+
const names = d.envNames ? await d.envNames(msg.jobs).catch(() => null) : null;
|
|
42713
|
+
const jobs = msg.jobs.filter((j) => !held.has(j.id)).map((j) => ({ ...j, createdAt: now, updatedAt: now, ...names ? { envNames: Object.hasOwn(names, j.id) ? names[j.id] : [] } : {} }));
|
|
42714
|
+
const base = await d.readCrontab();
|
|
42715
|
+
let crontab = base;
|
|
42579
42716
|
if (v.adopt) {
|
|
42580
42717
|
const adoptedJob = jobs.find((j) => j.id === v.adopt.jobId);
|
|
42581
42718
|
if (adoptedJob) crontab = tagUnmanagedInCrontab(crontab, adoptedJob, v.adopt.occurrence);
|
|
42582
42719
|
}
|
|
42583
42720
|
const next = renderJobsToCrontab(crontab, jobs);
|
|
42584
|
-
await d.writeCrontab(next);
|
|
42585
42721
|
d.rememberNonce(v.nonce);
|
|
42722
|
+
if (!await d.requestConsent({ before: base, after: next, jobs: msg.jobs })) return { applied: false, reason: "consent denied" };
|
|
42723
|
+
if (await d.readCrontab() !== base) return { applied: false, reason: "crontab changed while waiting for consent; retry" };
|
|
42724
|
+
await d.writeCrontab(next);
|
|
42586
42725
|
d.setGeneration(v.generation);
|
|
42587
|
-
return { applied: true };
|
|
42726
|
+
return { applied: true, held: [...held] };
|
|
42588
42727
|
}
|
|
42589
42728
|
|
|
42590
42729
|
// ../../packages/bridge/src/raw-write-intent.ts
|
|
@@ -42609,7 +42748,9 @@ async function handleRawWriteIntent(msg, d) {
|
|
|
42609
42748
|
}
|
|
42610
42749
|
const granted = await d.requestRawConsent({
|
|
42611
42750
|
beforeLines: current.split("\n").length,
|
|
42612
|
-
afterLines: msg.contents.split("\n").length
|
|
42751
|
+
afterLines: msg.contents.split("\n").length,
|
|
42752
|
+
before: current,
|
|
42753
|
+
after: msg.contents
|
|
42613
42754
|
});
|
|
42614
42755
|
if (!granted) return { applied: false, reason: "consent denied" };
|
|
42615
42756
|
const atWrite = await d.readCrontab();
|
|
@@ -42620,6 +42761,22 @@ async function handleRawWriteIntent(msg, d) {
|
|
|
42620
42761
|
return { applied: true, nextHash: intentHash };
|
|
42621
42762
|
}
|
|
42622
42763
|
|
|
42764
|
+
// ../../packages/bridge/src/step-up.ts
|
|
42765
|
+
var StepUpRequired = class extends Error {
|
|
42766
|
+
constructor(method) {
|
|
42767
|
+
super("step_up_required");
|
|
42768
|
+
this.method = method;
|
|
42769
|
+
}
|
|
42770
|
+
};
|
|
42771
|
+
var STEP_UP_MARKS = ["step_up_required", "AAL2_REQUIRED", "FRESH_AUTH_REQUIRED"];
|
|
42772
|
+
function stepUpMethodOf(e) {
|
|
42773
|
+
if (e instanceof StepUpRequired) return e.method;
|
|
42774
|
+
if (!e || typeof e !== "object") return null;
|
|
42775
|
+
const o = e;
|
|
42776
|
+
const hit = ["message", "hint", "details", "code", "error"].some((k) => typeof o[k] === "string" && STEP_UP_MARKS.some((m) => o[k].includes(m)));
|
|
42777
|
+
return hit ? o.method === "reauth" || o.hint === "reauth" ? "reauth" : "totp" : null;
|
|
42778
|
+
}
|
|
42779
|
+
|
|
42623
42780
|
// ../../packages/bridge/src/crypto.ts
|
|
42624
42781
|
var VERSION = 1;
|
|
42625
42782
|
var ECDH = { name: "ECDH", namedCurve: "P-256" };
|
|
@@ -42629,8 +42786,8 @@ function b64url(bytes) {
|
|
|
42629
42786
|
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
42630
42787
|
}
|
|
42631
42788
|
function unb64url(s) {
|
|
42632
|
-
const
|
|
42633
|
-
const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") +
|
|
42789
|
+
const pad2 = s.length % 4 === 0 ? "" : "=".repeat(4 - s.length % 4);
|
|
42790
|
+
const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") + pad2);
|
|
42634
42791
|
const out = new Uint8Array(bin.length);
|
|
42635
42792
|
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
42636
42793
|
return out;
|
|
@@ -42774,6 +42931,26 @@ var SealedBridgeTransport = class {
|
|
|
42774
42931
|
}
|
|
42775
42932
|
};
|
|
42776
42933
|
|
|
42934
|
+
// ../../packages/bridge/src/capability-trust.ts
|
|
42935
|
+
var CAPABILITY_TRUST_LIST = [
|
|
42936
|
+
{
|
|
42937
|
+
kid: "09621c79-698f-4328-bdac-1c347546708e",
|
|
42938
|
+
status: "active",
|
|
42939
|
+
jwk: {
|
|
42940
|
+
kty: "EC",
|
|
42941
|
+
crv: "P-256",
|
|
42942
|
+
alg: "ES256",
|
|
42943
|
+
use: "sig",
|
|
42944
|
+
x: "yRbJAsSJpAtBBWIXUg_5tVi0n574uZjComtLR9O6Jwk",
|
|
42945
|
+
y: "dVHs6ZeMH10d6IypZgM2-Q9i18_bf_Jj8vsybRPX0Fk"
|
|
42946
|
+
}
|
|
42947
|
+
}
|
|
42948
|
+
// Pre-staged next key goes here as { kid, status: 'inactive', jwk: <public JWK> }.
|
|
42949
|
+
];
|
|
42950
|
+
function activeTrustedKeys(list = CAPABILITY_TRUST_LIST) {
|
|
42951
|
+
return list.filter((e) => e.status === "active" && e.kid && e.jwk.kty === "EC" && e.jwk.crv === "P-256" && !("d" in e.jwk)).map((e) => ({ ...e.jwk, kid: e.kid }));
|
|
42952
|
+
}
|
|
42953
|
+
|
|
42777
42954
|
// src/supabase-config.ts
|
|
42778
42955
|
var DEFAULT_SUPABASE_URL = "https://eiuegfdaddrisfboijyy.supabase.co";
|
|
42779
42956
|
var DEFAULT_SUPABASE_ANON_KEY = "sb_publishable_qGCC0eLvfmXwL86zA1SLHA_q8rFMCcG";
|
|
@@ -42784,9 +42961,13 @@ function supabaseUrl() {
|
|
|
42784
42961
|
return checkedSupabaseUrl(process.env.NORC_SUPABASE_URL ?? DEFAULT_SUPABASE_URL);
|
|
42785
42962
|
}
|
|
42786
42963
|
var DEFAULT_VAULT_URL = "https://vault.norc.app";
|
|
42964
|
+
function vaultUrl() {
|
|
42965
|
+
return assertSecureUrl(process.env.NORC_VAULT_URL ?? DEFAULT_VAULT_URL, { allowLocalDev: process.env.NORC_ALLOW_INSECURE_LOCAL === "1" });
|
|
42966
|
+
}
|
|
42787
42967
|
|
|
42788
42968
|
// src/config.ts
|
|
42789
42969
|
var import_promises = require("node:fs/promises");
|
|
42970
|
+
var import_node_child_process = require("node:child_process");
|
|
42790
42971
|
var import_node_os = require("node:os");
|
|
42791
42972
|
var import_node_path = require("node:path");
|
|
42792
42973
|
|
|
@@ -42867,14 +43048,113 @@ function redactSensitiveOutput(text) {
|
|
|
42867
43048
|
for (const [pattern, replacement] of SENSITIVE_REPLACEMENTS) out = out.replace(pattern, replacement);
|
|
42868
43049
|
return out;
|
|
42869
43050
|
}
|
|
43051
|
+
function matchStarts(hay, needle) {
|
|
43052
|
+
const m = needle.length;
|
|
43053
|
+
const out = [];
|
|
43054
|
+
if (!m || hay.length < m) return out;
|
|
43055
|
+
const fail = new Int32Array(m);
|
|
43056
|
+
for (let i = 1, k = 0; i < m; i++) {
|
|
43057
|
+
while (k && needle[i] !== needle[k]) k = fail[k - 1];
|
|
43058
|
+
if (needle[i] === needle[k]) k++;
|
|
43059
|
+
fail[i] = k;
|
|
43060
|
+
}
|
|
43061
|
+
for (let i = 0, k = 0; i < hay.length; i++) {
|
|
43062
|
+
while (k && hay[i] !== needle[k]) k = fail[k - 1];
|
|
43063
|
+
if (hay[i] === needle[k]) k++;
|
|
43064
|
+
if (k === m) {
|
|
43065
|
+
out.push(i - m + 1);
|
|
43066
|
+
k = fail[k - 1];
|
|
43067
|
+
}
|
|
43068
|
+
}
|
|
43069
|
+
return out;
|
|
43070
|
+
}
|
|
43071
|
+
var toUnits = (s) => {
|
|
43072
|
+
const u = new Uint16Array(s.length);
|
|
43073
|
+
for (let i = 0; i < s.length; i++) u[i] = s.charCodeAt(i);
|
|
43074
|
+
return u;
|
|
43075
|
+
};
|
|
43076
|
+
function scrubValues(text, values) {
|
|
43077
|
+
let reach;
|
|
43078
|
+
let hay;
|
|
43079
|
+
for (const v of new Set(values)) {
|
|
43080
|
+
if (v.length < 4) continue;
|
|
43081
|
+
hay ??= toUnits(text);
|
|
43082
|
+
for (const s2 of matchStarts(hay, toUnits(v))) {
|
|
43083
|
+
reach ??= new Int32Array(text.length);
|
|
43084
|
+
if (reach[s2] < s2 + v.length) reach[s2] = s2 + v.length;
|
|
43085
|
+
}
|
|
43086
|
+
}
|
|
43087
|
+
if (!reach) return text;
|
|
43088
|
+
let out = "";
|
|
43089
|
+
let pos = 0;
|
|
43090
|
+
let s = -1;
|
|
43091
|
+
let e = -1;
|
|
43092
|
+
for (let i = 0; i < reach.length; i++) {
|
|
43093
|
+
const re = reach[i];
|
|
43094
|
+
if (!re) continue;
|
|
43095
|
+
if (s >= 0 && i <= e) {
|
|
43096
|
+
if (re > e) e = re;
|
|
43097
|
+
continue;
|
|
43098
|
+
}
|
|
43099
|
+
if (s >= 0) {
|
|
43100
|
+
out += text.slice(pos, s) + "[redacted]";
|
|
43101
|
+
pos = e;
|
|
43102
|
+
}
|
|
43103
|
+
s = i;
|
|
43104
|
+
e = re;
|
|
43105
|
+
}
|
|
43106
|
+
return out + text.slice(pos, s) + "[redacted]" + text.slice(e);
|
|
43107
|
+
}
|
|
42870
43108
|
|
|
42871
43109
|
// src/config.ts
|
|
43110
|
+
function replayFor(config, machineId) {
|
|
43111
|
+
const b = config.bridge ??= {};
|
|
43112
|
+
const by = b.byMachine ??= {};
|
|
43113
|
+
if (b.generation !== void 0 || b.nonces !== void 0) {
|
|
43114
|
+
by[machineId] ??= { generation: b.generation ?? 0, nonces: b.nonces ?? [] };
|
|
43115
|
+
delete b.generation;
|
|
43116
|
+
delete b.nonces;
|
|
43117
|
+
}
|
|
43118
|
+
return by[machineId] ??= { generation: 0, nonces: [] };
|
|
43119
|
+
}
|
|
43120
|
+
function windowsOwnerOnlyAclArgs(dir, user) {
|
|
43121
|
+
return [dir, "/inheritance:r", "/grant:r", `${user}:(OI)(CI)F`];
|
|
43122
|
+
}
|
|
43123
|
+
function windowsOwnerOnlyDirAclSteps(dir, user) {
|
|
43124
|
+
return [[dir, "/reset"], windowsOwnerOnlyAclArgs(dir, user)];
|
|
43125
|
+
}
|
|
43126
|
+
function windowsOwnerOnlyFileAclSteps(file, user) {
|
|
43127
|
+
return [[file, "/reset"], [file, "/inheritance:r", "/grant:r", `${user}:F`]];
|
|
43128
|
+
}
|
|
43129
|
+
var defaultExec = (cmd, args, cb) => (0, import_node_child_process.execFile)(cmd, args, (err) => cb(err));
|
|
43130
|
+
function icacls(args, exec) {
|
|
43131
|
+
return new Promise((resolve, reject) => {
|
|
43132
|
+
exec("icacls", args, (err) => err ? reject(new Error(`icacls failed, refusing to write credentials: ${err.message}`)) : resolve());
|
|
43133
|
+
});
|
|
43134
|
+
}
|
|
43135
|
+
async function restrictWindowsAcl(dir, file, opts = {}) {
|
|
43136
|
+
if ((opts.platform ?? process.platform) !== "win32") return;
|
|
43137
|
+
const exec = opts.exec ?? defaultExec;
|
|
43138
|
+
const user = opts.user ?? (0, import_node_os.userInfo)().username;
|
|
43139
|
+
for (const step of windowsOwnerOnlyDirAclSteps(dir, user)) await icacls(step, exec);
|
|
43140
|
+
if (await (0, import_promises.access)(file).then(() => true, () => false)) {
|
|
43141
|
+
for (const step of windowsOwnerOnlyFileAclSteps(file, user)) await icacls(step, exec);
|
|
43142
|
+
}
|
|
43143
|
+
}
|
|
42872
43144
|
function configPath() {
|
|
42873
43145
|
return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "norc", "config.json");
|
|
42874
43146
|
}
|
|
43147
|
+
async function loadConfigStrict(path = configPath()) {
|
|
43148
|
+
try {
|
|
43149
|
+
return JSON.parse(await (0, import_promises.readFile)(path, "utf8"));
|
|
43150
|
+
} catch (e) {
|
|
43151
|
+
if (e.code === "ENOENT") return {};
|
|
43152
|
+
throw e;
|
|
43153
|
+
}
|
|
43154
|
+
}
|
|
42875
43155
|
async function loadConfig(path = configPath()) {
|
|
42876
43156
|
try {
|
|
42877
|
-
const config =
|
|
43157
|
+
const config = await loadConfigStrict(path);
|
|
42878
43158
|
debugLog("config: loaded", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
42879
43159
|
return config;
|
|
42880
43160
|
} catch (e) {
|
|
@@ -42882,24 +43162,93 @@ async function loadConfig(path = configPath()) {
|
|
|
42882
43162
|
return {};
|
|
42883
43163
|
}
|
|
42884
43164
|
}
|
|
42885
|
-
async function
|
|
42886
|
-
|
|
42887
|
-
|
|
42888
|
-
|
|
42889
|
-
|
|
42890
|
-
|
|
43165
|
+
async function refreshRemote(config, path = configPath()) {
|
|
43166
|
+
try {
|
|
43167
|
+
const disk = JSON.parse(await (0, import_promises.readFile)(path, "utf8"));
|
|
43168
|
+
config.remote = disk.remote;
|
|
43169
|
+
} catch {
|
|
43170
|
+
config.remote = void 0;
|
|
43171
|
+
}
|
|
43172
|
+
}
|
|
43173
|
+
var LOCK_STALE_MS = 1e4;
|
|
43174
|
+
var LOCK_WAIT_MS = 5e3;
|
|
43175
|
+
async function withConfigLock(path, fn) {
|
|
43176
|
+
const lock = `${path}.lock`;
|
|
43177
|
+
await (0, import_promises.mkdir)((0, import_node_path.join)(path, ".."), { recursive: true, mode: 448 });
|
|
43178
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
43179
|
+
for (; ; ) {
|
|
43180
|
+
try {
|
|
43181
|
+
await (0, import_promises.mkdir)(lock);
|
|
43182
|
+
break;
|
|
43183
|
+
} catch (e) {
|
|
43184
|
+
if (e.code !== "EEXIST") throw e;
|
|
43185
|
+
const age = await (0, import_promises.stat)(lock).then((st) => Date.now() - st.mtimeMs).catch(() => 0);
|
|
43186
|
+
if (age > LOCK_STALE_MS) {
|
|
43187
|
+
await (0, import_promises.rm)(lock, { recursive: true, force: true });
|
|
43188
|
+
continue;
|
|
43189
|
+
}
|
|
43190
|
+
if (Date.now() > deadline) throw new Error("config is locked by another norc process; try again");
|
|
43191
|
+
await new Promise((r) => setTimeout(r, 25));
|
|
43192
|
+
}
|
|
43193
|
+
}
|
|
43194
|
+
try {
|
|
43195
|
+
return await fn();
|
|
43196
|
+
} finally {
|
|
43197
|
+
await (0, import_promises.rm)(lock, { recursive: true, force: true });
|
|
43198
|
+
}
|
|
43199
|
+
}
|
|
43200
|
+
async function sweepConfigTemps(path = configPath(), minAgeMs = 6e4) {
|
|
43201
|
+
const base = (0, import_node_path.basename)(path).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43202
|
+
const re = new RegExp(`^${base}\\.\\d+\\.\\d+\\.tmp$`);
|
|
43203
|
+
const dir = (0, import_node_path.dirname)(path);
|
|
43204
|
+
for (const n of (await (0, import_promises.readdir)(dir).catch(() => [])).filter((x) => re.test(x))) {
|
|
43205
|
+
try {
|
|
43206
|
+
const f = (0, import_node_path.join)(dir, n);
|
|
43207
|
+
const st = await (0, import_promises.lstat)(f);
|
|
43208
|
+
if (st.isDirectory() || minAgeMs > 0 && Date.now() - st.mtimeMs < minAgeMs) continue;
|
|
43209
|
+
await (0, import_promises.rm)(f, { force: true });
|
|
43210
|
+
} catch {
|
|
43211
|
+
}
|
|
43212
|
+
}
|
|
43213
|
+
}
|
|
43214
|
+
async function saveConfig(config, path, opts) {
|
|
43215
|
+
path ??= configPath();
|
|
43216
|
+
const file = path;
|
|
43217
|
+
await withConfigLock(file, async () => {
|
|
43218
|
+
const disk = await loadConfigStrict(file);
|
|
43219
|
+
for (const k of opts.keys) delete disk[k];
|
|
43220
|
+
for (const k of opts.keys) if (config[k] !== void 0) Object.assign(disk, { [k]: config[k] });
|
|
43221
|
+
config = disk;
|
|
43222
|
+
const dir = (0, import_node_path.join)(path, "..");
|
|
43223
|
+
await (0, import_promises.mkdir)(dir, { recursive: true, mode: 448 });
|
|
43224
|
+
await (0, import_promises.chmod)(dir, 448);
|
|
43225
|
+
await restrictWindowsAcl(dir, path);
|
|
43226
|
+
await (0, import_promises.chmod)(path, 384).catch((e) => {
|
|
43227
|
+
if (e.code !== "ENOENT") throw e;
|
|
43228
|
+
});
|
|
43229
|
+
await sweepConfigTemps(path, opts.sweepAll ? 0 : 6e4);
|
|
43230
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
43231
|
+
try {
|
|
43232
|
+
await (0, import_promises.writeFile)(tmp, JSON.stringify(config, null, 2), { mode: 384 });
|
|
43233
|
+
await (0, import_promises.chmod)(tmp, 384);
|
|
43234
|
+
await (0, import_promises.rename)(tmp, path);
|
|
43235
|
+
} catch (e) {
|
|
43236
|
+
await (0, import_promises.rm)(tmp, { force: true }).catch(() => {
|
|
43237
|
+
});
|
|
43238
|
+
throw e;
|
|
43239
|
+
}
|
|
43240
|
+
await (0, import_promises.chmod)(path, 384);
|
|
43241
|
+
await restrictWindowsAcl(dir, path);
|
|
43242
|
+
debugLog("config: saved", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
42891
43243
|
});
|
|
42892
|
-
await (0, import_promises.writeFile)(path, JSON.stringify(config, null, 2), { mode: 384 });
|
|
42893
|
-
await (0, import_promises.chmod)(path, 384);
|
|
42894
|
-
debugLog("config: saved", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
42895
43244
|
}
|
|
42896
43245
|
|
|
42897
43246
|
// src/crontab-io.ts
|
|
42898
|
-
var
|
|
43247
|
+
var import_node_child_process2 = require("node:child_process");
|
|
42899
43248
|
var systemCrontabIo = {
|
|
42900
43249
|
read() {
|
|
42901
43250
|
return new Promise((resolve, reject) => {
|
|
42902
|
-
(0,
|
|
43251
|
+
(0, import_node_child_process2.execFile)("crontab", ["-l"], (err, stdout, stderr) => {
|
|
42903
43252
|
if (err) {
|
|
42904
43253
|
if (/no crontab/i.test(stderr)) return resolve("");
|
|
42905
43254
|
return reject(new Error(stderr.trim() || err.message));
|
|
@@ -42910,7 +43259,7 @@ var systemCrontabIo = {
|
|
|
42910
43259
|
},
|
|
42911
43260
|
write(contents) {
|
|
42912
43261
|
return new Promise((resolve, reject) => {
|
|
42913
|
-
const child = (0,
|
|
43262
|
+
const child = (0, import_node_child_process2.execFile)("crontab", ["-"], { timeout: 15e3 }, (err, _stdout, stderr) => {
|
|
42914
43263
|
if (err) return reject(new Error(stderr.trim() || err.message));
|
|
42915
43264
|
resolve();
|
|
42916
43265
|
});
|
|
@@ -42937,6 +43286,9 @@ async function verifyLogin(client, email, code) {
|
|
|
42937
43286
|
};
|
|
42938
43287
|
}
|
|
42939
43288
|
|
|
43289
|
+
// src/commands/pair.ts
|
|
43290
|
+
var import_node_os3 = require("node:os");
|
|
43291
|
+
|
|
42940
43292
|
// src/host-info.ts
|
|
42941
43293
|
var import_node_os2 = require("node:os");
|
|
42942
43294
|
function normalizeArch(raw) {
|
|
@@ -42987,10 +43339,12 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
42987
43339
|
hostname: info.hostname,
|
|
42988
43340
|
network_name: info.networkName,
|
|
42989
43341
|
ip_address: info.ipAddress,
|
|
42990
|
-
cpu_arch: info.cpuArch
|
|
43342
|
+
cpu_arch: info.cpuArch,
|
|
43343
|
+
os: `${(0, import_node_os3.platform)()} ${(0, import_node_os3.release)()}`
|
|
43344
|
+
// shown to the approver in pair_preview (AZ-011)
|
|
42991
43345
|
});
|
|
42992
43346
|
if (error || !data?.[0]) {
|
|
42993
|
-
onProgress({ phase: "error", message: error?.message ?? "start failed" });
|
|
43347
|
+
onProgress({ phase: "error", message: isPairRateLimited(error) ? PAIR_RATE_LIMITED_MESSAGE : error?.message ?? "start failed" });
|
|
42994
43348
|
return;
|
|
42995
43349
|
}
|
|
42996
43350
|
const { code, poll_secret } = data[0];
|
|
@@ -43018,13 +43372,13 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
43018
43372
|
}
|
|
43019
43373
|
|
|
43020
43374
|
// src/commands/pair-key.ts
|
|
43021
|
-
async function pairWithApiKey(fetchImpl,
|
|
43022
|
-
const url = `${
|
|
43023
|
-
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, hostname:
|
|
43375
|
+
async function pairWithApiKey(fetchImpl, vaultUrl2, apiKey, hostname3) {
|
|
43376
|
+
const url = `${vaultUrl2}/api/v1/machines`;
|
|
43377
|
+
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, hostname: hostname3 });
|
|
43024
43378
|
const res = await fetchImpl(url, {
|
|
43025
43379
|
method: "POST",
|
|
43026
43380
|
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
43027
|
-
body: JSON.stringify({ hostname:
|
|
43381
|
+
body: JSON.stringify({ hostname: hostname3 })
|
|
43028
43382
|
});
|
|
43029
43383
|
const rawText = await res.text().catch(() => "");
|
|
43030
43384
|
let body;
|
|
@@ -43113,14 +43467,53 @@ async function listJobs(io) {
|
|
|
43113
43467
|
return jobsOf(parseCrontab(await io.read()));
|
|
43114
43468
|
}
|
|
43115
43469
|
async function addJob(io, schedule, command, name) {
|
|
43470
|
+
const job = newJob(schedule, command, name);
|
|
43471
|
+
await appendJob(io, job);
|
|
43472
|
+
return job;
|
|
43473
|
+
}
|
|
43474
|
+
function newJob(schedule, command, name) {
|
|
43116
43475
|
const errors = validateCron(schedule);
|
|
43117
43476
|
if (errors.length > 0) throw new Error(`invalid schedule: ${errors.map((e) => e.message).join("; ")}`);
|
|
43118
43477
|
assertSafeField("command", command);
|
|
43119
43478
|
if (name) assertSafeField("name", name);
|
|
43479
|
+
return { kind: "job", id: (0, import_node_crypto.randomUUID)(), name, schedule, command, enabled: true };
|
|
43480
|
+
}
|
|
43481
|
+
var wrapped = (job, envNames = []) => ({ ...job, command: wrapCommand(job.id, job.command, "posix", envNames) });
|
|
43482
|
+
async function appendJob(io, job, envNames = []) {
|
|
43120
43483
|
const entries = parseCrontab(await io.read());
|
|
43121
|
-
|
|
43122
|
-
entries.push({ ...job, command: wrapCommand(job.id, command) });
|
|
43484
|
+
entries.push(wrapped(job, envNames));
|
|
43123
43485
|
await io.write(renderCrontab(entries));
|
|
43486
|
+
}
|
|
43487
|
+
var ENV_NAME_RE2 = /^[A-Z_][A-Z0-9_]{0,127}$/;
|
|
43488
|
+
function splitTrailingEnv(parts) {
|
|
43489
|
+
if (parts.at(-1) === "--env") throw new Error("--env needs a NAME");
|
|
43490
|
+
let end = parts.length;
|
|
43491
|
+
const envNames = [];
|
|
43492
|
+
while (end >= 2 && parts[end - 2] === "--env") {
|
|
43493
|
+
envNames.unshift(parts[end - 1]);
|
|
43494
|
+
end -= 2;
|
|
43495
|
+
}
|
|
43496
|
+
return { command: parts.slice(0, end).join(" "), envNames };
|
|
43497
|
+
}
|
|
43498
|
+
async function addJobWithEnv(io, schedule, command, envNames, deps, name) {
|
|
43499
|
+
for (const n of envNames) if (!ENV_NAME_RE2.test(n)) throw new Error(`invalid env name: ${n}`);
|
|
43500
|
+
await deps.prepare();
|
|
43501
|
+
const job = newJob(schedule, command, name);
|
|
43502
|
+
let step = "syncing the job to the cloud";
|
|
43503
|
+
try {
|
|
43504
|
+
await deps.sync(wrapped(job, envNames));
|
|
43505
|
+
step = "binding env vars";
|
|
43506
|
+
await deps.bind(job.id, envNames);
|
|
43507
|
+
} catch (e) {
|
|
43508
|
+
const why = `${step} failed (${e instanceof Error ? e.message : String(e)})`;
|
|
43509
|
+
try {
|
|
43510
|
+
await deps.sync();
|
|
43511
|
+
} catch {
|
|
43512
|
+
throw new Error(`${why}; the job was not added to the crontab, and its cloud copy clears on the next sync.`);
|
|
43513
|
+
}
|
|
43514
|
+
throw new Error(`${why}; the job was not added. Fix the problem and run the command again.`);
|
|
43515
|
+
}
|
|
43516
|
+
await appendJob(io, job, envNames);
|
|
43124
43517
|
return job;
|
|
43125
43518
|
}
|
|
43126
43519
|
async function withJob(io, id, fn) {
|
|
@@ -43142,6 +43535,236 @@ function setEnabled(io, id, enabled2) {
|
|
|
43142
43535
|
return withJob(io, id, (e) => ({ ...e, enabled: enabled2 }));
|
|
43143
43536
|
}
|
|
43144
43537
|
|
|
43538
|
+
// src/commands/env.ts
|
|
43539
|
+
var NAME_RE = /^[A-Z_][A-Z0-9_]{0,127}$/;
|
|
43540
|
+
var MAX_ROWS = 10;
|
|
43541
|
+
var MAX_NA = 3;
|
|
43542
|
+
var USAGE = "usage: norc env <ls|set NAME|archive NAME [--yes]|restore NAME|rm NAME [--yes]>";
|
|
43543
|
+
function impactText(verb, name, rows) {
|
|
43544
|
+
const machines = new Set(rows.map((r) => r.machine_id)).size;
|
|
43545
|
+
const lines = [
|
|
43546
|
+
`${verb} \`${name}\` will break ${rows.length} job${rows.length === 1 ? "" : "s"} on ${machines} machine${machines === 1 ? "" : "s"}. They will fail on their next run until you restore it or unbind it.`,
|
|
43547
|
+
...rows.slice(0, MAX_ROWS).map((r) => ` ${r.job_name} \xB7 ${r.machine_name}`)
|
|
43548
|
+
];
|
|
43549
|
+
if (rows.length > MAX_ROWS) lines.push(` and ${rows.length - MAX_ROWS} more`);
|
|
43550
|
+
return lines.join("\n");
|
|
43551
|
+
}
|
|
43552
|
+
function notAffectedText(rows) {
|
|
43553
|
+
return [
|
|
43554
|
+
"Not affected \xB7 archived jobs",
|
|
43555
|
+
...rows.slice(0, MAX_NA).map((r) => ` ${r.job_name} \xB7 ${r.machine_name}`),
|
|
43556
|
+
...rows.length > MAX_NA ? [` and ${rows.length - MAX_NA} more`] : []
|
|
43557
|
+
].join("\n");
|
|
43558
|
+
}
|
|
43559
|
+
async function cmdEnv(args, d) {
|
|
43560
|
+
const yes = args.includes("--yes");
|
|
43561
|
+
const [sub, ...rest] = args.filter((a) => a !== "--yes");
|
|
43562
|
+
try {
|
|
43563
|
+
if (sub === "ls" && rest.length === 0) return await ls(d);
|
|
43564
|
+
if (sub && ["set", "archive", "restore", "rm"].includes(sub)) {
|
|
43565
|
+
if (rest.length !== 1) {
|
|
43566
|
+
d.err(sub === "set" && rest.length > 1 ? 'refusing a value on the command line (it lands in shell history). Pipe it in: echo "$VALUE" | norc env set NAME' : USAGE);
|
|
43567
|
+
return 2;
|
|
43568
|
+
}
|
|
43569
|
+
const name = rest[0];
|
|
43570
|
+
if (!NAME_RE.test(name)) {
|
|
43571
|
+
d.err("invalid name: use A-Z, 0-9 and _, not starting with a digit (max 128)");
|
|
43572
|
+
return 2;
|
|
43573
|
+
}
|
|
43574
|
+
if (sub === "set") return await set(name, d);
|
|
43575
|
+
const v = (await d.listVars()).find((x) => x.name === name);
|
|
43576
|
+
if (!v) {
|
|
43577
|
+
d.err(`no environment variable named ${name}`);
|
|
43578
|
+
return 1;
|
|
43579
|
+
}
|
|
43580
|
+
if (sub === "restore") return await act(d, "restore_env_var", v, `restored ${name}`);
|
|
43581
|
+
return await destructive(sub, name, v, yes, d);
|
|
43582
|
+
}
|
|
43583
|
+
d.err(USAGE);
|
|
43584
|
+
return 2;
|
|
43585
|
+
} catch (e) {
|
|
43586
|
+
d.err(e instanceof Error ? e.message : String(e));
|
|
43587
|
+
return 1;
|
|
43588
|
+
}
|
|
43589
|
+
}
|
|
43590
|
+
async function ls(d) {
|
|
43591
|
+
const [vars, bound] = await Promise.all([d.listVars(), d.bindingNames()]);
|
|
43592
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
43593
|
+
for (const n of bound) counts2.set(n, (counts2.get(n) ?? 0) + 1);
|
|
43594
|
+
if (vars.length === 0) d.out("no environment variables.");
|
|
43595
|
+
for (const v of [...vars].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
43596
|
+
d.out(`${v.name} ${v.archived ? "archived" : "active "} ${counts2.get(v.name) ?? 0} jobs`);
|
|
43597
|
+
}
|
|
43598
|
+
const plan = await d.plan?.().catch(() => null);
|
|
43599
|
+
if (plan) {
|
|
43600
|
+
d.err(`${envVarUsageLabel(plan, vars.length)} (${plan.charAt(0).toUpperCase() + plan.slice(1)} plan)`);
|
|
43601
|
+
const full = envVarLimitMessage(plan, vars.length);
|
|
43602
|
+
if (full) d.err(full);
|
|
43603
|
+
}
|
|
43604
|
+
return 0;
|
|
43605
|
+
}
|
|
43606
|
+
async function set(name, d) {
|
|
43607
|
+
const existing = (await d.listVars()).find((x) => x.name === name);
|
|
43608
|
+
if (existing?.archived) {
|
|
43609
|
+
d.err(`${name} is archived; restore it first (norc env restore ${name})`);
|
|
43610
|
+
return 1;
|
|
43611
|
+
}
|
|
43612
|
+
const value = await d.readSecret(`value for ${name} (hidden): `);
|
|
43613
|
+
if (!value) {
|
|
43614
|
+
d.err("empty value, nothing saved");
|
|
43615
|
+
return 1;
|
|
43616
|
+
}
|
|
43617
|
+
if (value.includes("\0")) {
|
|
43618
|
+
d.err("value contains a NUL byte, which a command cannot receive; nothing saved");
|
|
43619
|
+
return 1;
|
|
43620
|
+
}
|
|
43621
|
+
const res = existing ? await d.write({ action: "set_value", id: existing.id, value }) : await d.write({ action: "create", name, value });
|
|
43622
|
+
if (res.status >= 200 && res.status < 300) {
|
|
43623
|
+
d.out(`${existing ? "updated" : "created"} ${name}`);
|
|
43624
|
+
return 0;
|
|
43625
|
+
}
|
|
43626
|
+
if (res.status === 403 && res.body.error === "plan_limit_reached") d.err("plan limit reached: archive or delete a variable, or upgrade your plan");
|
|
43627
|
+
else if (res.status === 409) d.err(`${name} already exists`);
|
|
43628
|
+
else d.err(`could not save ${name} (${res.body.error ?? `HTTP ${res.status}`})`);
|
|
43629
|
+
return 1;
|
|
43630
|
+
}
|
|
43631
|
+
async function act(d, fn, v, done) {
|
|
43632
|
+
const e = await d.rpc(fn, v.id);
|
|
43633
|
+
if (e) {
|
|
43634
|
+
d.err(e);
|
|
43635
|
+
return 1;
|
|
43636
|
+
}
|
|
43637
|
+
d.out(done);
|
|
43638
|
+
return 0;
|
|
43639
|
+
}
|
|
43640
|
+
async function destructive(sub, name, v, yes, d) {
|
|
43641
|
+
const rm5 = sub === "rm";
|
|
43642
|
+
const all = await d.impact(name);
|
|
43643
|
+
const rows = all.filter((r) => !r.job_archived);
|
|
43644
|
+
const na = all.filter((r) => r.job_archived);
|
|
43645
|
+
if (rows.length > 0) d.out(impactText(rm5 ? "Deleting" : "Archiving", name, rows));
|
|
43646
|
+
if (na.length > 0) d.out(notAffectedText(na));
|
|
43647
|
+
if (!yes) {
|
|
43648
|
+
if (!d.isTTY) {
|
|
43649
|
+
if (rm5 || rows.length > 0) {
|
|
43650
|
+
d.err("refusing without --yes on a non-interactive terminal");
|
|
43651
|
+
return 1;
|
|
43652
|
+
}
|
|
43653
|
+
} else if (rm5) {
|
|
43654
|
+
const answer = await d.readLine(`type ${name} to delete it permanently: `);
|
|
43655
|
+
if (answer === null || answer.trim() !== name) {
|
|
43656
|
+
d.err("cancelled");
|
|
43657
|
+
return 1;
|
|
43658
|
+
}
|
|
43659
|
+
} else {
|
|
43660
|
+
const answer = await d.readLine(`archive ${name}? [y/N] `);
|
|
43661
|
+
if (answer === null || !/^y(es)?$/i.test(answer.trim())) {
|
|
43662
|
+
d.err("cancelled");
|
|
43663
|
+
return 1;
|
|
43664
|
+
}
|
|
43665
|
+
}
|
|
43666
|
+
}
|
|
43667
|
+
if (!rm5) return act(d, "archive_env_var", v, `archived ${name}`);
|
|
43668
|
+
return remove2(name, v, d);
|
|
43669
|
+
}
|
|
43670
|
+
async function remove2(name, v, d) {
|
|
43671
|
+
const fallback = `Deleting a variable needs a fresh sign-in. Delete it in the web vault (Environment), or archive it with \`norc env archive ${name}\`.`;
|
|
43672
|
+
let e = await d.deleteVar(v.id);
|
|
43673
|
+
const method = e && stepUpMethodOf(e);
|
|
43674
|
+
if (e && method) {
|
|
43675
|
+
if (!d.isTTY || !await stepUp(method, d)) {
|
|
43676
|
+
d.err(fallback);
|
|
43677
|
+
return 1;
|
|
43678
|
+
}
|
|
43679
|
+
e = await d.deleteVar(v.id);
|
|
43680
|
+
if (e && stepUpMethodOf(e)) {
|
|
43681
|
+
d.err(fallback);
|
|
43682
|
+
return 1;
|
|
43683
|
+
}
|
|
43684
|
+
}
|
|
43685
|
+
if (e) {
|
|
43686
|
+
d.err(e.message);
|
|
43687
|
+
return 1;
|
|
43688
|
+
}
|
|
43689
|
+
d.out(`deleted ${name}`);
|
|
43690
|
+
return 0;
|
|
43691
|
+
}
|
|
43692
|
+
async function stepUp(method, d) {
|
|
43693
|
+
const ask = (q) => d.readSecret(q).then((c) => c.trim(), () => "");
|
|
43694
|
+
if (method === "totp") {
|
|
43695
|
+
const code = await ask("6-digit code from your authenticator app (hidden): ");
|
|
43696
|
+
if (!code) return false;
|
|
43697
|
+
const e2 = await d.verifyTotp(code);
|
|
43698
|
+
if (e2) d.err(e2);
|
|
43699
|
+
return !e2;
|
|
43700
|
+
}
|
|
43701
|
+
const started = await d.reauth({ action: "start" });
|
|
43702
|
+
if (started) {
|
|
43703
|
+
d.err(started);
|
|
43704
|
+
return false;
|
|
43705
|
+
}
|
|
43706
|
+
d.out("To confirm it is you, we emailed a one-time code to your account address.");
|
|
43707
|
+
const token = await ask("code from your email (hidden): ");
|
|
43708
|
+
if (!token) return false;
|
|
43709
|
+
const e = await d.reauth({ action: "verify", method: "email_otp", token });
|
|
43710
|
+
if (e) d.err(e);
|
|
43711
|
+
return !e;
|
|
43712
|
+
}
|
|
43713
|
+
|
|
43714
|
+
// src/commands/env-auth.ts
|
|
43715
|
+
function makeStepUpDeps(sb, fetchImpl, url, anon, saveSession2) {
|
|
43716
|
+
return {
|
|
43717
|
+
verifyTotp: async (code) => {
|
|
43718
|
+
const { data, error } = await sb.auth.mfa.listFactors();
|
|
43719
|
+
const factor = data?.totp[0];
|
|
43720
|
+
if (error || !factor) return "Could not start the 2FA check.";
|
|
43721
|
+
const { error: e } = await sb.auth.mfa.challengeAndVerify({ factorId: factor.id, code });
|
|
43722
|
+
if (e) return "That code did not work.";
|
|
43723
|
+
try {
|
|
43724
|
+
await saveSession2();
|
|
43725
|
+
} catch {
|
|
43726
|
+
return "Could not save the new sign-in on this machine.";
|
|
43727
|
+
}
|
|
43728
|
+
return null;
|
|
43729
|
+
},
|
|
43730
|
+
reauth: async (body) => {
|
|
43731
|
+
const { data: { session } } = await sb.auth.getSession();
|
|
43732
|
+
try {
|
|
43733
|
+
const res = await fetchImpl(`${url}/functions/v1/reauth`, {
|
|
43734
|
+
method: "POST",
|
|
43735
|
+
headers: { "Content-Type": "application/json", apikey: anon, Authorization: `Bearer ${session?.access_token ?? ""}` },
|
|
43736
|
+
body: JSON.stringify(body)
|
|
43737
|
+
});
|
|
43738
|
+
if (res.ok) return null;
|
|
43739
|
+
if (res.status === 429) return "Too many attempts. Wait a minute and try again.";
|
|
43740
|
+
return res.status >= 400 && res.status < 500 ? "That did not work." : "Could not confirm right now.";
|
|
43741
|
+
} catch {
|
|
43742
|
+
return "Could not reach norc. Check your connection.";
|
|
43743
|
+
}
|
|
43744
|
+
}
|
|
43745
|
+
};
|
|
43746
|
+
}
|
|
43747
|
+
|
|
43748
|
+
// src/commands/read-value.ts
|
|
43749
|
+
async function readStdinValue(stdin) {
|
|
43750
|
+
const chunks = [];
|
|
43751
|
+
for await (const c of stdin) chunks.push(typeof c === "string" ? Buffer.from(c) : c);
|
|
43752
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
43753
|
+
}
|
|
43754
|
+
|
|
43755
|
+
// src/machines.ts
|
|
43756
|
+
async function syncJobs(sb, entries) {
|
|
43757
|
+
const jobs = jobsOf(entries).filter((j) => typeof j.id === "string").map((j) => ({
|
|
43758
|
+
id: j.id,
|
|
43759
|
+
name: j.name ?? "",
|
|
43760
|
+
schedule: j.schedule,
|
|
43761
|
+
command: j.command,
|
|
43762
|
+
enabled: j.enabled ?? true
|
|
43763
|
+
}));
|
|
43764
|
+
const { error } = await sb.rpc("sync_account_jobs", { p_jobs: jobs, p_authoritative_empty: true });
|
|
43765
|
+
if (error) throw new Error(error.message);
|
|
43766
|
+
}
|
|
43767
|
+
|
|
43145
43768
|
// src/commands/gitops.ts
|
|
43146
43769
|
var import_yaml = __toESM(require_dist());
|
|
43147
43770
|
var CONTROL4 = /[\r\n\0]/;
|
|
@@ -43271,10 +43894,10 @@ async function getJson(fetchImpl, url, apiKey) {
|
|
|
43271
43894
|
if (!Array.isArray(body)) return { ok: false, message: "malformed response from vault API" };
|
|
43272
43895
|
return { ok: true, data: body };
|
|
43273
43896
|
}
|
|
43274
|
-
async function fetchLiveJobs(fetchImpl,
|
|
43275
|
-
const machinesResult = await getJson(fetchImpl, `${
|
|
43897
|
+
async function fetchLiveJobs(fetchImpl, vaultUrl2, apiKey) {
|
|
43898
|
+
const machinesResult = await getJson(fetchImpl, `${vaultUrl2}/api/v1/machines`, apiKey);
|
|
43276
43899
|
if (!machinesResult.ok) return machinesResult;
|
|
43277
|
-
const jobsResult = await getJson(fetchImpl, `${
|
|
43900
|
+
const jobsResult = await getJson(fetchImpl, `${vaultUrl2}/api/v1/jobs`, apiKey);
|
|
43278
43901
|
if (!jobsResult.ok) return jobsResult;
|
|
43279
43902
|
const machineNameById = new Map(machinesResult.data.map((m) => [m.id, m.name]));
|
|
43280
43903
|
const jobs = [];
|
|
@@ -43285,7 +43908,7 @@ async function fetchLiveJobs(fetchImpl, vaultUrl, apiKey) {
|
|
|
43285
43908
|
}
|
|
43286
43909
|
return { ok: true, jobs, machines: machinesResult.data };
|
|
43287
43910
|
}
|
|
43288
|
-
async function applySync(fetchImpl,
|
|
43911
|
+
async function applySync(fetchImpl, vaultUrl2, apiKey, diff, machineNameToId) {
|
|
43289
43912
|
const creates = diff.creates.map((c) => ({
|
|
43290
43913
|
key: `${c.machineName}/${c.jobName}`,
|
|
43291
43914
|
machineId: machineNameToId.get(c.machineName),
|
|
@@ -43300,7 +43923,7 @@ async function applySync(fetchImpl, vaultUrl, apiKey, diff, machineNameToId) {
|
|
|
43300
43923
|
patch: { schedule: u.desired.schedule, command: u.desired.command, enabled: u.desired.enabled }
|
|
43301
43924
|
}));
|
|
43302
43925
|
const deletes = diff.deletes.map((d) => ({ key: `${d.machineName}/${d.jobName}`, id: d.id }));
|
|
43303
|
-
const url = `${
|
|
43926
|
+
const url = `${vaultUrl2}/api/v1/jobs/sync`;
|
|
43304
43927
|
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, creates: creates.length, updates: updates.length, deletes: deletes.length });
|
|
43305
43928
|
let res;
|
|
43306
43929
|
try {
|
|
@@ -43330,6 +43953,8 @@ async function applySync(fetchImpl, vaultUrl, apiKey, diff, machineNameToId) {
|
|
|
43330
43953
|
}
|
|
43331
43954
|
|
|
43332
43955
|
// src/commands/gitops-cmd.ts
|
|
43956
|
+
var MORE_HINT = "Need more? Email hello@norc.app";
|
|
43957
|
+
var isJobLimit = (m) => /job limit/i.test(m ?? "");
|
|
43333
43958
|
async function cmdGitops(args, deps, log = console.log) {
|
|
43334
43959
|
const [sub, ...rest] = args;
|
|
43335
43960
|
if (sub !== "plan" && sub !== "apply") {
|
|
@@ -43366,7 +43991,7 @@ async function cmdGitops(args, deps, log = console.log) {
|
|
|
43366
43991
|
}
|
|
43367
43992
|
const machineNameCounts = /* @__PURE__ */ new Map();
|
|
43368
43993
|
for (const m of liveResult.machines) machineNameCounts.set(m.name, (machineNameCounts.get(m.name) ?? 0) + 1);
|
|
43369
|
-
const dupMachines = [...machineNameCounts.entries()].filter(([,
|
|
43994
|
+
const dupMachines = [...machineNameCounts.entries()].filter(([, count2]) => count2 > 1).map(([name]) => name);
|
|
43370
43995
|
if (dupMachines.length > 0) {
|
|
43371
43996
|
for (const name of dupMachines) log(`error: duplicate machine name "${name}" \u2014 norc gitops requires unique machine names per account`);
|
|
43372
43997
|
return 2;
|
|
@@ -43378,7 +44003,7 @@ async function cmdGitops(args, deps, log = console.log) {
|
|
|
43378
44003
|
jobKeyCounts.set(key, [j.machineName, j.jobName]);
|
|
43379
44004
|
jobKeyDupCount.set(key, (jobKeyDupCount.get(key) ?? 0) + 1);
|
|
43380
44005
|
}
|
|
43381
|
-
const dupJobs = [...jobKeyDupCount.entries()].filter(([,
|
|
44006
|
+
const dupJobs = [...jobKeyDupCount.entries()].filter(([, count2]) => count2 > 1).map(([key]) => jobKeyCounts.get(key));
|
|
43382
44007
|
if (dupJobs.length > 0) {
|
|
43383
44008
|
for (const [machineName, jobName] of dupJobs) log(`error: duplicate job "${machineName}/${jobName}" \u2014 norc gitops requires unique job names per machine`);
|
|
43384
44009
|
return 2;
|
|
@@ -43398,11 +44023,13 @@ async function cmdGitops(args, deps, log = console.log) {
|
|
|
43398
44023
|
const applyResult = await applySync(deps.fetchImpl, deps.vaultUrl, deps.apiKey, diff, machineNameToId);
|
|
43399
44024
|
if (!applyResult.ok) {
|
|
43400
44025
|
log(`error: ${applyResult.message}`);
|
|
44026
|
+
if (isJobLimit(applyResult.message)) log(MORE_HINT);
|
|
43401
44027
|
return 2;
|
|
43402
44028
|
}
|
|
43403
44029
|
for (const r of applyResult.results) {
|
|
43404
44030
|
log(r.ok ? `${r.op} ${r.key}: ok` : `${r.op} ${r.key}: FAILED \u2014 ${r.error}`);
|
|
43405
44031
|
}
|
|
44032
|
+
if (applyResult.results.some((r) => !r.ok && isJobLimit(r.error))) log(MORE_HINT);
|
|
43406
44033
|
return applyResult.results.some((r) => !r.ok) ? 1 : 0;
|
|
43407
44034
|
}
|
|
43408
44035
|
|
|
@@ -43412,22 +44039,22 @@ function tailRunsMessage() {
|
|
|
43412
44039
|
}
|
|
43413
44040
|
|
|
43414
44041
|
// src/child-env.ts
|
|
43415
|
-
function withoutPkgEnv(command,
|
|
43416
|
-
return
|
|
44042
|
+
function withoutPkgEnv(command, platform2 = process.platform) {
|
|
44043
|
+
return platform2 === "win32" ? `set "PKG_EXECPATH=" && ${command}` : `unset PKG_EXECPATH; ${command}`;
|
|
43417
44044
|
}
|
|
43418
44045
|
|
|
43419
44046
|
// src/commands/run.ts
|
|
43420
|
-
var
|
|
44047
|
+
var import_node_child_process4 = require("node:child_process");
|
|
43421
44048
|
|
|
43422
44049
|
// src/host-details.ts
|
|
43423
|
-
var
|
|
44050
|
+
var import_node_child_process3 = require("node:child_process");
|
|
43424
44051
|
var import_node_fs = require("node:fs");
|
|
43425
44052
|
var import_node_crypto2 = require("node:crypto");
|
|
43426
|
-
var
|
|
44053
|
+
var import_node_os4 = require("node:os");
|
|
43427
44054
|
var import_node_path2 = require("node:path");
|
|
43428
44055
|
|
|
43429
44056
|
// src/version.ts
|
|
43430
|
-
var VERSION2 = "0.
|
|
44057
|
+
var VERSION2 = "0.3.1";
|
|
43431
44058
|
|
|
43432
44059
|
// src/host-details.ts
|
|
43433
44060
|
var ARCH = { x64: "x86_64", arm64: "arm64", ia32: "x86", arm: "arm" };
|
|
@@ -43446,21 +44073,21 @@ function windowsOsName(kernel, isClient) {
|
|
|
43446
44073
|
}
|
|
43447
44074
|
function windowsIsClient() {
|
|
43448
44075
|
try {
|
|
43449
|
-
const out = (0,
|
|
44076
|
+
const out = (0, import_node_child_process3.execFileSync)("powershell.exe", ["-NoProfile", "-Command", "(Get-CimInstance Win32_OperatingSystem).ProductType"], { encoding: "utf8", timeout: 4e3 }).trim();
|
|
43450
44077
|
return out === "1" ? true : out === "2" || out === "3" ? false : void 0;
|
|
43451
44078
|
} catch {
|
|
43452
44079
|
return void 0;
|
|
43453
44080
|
}
|
|
43454
44081
|
}
|
|
43455
|
-
function osName(
|
|
43456
|
-
if (
|
|
43457
|
-
const file = (0, import_node_path2.join)((0,
|
|
44082
|
+
function osName(platform2) {
|
|
44083
|
+
if (platform2 === "linux") return osNameUncached(platform2);
|
|
44084
|
+
const file = (0, import_node_path2.join)((0, import_node_os4.homedir)(), ".config", "norc", `os-${platform2}-${(0, import_node_crypto2.createHash)("sha1").update(`${(0, import_node_os4.release)()}|${(0, import_node_os4.version)()}`).digest("hex").slice(0, 12)}.txt`);
|
|
43458
44085
|
try {
|
|
43459
44086
|
const hit = (0, import_node_fs.readFileSync)(file, "utf8").trim();
|
|
43460
44087
|
if (/^[\w .()+-]{1,64}$/.test(hit)) return hit;
|
|
43461
44088
|
} catch {
|
|
43462
44089
|
}
|
|
43463
|
-
const name = osNameUncached(
|
|
44090
|
+
const name = osNameUncached(platform2);
|
|
43464
44091
|
if (name) {
|
|
43465
44092
|
try {
|
|
43466
44093
|
(0, import_node_fs.writeFileSync)(file, name);
|
|
@@ -43469,18 +44096,18 @@ function osName(platform) {
|
|
|
43469
44096
|
}
|
|
43470
44097
|
return name;
|
|
43471
44098
|
}
|
|
43472
|
-
function osNameUncached(
|
|
44099
|
+
function osNameUncached(platform2) {
|
|
43473
44100
|
try {
|
|
43474
|
-
if (
|
|
43475
|
-
if (
|
|
43476
|
-
if (
|
|
44101
|
+
if (platform2 === "linux") return linuxOsName((0, import_node_fs.readFileSync)("/etc/os-release", "utf8"));
|
|
44102
|
+
if (platform2 === "darwin") return `macOS ${(0, import_node_child_process3.execFileSync)("sw_vers", ["-productVersion"], { encoding: "utf8", timeout: 2e3 }).trim()}`;
|
|
44103
|
+
if (platform2 === "win32") return windowsOsName((0, import_node_os4.release)(), windowsIsClient());
|
|
43477
44104
|
} catch {
|
|
43478
44105
|
}
|
|
43479
44106
|
return void 0;
|
|
43480
44107
|
}
|
|
43481
44108
|
function bootedAt() {
|
|
43482
44109
|
try {
|
|
43483
|
-
return new Date(Math.round((Date.now() - (0,
|
|
44110
|
+
return new Date(Math.round((Date.now() - (0, import_node_os4.uptime)() * 1e3) / 6e4) * 6e4).toISOString();
|
|
43484
44111
|
} catch {
|
|
43485
44112
|
return void 0;
|
|
43486
44113
|
}
|
|
@@ -43491,8 +44118,95 @@ function hostDetails() {
|
|
|
43491
44118
|
return cached;
|
|
43492
44119
|
}
|
|
43493
44120
|
|
|
44121
|
+
// src/env-cache.ts
|
|
44122
|
+
var import_promises2 = require("node:fs/promises");
|
|
44123
|
+
var import_node_path3 = require("node:path");
|
|
44124
|
+
function envCachePath() {
|
|
44125
|
+
return (0, import_node_path3.join)((0, import_node_path3.dirname)(configPath()), "env");
|
|
44126
|
+
}
|
|
44127
|
+
async function tempLeftovers(path) {
|
|
44128
|
+
const re = new RegExp(`^${(0, import_node_path3.basename)(path).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.\\d+\\.\\d+\\.tmp$`);
|
|
44129
|
+
return (await (0, import_promises2.readdir)((0, import_node_path3.dirname)(path)).catch(() => [])).filter((n) => re.test(n)).map((n) => (0, import_node_path3.join)((0, import_node_path3.dirname)(path), n));
|
|
44130
|
+
}
|
|
44131
|
+
async function writeEnvCache(body, path = envCachePath()) {
|
|
44132
|
+
const dir = (0, import_node_path3.dirname)(path);
|
|
44133
|
+
await (0, import_promises2.mkdir)(dir, { recursive: true, mode: 448 });
|
|
44134
|
+
await (0, import_promises2.chmod)(dir, 448);
|
|
44135
|
+
await restrictWindowsAcl(dir, path);
|
|
44136
|
+
for (const f of await tempLeftovers(path)) {
|
|
44137
|
+
const st = await (0, import_promises2.stat)(f).catch(() => null);
|
|
44138
|
+
if (st && Date.now() - st.mtimeMs > 6e4) await (0, import_promises2.rm)(f, { force: true }).catch(() => {
|
|
44139
|
+
});
|
|
44140
|
+
}
|
|
44141
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
44142
|
+
try {
|
|
44143
|
+
await (0, import_promises2.writeFile)(tmp, JSON.stringify(body), { mode: 384 });
|
|
44144
|
+
await (0, import_promises2.chmod)(tmp, 384);
|
|
44145
|
+
await (0, import_promises2.rename)(tmp, path);
|
|
44146
|
+
} catch (e) {
|
|
44147
|
+
await (0, import_promises2.rm)(tmp, { force: true }).catch(() => {
|
|
44148
|
+
});
|
|
44149
|
+
throw e;
|
|
44150
|
+
}
|
|
44151
|
+
await (0, import_promises2.chmod)(path, 384);
|
|
44152
|
+
await restrictWindowsAcl(dir, path);
|
|
44153
|
+
}
|
|
44154
|
+
async function clearEnvCache(path = envCachePath()) {
|
|
44155
|
+
try {
|
|
44156
|
+
await (0, import_promises2.rm)(path, { force: true });
|
|
44157
|
+
let ok = true;
|
|
44158
|
+
for (const f of await tempLeftovers(path)) await (0, import_promises2.rm)(f, { force: true }).catch(() => {
|
|
44159
|
+
ok = false;
|
|
44160
|
+
});
|
|
44161
|
+
return ok;
|
|
44162
|
+
} catch {
|
|
44163
|
+
return false;
|
|
44164
|
+
}
|
|
44165
|
+
}
|
|
44166
|
+
var isObj = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
44167
|
+
function parseEnvSyncBody(x) {
|
|
44168
|
+
if (!isObj(x) || !isObj(x.jobs) || !isObj(x.vars)) return null;
|
|
44169
|
+
for (const names of Object.values(x.jobs)) {
|
|
44170
|
+
if (!Array.isArray(names) || !names.every((n) => typeof n === "string")) return null;
|
|
44171
|
+
}
|
|
44172
|
+
for (const v of Object.values(x.vars)) {
|
|
44173
|
+
if (!isObj(v)) return null;
|
|
44174
|
+
if (v.state === "active") {
|
|
44175
|
+
if (typeof v.value !== "string") return null;
|
|
44176
|
+
} else if (v.state !== "archived" && v.state !== "missing" || "value" in v) return null;
|
|
44177
|
+
}
|
|
44178
|
+
const body = x;
|
|
44179
|
+
return {
|
|
44180
|
+
jobs: Object.fromEntries(Object.entries(body.jobs).map(([id, names]) => [id, names.filter((n) => ENV_NAME_RE.test(n))])),
|
|
44181
|
+
vars: Object.fromEntries(Object.entries(body.vars).filter(([n]) => ENV_NAME_RE.test(n)))
|
|
44182
|
+
};
|
|
44183
|
+
}
|
|
44184
|
+
async function readEnvCache(path = envCachePath()) {
|
|
44185
|
+
try {
|
|
44186
|
+
return parseEnvSyncBody(JSON.parse(await (0, import_promises2.readFile)(path, "utf8")));
|
|
44187
|
+
} catch {
|
|
44188
|
+
return null;
|
|
44189
|
+
}
|
|
44190
|
+
}
|
|
44191
|
+
function resolveJobEnv(body, jobId, required) {
|
|
44192
|
+
const names = [.../* @__PURE__ */ new Set([...required ?? [], ...body?.jobs[jobId] ?? []])].sort();
|
|
44193
|
+
if (names.length === 0) return { ok: true, env: {} };
|
|
44194
|
+
const env = {};
|
|
44195
|
+
for (const name of names) {
|
|
44196
|
+
const v = body?.vars[name];
|
|
44197
|
+
if (v?.state === "active" && v.value.includes("\0")) return { ok: false, message: `env ${name} has an invalid value` };
|
|
44198
|
+
if (v?.state === "active") env[name] = v.value;
|
|
44199
|
+
else if (v?.state === "archived") return { ok: false, message: `env ${name} is archived` };
|
|
44200
|
+
else if (!v && required?.includes(name)) return { ok: false, message: `env ${name} is unavailable (norc could not sync)` };
|
|
44201
|
+
else return { ok: false, message: `env ${name} not found` };
|
|
44202
|
+
}
|
|
44203
|
+
return { ok: true, env };
|
|
44204
|
+
}
|
|
44205
|
+
|
|
43494
44206
|
// src/device-session.ts
|
|
43495
|
-
|
|
44207
|
+
var revoked = null;
|
|
44208
|
+
var revokedMint = () => revoked;
|
|
44209
|
+
async function deviceSession(supabaseUrl2, anonKey, signal, encPublicJwk, cachePath = envCachePath()) {
|
|
43496
44210
|
const config = await loadConfig();
|
|
43497
44211
|
const token = config.device?.deviceToken;
|
|
43498
44212
|
if (!token) return null;
|
|
@@ -43513,8 +44227,16 @@ async function deviceSession(supabaseUrl2, anonKey, signal, encPublicJwk) {
|
|
|
43513
44227
|
}),
|
|
43514
44228
|
signal
|
|
43515
44229
|
});
|
|
44230
|
+
if (res.status === 401 && (await res.json?.().catch(() => null))?.error === "invalid device token") {
|
|
44231
|
+
const before = await readEnvCache(cachePath);
|
|
44232
|
+
revoked = { body: before ?? revoked?.body ?? null };
|
|
44233
|
+
await clearEnvCache(cachePath);
|
|
44234
|
+
return null;
|
|
44235
|
+
}
|
|
43516
44236
|
if (!res.ok) return null;
|
|
43517
|
-
|
|
44237
|
+
const session = await res.json();
|
|
44238
|
+
revoked = null;
|
|
44239
|
+
return session;
|
|
43518
44240
|
} catch (e) {
|
|
43519
44241
|
console.error("[norc bridge] device-session fetch failed:", e);
|
|
43520
44242
|
return null;
|
|
@@ -43522,17 +44244,17 @@ async function deviceSession(supabaseUrl2, anonKey, signal, encPublicJwk) {
|
|
|
43522
44244
|
}
|
|
43523
44245
|
|
|
43524
44246
|
// src/run-queue.ts
|
|
43525
|
-
var
|
|
43526
|
-
var
|
|
43527
|
-
var
|
|
44247
|
+
var import_promises3 = require("node:fs/promises");
|
|
44248
|
+
var import_node_os5 = require("node:os");
|
|
44249
|
+
var import_node_path4 = require("node:path");
|
|
43528
44250
|
var MAX_QUEUE_LENGTH = 500;
|
|
43529
44251
|
function runQueuePath() {
|
|
43530
|
-
return (0,
|
|
44252
|
+
return (0, import_node_path4.join)((0, import_node_os5.homedir)(), ".config", "norc", "run-queue.jsonl");
|
|
43531
44253
|
}
|
|
43532
44254
|
async function readQueue(path = runQueuePath()) {
|
|
43533
44255
|
let text;
|
|
43534
44256
|
try {
|
|
43535
|
-
text = await (0,
|
|
44257
|
+
text = await (0, import_promises3.readFile)(path, "utf8");
|
|
43536
44258
|
} catch {
|
|
43537
44259
|
return [];
|
|
43538
44260
|
}
|
|
@@ -43540,26 +44262,26 @@ async function readQueue(path = runQueuePath()) {
|
|
|
43540
44262
|
}
|
|
43541
44263
|
async function writeQueue(entries, path) {
|
|
43542
44264
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
43543
|
-
await (0,
|
|
43544
|
-
await (0,
|
|
44265
|
+
await (0, import_promises3.writeFile)(tmp, entries.map((e) => JSON.stringify(e)).join("\n") + (entries.length ? "\n" : ""), "utf8");
|
|
44266
|
+
await (0, import_promises3.rename)(tmp, path);
|
|
43545
44267
|
}
|
|
43546
|
-
var
|
|
44268
|
+
var LOCK_STALE_MS2 = 3e4;
|
|
43547
44269
|
var LOCK_RETRY_MS = 25;
|
|
43548
44270
|
var LOCK_ATTEMPTS = 40;
|
|
43549
44271
|
async function withLock(path, fn) {
|
|
43550
44272
|
const lockPath = `${path}.lock`;
|
|
43551
|
-
await (0,
|
|
44273
|
+
await (0, import_promises3.mkdir)((0, import_node_path4.dirname)(path), { recursive: true });
|
|
43552
44274
|
let held = false;
|
|
43553
44275
|
for (let i = 0; i < LOCK_ATTEMPTS; i++) {
|
|
43554
44276
|
try {
|
|
43555
|
-
const fh = await (0,
|
|
44277
|
+
const fh = await (0, import_promises3.open)(lockPath, "wx");
|
|
43556
44278
|
await fh.close();
|
|
43557
44279
|
held = true;
|
|
43558
44280
|
break;
|
|
43559
44281
|
} catch {
|
|
43560
44282
|
try {
|
|
43561
|
-
const { mtimeMs } = await (0,
|
|
43562
|
-
if (Date.now() - mtimeMs >
|
|
44283
|
+
const { mtimeMs } = await (0, import_promises3.stat)(lockPath);
|
|
44284
|
+
if (Date.now() - mtimeMs > LOCK_STALE_MS2) await (0, import_promises3.rm)(lockPath, { force: true });
|
|
43563
44285
|
} catch {
|
|
43564
44286
|
}
|
|
43565
44287
|
await new Promise((r) => setTimeout(r, LOCK_RETRY_MS));
|
|
@@ -43569,7 +44291,7 @@ async function withLock(path, fn) {
|
|
|
43569
44291
|
try {
|
|
43570
44292
|
return await fn();
|
|
43571
44293
|
} finally {
|
|
43572
|
-
await (0,
|
|
44294
|
+
await (0, import_promises3.rm)(lockPath, { force: true }).catch(() => {
|
|
43573
44295
|
});
|
|
43574
44296
|
}
|
|
43575
44297
|
}
|
|
@@ -43599,10 +44321,50 @@ async function clearQueue(toRemove, path = runQueuePath()) {
|
|
|
43599
44321
|
});
|
|
43600
44322
|
}
|
|
43601
44323
|
|
|
44324
|
+
// src/commands/env-sync.ts
|
|
44325
|
+
async function pullEnv(fetchFn, session, timeoutMs, path, clear) {
|
|
44326
|
+
if (!session) return { body: null, written: false };
|
|
44327
|
+
try {
|
|
44328
|
+
const res = await fetchFn(`${supabaseUrl()}/functions/v1/device-env-sync`, {
|
|
44329
|
+
method: "POST",
|
|
44330
|
+
headers: { apikey: process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY, Authorization: `Bearer ${session.token}` },
|
|
44331
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
44332
|
+
});
|
|
44333
|
+
if (res.status === 403) {
|
|
44334
|
+
const denied = await readEnvCache(path);
|
|
44335
|
+
await clear(path);
|
|
44336
|
+
return { body: null, written: false, denied };
|
|
44337
|
+
}
|
|
44338
|
+
if (!res.ok) return { body: null, written: false };
|
|
44339
|
+
const body = parseEnvSyncBody(await res.json());
|
|
44340
|
+
if (!body) return { body: null, written: false };
|
|
44341
|
+
const written = await writeEnvCache(body, path).then(() => true, () => false);
|
|
44342
|
+
return { body, written };
|
|
44343
|
+
} catch {
|
|
44344
|
+
return { body: null, written: false };
|
|
44345
|
+
}
|
|
44346
|
+
}
|
|
44347
|
+
async function pullEnvNames(fetchFn, session, timeoutMs, path = envCachePath()) {
|
|
44348
|
+
return (await pullEnv(fetchFn, session, timeoutMs, path, clearEnvCache)).body?.jobs ?? null;
|
|
44349
|
+
}
|
|
44350
|
+
var REFRESH_BUDGET_MS = 3e3;
|
|
44351
|
+
function createJobEnvLoader(getSession, path = envCachePath(), fetchFn = fetch, clear = clearEnvCache) {
|
|
44352
|
+
return async (jobId, envNames) => {
|
|
44353
|
+
const session = await getSession().catch(() => null);
|
|
44354
|
+
const pulled = await pullEnv(fetchFn, session, REFRESH_BUDGET_MS, path, clear);
|
|
44355
|
+
const { body } = pulled;
|
|
44356
|
+
const denied = pulled.denied !== void 0 ? pulled.denied : !session ? revokedMint()?.body : void 0;
|
|
44357
|
+
if (denied !== void 0 && ((denied?.jobs[jobId]?.length ?? 0) > 0 || (envNames?.length ?? 0) > 0)) return { ok: false, message: "this machine is no longer authorized to read env vars" };
|
|
44358
|
+
if (denied !== void 0) return { ok: true, env: {} };
|
|
44359
|
+
if (body) return resolveJobEnv(body, jobId);
|
|
44360
|
+
return resolveJobEnv(await readEnvCache(path), jobId, envNames);
|
|
44361
|
+
};
|
|
44362
|
+
}
|
|
44363
|
+
|
|
43602
44364
|
// src/commands/run.ts
|
|
43603
44365
|
var FLUSH_BATCH = 25;
|
|
43604
44366
|
var FLUSH_BUDGET_MS = 2e4;
|
|
43605
|
-
async function runWrapped(deps, jobId, command) {
|
|
44367
|
+
async function runWrapped(deps, jobId, command, envNames) {
|
|
43606
44368
|
try {
|
|
43607
44369
|
const queued = (await deps.readQueue()).slice(0, FLUSH_BATCH);
|
|
43608
44370
|
const flushed = [];
|
|
@@ -43614,6 +44376,25 @@ async function runWrapped(deps, jobId, command) {
|
|
|
43614
44376
|
if (flushed.length) await deps.clearQueue(flushed);
|
|
43615
44377
|
} catch {
|
|
43616
44378
|
}
|
|
44379
|
+
let jobEnv;
|
|
44380
|
+
try {
|
|
44381
|
+
jobEnv = await deps.loadJobEnv(jobId, envNames);
|
|
44382
|
+
} catch {
|
|
44383
|
+
jobEnv = { ok: false, message: "env could not be loaded" };
|
|
44384
|
+
}
|
|
44385
|
+
if (!jobEnv.ok) {
|
|
44386
|
+
const at = deps.now().toISOString();
|
|
44387
|
+
const failed = { jobId, exitCode: 1, startedAt: at, finishedAt: at, status: "failed", errorSnippet: jobEnv.message, outputSnippet: jobEnv.message };
|
|
44388
|
+
const ok = await deps.report(failed).catch(() => false);
|
|
44389
|
+
if (!ok) await deps.enqueueRun(failed).catch(() => {
|
|
44390
|
+
});
|
|
44391
|
+
return 1;
|
|
44392
|
+
}
|
|
44393
|
+
const env = jobEnv.env;
|
|
44394
|
+
const hasEnv = Object.keys(env).length > 0;
|
|
44395
|
+
const spawnIt = () => hasEnv ? deps.spawnCommand(command, env) : deps.spawnCommand(command);
|
|
44396
|
+
const secrets = Object.values(env);
|
|
44397
|
+
const clean2 = (t) => redactSensitiveOutput(scrubValues(t, secrets));
|
|
43617
44398
|
let claimed = [];
|
|
43618
44399
|
try {
|
|
43619
44400
|
claimed = await deps.claimBackfills(jobId);
|
|
@@ -43622,10 +44403,10 @@ async function runWrapped(deps, jobId, command) {
|
|
|
43622
44403
|
}
|
|
43623
44404
|
for (const backfill of claimed) {
|
|
43624
44405
|
const backfillStartedAt = deps.now().toISOString();
|
|
43625
|
-
const { exitCode: backfillExitCode, stderrTail: backfillStderrTail, outputTail: backfillOutputTail } = await
|
|
44406
|
+
const { exitCode: backfillExitCode, stderrTail: backfillStderrTail, outputTail: backfillOutputTail } = await spawnIt();
|
|
43626
44407
|
const backfillFinishedAt = deps.now().toISOString();
|
|
43627
|
-
const backfillErrorSnippet = backfillExitCode !== 0 ?
|
|
43628
|
-
const backfillOutputSnippet =
|
|
44408
|
+
const backfillErrorSnippet = backfillExitCode !== 0 ? clean2(backfillStderrTail.trim()) : "";
|
|
44409
|
+
const backfillOutputSnippet = clean2((backfillOutputTail ?? "").trim());
|
|
43629
44410
|
const replayRun = {
|
|
43630
44411
|
jobId,
|
|
43631
44412
|
exitCode: backfillExitCode,
|
|
@@ -43645,10 +44426,10 @@ async function runWrapped(deps, jobId, command) {
|
|
|
43645
44426
|
}
|
|
43646
44427
|
}
|
|
43647
44428
|
const startedAt = deps.now().toISOString();
|
|
43648
|
-
const { exitCode, stderrTail, outputTail } = await
|
|
44429
|
+
const { exitCode, stderrTail, outputTail } = await spawnIt();
|
|
43649
44430
|
const finishedAt = deps.now().toISOString();
|
|
43650
|
-
const errorSnippet = exitCode !== 0 ?
|
|
43651
|
-
const outputSnippet =
|
|
44431
|
+
const errorSnippet = exitCode !== 0 ? clean2(stderrTail.trim()) : "";
|
|
44432
|
+
const outputSnippet = clean2((outputTail ?? "").trim());
|
|
43652
44433
|
const run = {
|
|
43653
44434
|
jobId,
|
|
43654
44435
|
exitCode,
|
|
@@ -43671,33 +44452,75 @@ var STDERR_TAIL_BYTES = 4096;
|
|
|
43671
44452
|
var OUTPUT_SNIPPET_MAX_CHARS = 4e3;
|
|
43672
44453
|
var OUTPUT_SNIPPET_MAX_LINES = 20;
|
|
43673
44454
|
var OUTPUT_TAIL_MAX_BYTES = OUTPUT_SNIPPET_MAX_CHARS * 4;
|
|
43674
|
-
function
|
|
43675
|
-
|
|
44455
|
+
function scrubTail(tail, secrets, truncated, extra) {
|
|
44456
|
+
if (!truncated) return Buffer.from(scrubValues(tail.toString("utf8"), secrets), "utf8");
|
|
44457
|
+
const needles = secrets.filter((v) => v.length >= 4).map((v) => {
|
|
44458
|
+
const n = Buffer.from(v, "utf8");
|
|
44459
|
+
return { len: n.length, starts: matchStarts(tail, n), next: 0 };
|
|
44460
|
+
});
|
|
44461
|
+
let cut = Math.min(extra, tail.length);
|
|
44462
|
+
let crossed = false;
|
|
44463
|
+
for (let moved = true; moved; ) {
|
|
44464
|
+
moved = false;
|
|
44465
|
+
while (cut < tail.length && (tail[cut] & 192) === 128) {
|
|
44466
|
+
cut++;
|
|
44467
|
+
moved = true;
|
|
44468
|
+
}
|
|
44469
|
+
for (const n of needles) {
|
|
44470
|
+
for (; n.next < n.starts.length && n.starts[n.next] < cut; n.next++) {
|
|
44471
|
+
const end = n.starts[n.next] + n.len;
|
|
44472
|
+
if (end > cut) {
|
|
44473
|
+
cut = end;
|
|
44474
|
+
crossed = moved = true;
|
|
44475
|
+
}
|
|
44476
|
+
}
|
|
44477
|
+
}
|
|
44478
|
+
}
|
|
44479
|
+
const rest = scrubValues(tail.subarray(cut).toString("utf8"), secrets);
|
|
44480
|
+
return Buffer.from((crossed ? "[redacted]" : "") + rest, "utf8");
|
|
44481
|
+
}
|
|
44482
|
+
function decodeOutputTail(tail, secrets = [], truncated = false, extra = 0) {
|
|
44483
|
+
const decoded = redactSensitiveOutput(scrubTail(tail, secrets, truncated, extra).toString("utf8"));
|
|
43676
44484
|
const lines = decoded.split("\n");
|
|
43677
44485
|
return lines.slice(-OUTPUT_SNIPPET_MAX_LINES).join("\n").slice(-OUTPUT_SNIPPET_MAX_CHARS);
|
|
43678
44486
|
}
|
|
43679
|
-
function realSpawnCommand(command) {
|
|
44487
|
+
function realSpawnCommand(command, env) {
|
|
43680
44488
|
return new Promise((resolve) => {
|
|
43681
|
-
|
|
44489
|
+
let child;
|
|
44490
|
+
try {
|
|
44491
|
+
child = (0, import_node_child_process4.spawn)(withoutPkgEnv(command.join(" ")), { stdio: ["inherit", "pipe", "pipe"], shell: true, ...env ? { env: { ...process.env, ...env } } : {} });
|
|
44492
|
+
} catch {
|
|
44493
|
+
resolve({ exitCode: 1, stderrTail: "env value could not be passed to the command", outputTail: "" });
|
|
44494
|
+
return;
|
|
44495
|
+
}
|
|
44496
|
+
const secrets = Object.values(env ?? {});
|
|
44497
|
+
const extra = Math.max(0, ...secrets.map((v) => Buffer.byteLength(v)));
|
|
44498
|
+
const finishStderr = () => scrubTail(tail, secrets, tailSeen > tail.length, extra).subarray(-STDERR_TAIL_BYTES).toString("utf8");
|
|
44499
|
+
const finishOutput = () => decodeOutputTail(outputTail, secrets, outputSeen > outputTail.length, extra);
|
|
43682
44500
|
let tail = Buffer.alloc(0);
|
|
43683
44501
|
let outputTail = Buffer.alloc(0);
|
|
44502
|
+
let tailSeen = 0;
|
|
44503
|
+
let outputSeen = 0;
|
|
43684
44504
|
child.stdout?.on("data", (chunk) => {
|
|
43685
44505
|
if (!process.stdout.write(chunk)) {
|
|
43686
44506
|
child.stdout?.pause();
|
|
43687
44507
|
process.stdout.once("drain", () => child.stdout?.resume());
|
|
43688
44508
|
}
|
|
43689
|
-
|
|
44509
|
+
outputSeen += chunk.length;
|
|
44510
|
+
outputTail = Buffer.concat([outputTail, chunk]).subarray(-(OUTPUT_TAIL_MAX_BYTES + extra));
|
|
43690
44511
|
});
|
|
43691
44512
|
child.stderr?.on("data", (chunk) => {
|
|
43692
44513
|
if (!process.stderr.write(chunk)) {
|
|
43693
44514
|
child.stderr?.pause();
|
|
43694
44515
|
process.stderr.once("drain", () => child.stderr?.resume());
|
|
43695
44516
|
}
|
|
43696
|
-
|
|
43697
|
-
|
|
44517
|
+
tailSeen += chunk.length;
|
|
44518
|
+
outputSeen += chunk.length;
|
|
44519
|
+
tail = Buffer.concat([tail, chunk]).subarray(-(STDERR_TAIL_BYTES + extra));
|
|
44520
|
+
outputTail = Buffer.concat([outputTail, chunk]).subarray(-(OUTPUT_TAIL_MAX_BYTES + extra));
|
|
43698
44521
|
});
|
|
43699
|
-
child.on("close", (code) => resolve({ exitCode: code ?? 1, stderrTail:
|
|
43700
|
-
child.on("error", () => resolve({ exitCode: 1, stderrTail:
|
|
44522
|
+
child.on("close", (code) => resolve({ exitCode: code ?? 1, stderrTail: finishStderr(), outputTail: finishOutput() }));
|
|
44523
|
+
child.on("error", () => resolve({ exitCode: 1, stderrTail: finishStderr(), outputTail: finishOutput() }));
|
|
43701
44524
|
});
|
|
43702
44525
|
}
|
|
43703
44526
|
var FETCH_TIMEOUT_MS = 8e3;
|
|
@@ -43766,15 +44589,25 @@ function createBackfillClaimer(getSession) {
|
|
|
43766
44589
|
}
|
|
43767
44590
|
};
|
|
43768
44591
|
}
|
|
43769
|
-
|
|
44592
|
+
var RUN_USAGE = "usage: norc run --job-id <id> [--env NAME,...] -- <command>";
|
|
44593
|
+
function parseRunArgs(args) {
|
|
43770
44594
|
const sepIndex = args.indexOf("--");
|
|
43771
|
-
const
|
|
43772
|
-
|
|
43773
|
-
|
|
43774
|
-
}
|
|
44595
|
+
const flags = sepIndex === -1 ? args : args.slice(0, sepIndex);
|
|
44596
|
+
const jobIdFlagIndex = flags.indexOf("--job-id");
|
|
44597
|
+
if (jobIdFlagIndex === -1 || sepIndex === -1 || sepIndex < jobIdFlagIndex + 2) throw new Error(RUN_USAGE);
|
|
43775
44598
|
const jobId = args[jobIdFlagIndex + 1];
|
|
43776
44599
|
const command = args.slice(sepIndex + 1);
|
|
43777
|
-
if (!jobId || command.length === 0) throw new Error(
|
|
44600
|
+
if (!jobId || jobId.startsWith("-") || command.length === 0) throw new Error(RUN_USAGE);
|
|
44601
|
+
const envFlagIndex = flags.indexOf("--env");
|
|
44602
|
+
let envNames;
|
|
44603
|
+
if (envFlagIndex !== -1) {
|
|
44604
|
+
envNames = (flags[envFlagIndex + 1] ?? "").split(",");
|
|
44605
|
+
if (!envNames.every((n) => ENV_NAME_RE.test(n))) throw new Error(`invalid --env list; ${RUN_USAGE}`);
|
|
44606
|
+
}
|
|
44607
|
+
return { jobId, envNames, command };
|
|
44608
|
+
}
|
|
44609
|
+
async function cmdRun(args) {
|
|
44610
|
+
const { jobId, envNames, command } = parseRunArgs(args);
|
|
43778
44611
|
const getSession = createSessionCache(process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY);
|
|
43779
44612
|
return runWrapped(
|
|
43780
44613
|
{
|
|
@@ -43784,15 +44617,576 @@ async function cmdRun(args) {
|
|
|
43784
44617
|
clearQueue,
|
|
43785
44618
|
enqueueRun,
|
|
43786
44619
|
now: () => /* @__PURE__ */ new Date(),
|
|
43787
|
-
claimBackfills: createBackfillClaimer(getSession)
|
|
44620
|
+
claimBackfills: createBackfillClaimer(getSession),
|
|
44621
|
+
loadJobEnv: createJobEnvLoader(getSession)
|
|
43788
44622
|
},
|
|
43789
44623
|
jobId,
|
|
43790
|
-
command
|
|
44624
|
+
command,
|
|
44625
|
+
envNames
|
|
43791
44626
|
);
|
|
43792
44627
|
}
|
|
43793
44628
|
|
|
44629
|
+
// ../../packages/usage/src/parse.ts
|
|
44630
|
+
var UsageParseError = class extends Error {
|
|
44631
|
+
constructor(path, what) {
|
|
44632
|
+
super(`invalid usage payload at ${path}: ${what}`);
|
|
44633
|
+
this.name = "UsageParseError";
|
|
44634
|
+
}
|
|
44635
|
+
};
|
|
44636
|
+
var PLANS2 = ["free", "pro", "power", "team"];
|
|
44637
|
+
var obj = (v, p) => {
|
|
44638
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) throw new UsageParseError(p, "expected object");
|
|
44639
|
+
return v;
|
|
44640
|
+
};
|
|
44641
|
+
var arr = (v, p) => {
|
|
44642
|
+
if (!Array.isArray(v)) throw new UsageParseError(p, "expected array");
|
|
44643
|
+
return v;
|
|
44644
|
+
};
|
|
44645
|
+
var num = (v, p) => {
|
|
44646
|
+
const n = typeof v === "string" && v.trim() !== "" ? Number(v) : v;
|
|
44647
|
+
if (typeof n !== "number" || !Number.isFinite(n)) throw new UsageParseError(p, "expected number");
|
|
44648
|
+
return n;
|
|
44649
|
+
};
|
|
44650
|
+
var count = (v, p) => {
|
|
44651
|
+
const n = num(v, p);
|
|
44652
|
+
if (!Number.isInteger(n) || n < 0) throw new UsageParseError(p, "expected non-negative integer");
|
|
44653
|
+
return n;
|
|
44654
|
+
};
|
|
44655
|
+
var str = (v, p) => {
|
|
44656
|
+
if (typeof v !== "string") throw new UsageParseError(p, "expected string");
|
|
44657
|
+
return v;
|
|
44658
|
+
};
|
|
44659
|
+
var counts = (v, p) => {
|
|
44660
|
+
const o = obj(v, p);
|
|
44661
|
+
return { ok: count(o.ok, `${p}.ok`), failed: count(o.failed, `${p}.failed`), missed: count(o.missed, `${p}.missed`) };
|
|
44662
|
+
};
|
|
44663
|
+
function parseUsageSummary(raw) {
|
|
44664
|
+
const o = obj(raw, "$");
|
|
44665
|
+
const days = count(o.days, "days");
|
|
44666
|
+
if (days !== 7 && days !== 30) throw new UsageParseError("days", "expected 7 or 30");
|
|
44667
|
+
const plan = str(o.plan, "plan");
|
|
44668
|
+
if (!PLANS2.includes(plan)) throw new UsageParseError("plan", `unknown plan "${plan}"`);
|
|
44669
|
+
const daily = arr(o.daily, "daily").map((d, i) => {
|
|
44670
|
+
const e = obj(d, `daily[${i}]`);
|
|
44671
|
+
const date = str(e.date, `daily[${i}].date`);
|
|
44672
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw new UsageParseError(`daily[${i}].date`, "expected YYYY-MM-DD");
|
|
44673
|
+
return { date, ...counts(e, `daily[${i}]`) };
|
|
44674
|
+
});
|
|
44675
|
+
if (daily.length !== days) throw new UsageParseError("daily", `expected ${days} entries, got ${daily.length}`);
|
|
44676
|
+
const heatmap = arr(o.heatmap, "heatmap").map((r, i) => arr(r, `heatmap[${i}]`).map((c, h) => count(c, `heatmap[${i}][${h}]`)));
|
|
44677
|
+
if (heatmap.length !== 7 || heatmap.some((r) => r.length !== 24)) throw new UsageParseError("heatmap", "expected 7 rows of 24");
|
|
44678
|
+
const med = o.medianDurationSeconds;
|
|
44679
|
+
const lp = o.lastProblem;
|
|
44680
|
+
let lastProblem = null;
|
|
44681
|
+
if (lp != null) {
|
|
44682
|
+
const e = obj(lp, "lastProblem");
|
|
44683
|
+
const status = str(e.status, "lastProblem.status");
|
|
44684
|
+
if (status !== "failed" && status !== "missed") throw new UsageParseError("lastProblem.status", "expected failed|missed");
|
|
44685
|
+
lastProblem = { at: str(e.at, "lastProblem.at"), jobId: str(e.jobId, "lastProblem.jobId"), jobName: str(e.jobName, "lastProblem.jobName"), status };
|
|
44686
|
+
}
|
|
44687
|
+
return {
|
|
44688
|
+
generatedAt: str(o.generatedAt, "generatedAt"),
|
|
44689
|
+
days,
|
|
44690
|
+
plan,
|
|
44691
|
+
usedJobs: count(o.usedJobs, "usedJobs"),
|
|
44692
|
+
usedMachines: count(o.usedMachines, "usedMachines"),
|
|
44693
|
+
totals: counts(o.totals, "totals"),
|
|
44694
|
+
medianDurationSeconds: med == null ? null : num(med, "medianDurationSeconds"),
|
|
44695
|
+
daily,
|
|
44696
|
+
heatmap,
|
|
44697
|
+
topFailingJobs: arr(o.topFailingJobs, "topFailingJobs").map((j, i) => {
|
|
44698
|
+
const e = obj(j, `topFailingJobs[${i}]`);
|
|
44699
|
+
const p = `topFailingJobs[${i}]`;
|
|
44700
|
+
return {
|
|
44701
|
+
jobId: str(e.jobId, `${p}.jobId`),
|
|
44702
|
+
jobName: str(e.jobName, `${p}.jobName`),
|
|
44703
|
+
machineId: str(e.machineId, `${p}.machineId`),
|
|
44704
|
+
machineName: str(e.machineName, `${p}.machineName`),
|
|
44705
|
+
failed: count(e.failed, `${p}.failed`),
|
|
44706
|
+
missed: count(e.missed, `${p}.missed`)
|
|
44707
|
+
};
|
|
44708
|
+
}),
|
|
44709
|
+
machines: arr(o.machines, "machines").map((m, i) => {
|
|
44710
|
+
const e = obj(m, `machines[${i}]`);
|
|
44711
|
+
const p = `machines[${i}]`;
|
|
44712
|
+
const md = arr(e.daily, `${p}.daily`).map((d, k) => counts(d, `${p}.daily[${k}]`));
|
|
44713
|
+
if (md.length !== days) throw new UsageParseError(`${p}.daily`, `expected ${days} entries`);
|
|
44714
|
+
return {
|
|
44715
|
+
id: str(e.id, `${p}.id`),
|
|
44716
|
+
name: str(e.name, `${p}.name`),
|
|
44717
|
+
env: e.env == null ? null : str(e.env, `${p}.env`),
|
|
44718
|
+
...counts(e, p),
|
|
44719
|
+
daily: md
|
|
44720
|
+
};
|
|
44721
|
+
}),
|
|
44722
|
+
lastProblem,
|
|
44723
|
+
cleanDays: count(o.cleanDays, "cleanDays")
|
|
44724
|
+
};
|
|
44725
|
+
}
|
|
44726
|
+
|
|
44727
|
+
// ../../packages/usage/src/fetch.ts
|
|
44728
|
+
async function fetchUsageDevice(opts) {
|
|
44729
|
+
const f = opts.fetchImpl ?? fetch;
|
|
44730
|
+
const res = await f(`${opts.functionsUrl.replace(/\/$/, "")}/device-usage`, {
|
|
44731
|
+
method: "POST",
|
|
44732
|
+
headers: { Authorization: `Bearer ${opts.deviceJwt}`, "Content-Type": "application/json" },
|
|
44733
|
+
body: JSON.stringify({ days: opts.days ?? 30 })
|
|
44734
|
+
});
|
|
44735
|
+
if (!res.ok) throw new Error(`device-usage failed: HTTP ${res.status}`);
|
|
44736
|
+
return parseUsageSummary(await res.json());
|
|
44737
|
+
}
|
|
44738
|
+
|
|
44739
|
+
// ../../packages/status/src/health.ts
|
|
44740
|
+
var HEARTBEAT_STALE_MS = 10 * 60 * 1e3;
|
|
44741
|
+
function relativeTimeAgo(iso, now = /* @__PURE__ */ new Date()) {
|
|
44742
|
+
if (!iso) return "never";
|
|
44743
|
+
const ms = now.getTime() - new Date(iso).getTime();
|
|
44744
|
+
if (ms < 0) return "just now";
|
|
44745
|
+
const s = Math.floor(ms / 1e3);
|
|
44746
|
+
if (s < 60) return "just now";
|
|
44747
|
+
const m = Math.floor(s / 60);
|
|
44748
|
+
if (m < 60) return `${m}m ago`;
|
|
44749
|
+
const h = Math.floor(m / 60);
|
|
44750
|
+
if (h < 24) return `${h}h ago`;
|
|
44751
|
+
const d = Math.floor(h / 24);
|
|
44752
|
+
return `${d}d ago`;
|
|
44753
|
+
}
|
|
44754
|
+
|
|
44755
|
+
// ../../packages/status/src/display.ts
|
|
44756
|
+
var MACHINE_STATUS_DISPLAY = {
|
|
44757
|
+
online: { tone: "success", label: "Online", glyph: "\u25CF" },
|
|
44758
|
+
warning: { tone: "warning", label: "Warning", glyph: "\u25B2" },
|
|
44759
|
+
offline: { tone: "failed", label: "Offline", glyph: "\u2715" },
|
|
44760
|
+
unknown: { tone: "disabled", label: "Unknown", glyph: "?" }
|
|
44761
|
+
};
|
|
44762
|
+
var UPDATE_REQUIRED_DISPLAY = { ...MACHINE_STATUS_DISPLAY.offline, label: "Update required" };
|
|
44763
|
+
|
|
44764
|
+
// ../../packages/usage/src/view.ts
|
|
44765
|
+
var PLAN_NAMES = { free: "Free", pro: "Pro", power: "Power", team: "Team" };
|
|
44766
|
+
function headroomTone(used, cap) {
|
|
44767
|
+
const p = used / cap;
|
|
44768
|
+
return p >= 0.9 ? "failed" : p >= 0.7 ? "warning" : "calm";
|
|
44769
|
+
}
|
|
44770
|
+
function headroom(kind, used, plan) {
|
|
44771
|
+
const c = kind === "jobs" ? jobLimit(plan) : machineLimit(plan);
|
|
44772
|
+
if (c === "custom") {
|
|
44773
|
+
return { used, cap: null, left: null, tone: "calm", pct: 0, text: kind === "jobs" ? "Unlimited" : "Custom limit", showChip: false };
|
|
44774
|
+
}
|
|
44775
|
+
const tone = headroomTone(used, c);
|
|
44776
|
+
const left = c - used;
|
|
44777
|
+
return { used, cap: c, left, tone, pct: Math.min(100, used / c * 100), text: left <= 0 ? "At limit" : `${left} left`, showChip: tone !== "calm" };
|
|
44778
|
+
}
|
|
44779
|
+
function headroomFooter(usedJobs, usedMachines, plan) {
|
|
44780
|
+
const n = PLAN_NAMES[plan];
|
|
44781
|
+
const jobs = headroom("jobs", usedJobs, plan);
|
|
44782
|
+
const mach = headroom("machines", usedMachines, plan);
|
|
44783
|
+
const messages = [];
|
|
44784
|
+
if (jobs.tone !== "calm" && jobs.left != null) {
|
|
44785
|
+
messages.push(jobs.left <= 0 ? `Job limit reached on ${n}.` : `${jobs.left} job${jobs.left === 1 ? "" : "s"} left on ${n}.`);
|
|
44786
|
+
}
|
|
44787
|
+
if (mach.tone !== "calm" && mach.left != null) {
|
|
44788
|
+
messages.push(mach.left <= 0 ? `Machine limit reached on ${n}.` : `${mach.left} machine${mach.left === 1 ? "" : "s"} left on ${n}.`);
|
|
44789
|
+
}
|
|
44790
|
+
return messages.length ? { messages, note: "Plans scale jobs and machines together.", showUpgrade: plan !== "power" && plan !== "team" } : { messages, note: `Plenty of room on ${n}. You'll see a note here when you pass 70%.`, showUpgrade: false };
|
|
44791
|
+
}
|
|
44792
|
+
var formatCount = (n) => Math.round(n).toLocaleString("en-US");
|
|
44793
|
+
var formatPercent = (v) => `${v.toFixed(1)}%`;
|
|
44794
|
+
var formatSeconds = (v) => `${v.toFixed(1)}s`;
|
|
44795
|
+
var DOW = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
44796
|
+
var MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
44797
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
44798
|
+
function dayLabel(date) {
|
|
44799
|
+
const d = /* @__PURE__ */ new Date(`${date}T00:00:00Z`);
|
|
44800
|
+
return `${DOW[d.getUTCDay()]} ${d.getUTCDate()} ${MON[d.getUTCMonth()]}`;
|
|
44801
|
+
}
|
|
44802
|
+
var totalRuns = (c) => c.ok + c.failed + c.missed;
|
|
44803
|
+
function successRate(c) {
|
|
44804
|
+
const t = totalRuns(c);
|
|
44805
|
+
return t ? c.ok / t * 100 : 100;
|
|
44806
|
+
}
|
|
44807
|
+
var dailyRates = (daily) => daily.map(successRate);
|
|
44808
|
+
function lowestDay(daily) {
|
|
44809
|
+
const rates = dailyRates(daily);
|
|
44810
|
+
if (!rates.length) return null;
|
|
44811
|
+
const rate = Math.min(...rates);
|
|
44812
|
+
const index = rates.indexOf(rate);
|
|
44813
|
+
return { rate, index, date: daily[index]?.date ?? null };
|
|
44814
|
+
}
|
|
44815
|
+
function rateCaption(daily) {
|
|
44816
|
+
const low = lowestDay(daily);
|
|
44817
|
+
if (!low || !low.date) return "";
|
|
44818
|
+
const now = successRate(daily[daily.length - 1]);
|
|
44819
|
+
return `Low ${formatPercent(low.rate)} on ${dayLabel(low.date)} \xB7 now ${formatPercent(now)}`;
|
|
44820
|
+
}
|
|
44821
|
+
function streakChip(s, now = /* @__PURE__ */ new Date()) {
|
|
44822
|
+
if (s.cleanDays >= 3) return { kind: "streak", text: `${s.cleanDays} clean days` };
|
|
44823
|
+
if (s.lastProblem) return { kind: "problem", text: `Last problem ${relativeTimeAgo(s.lastProblem.at, now)}: ${s.lastProblem.jobName}` };
|
|
44824
|
+
return { kind: "none" };
|
|
44825
|
+
}
|
|
44826
|
+
var medianText = (s) => s == null ? "\u2014" : formatSeconds(s);
|
|
44827
|
+
var isUsageEmpty = (s) => totalRuns(s.totals) === 0;
|
|
44828
|
+
var sparklineFloor = (vals) => Math.floor(Math.min(...vals)) - 1;
|
|
44829
|
+
function runsSummarySentence(daily, days = daily.length) {
|
|
44830
|
+
const t = daily.reduce((a, d) => ({ ok: a.ok + d.ok, failed: a.failed + d.failed, missed: a.missed + d.missed }), { ok: 0, failed: 0, missed: 0 });
|
|
44831
|
+
const tot = totalRuns(t);
|
|
44832
|
+
if (!daily.length || tot === 0) return `No runs in ${days} days.`;
|
|
44833
|
+
const busy = daily.reduce((a, d) => totalRuns(d) > totalRuns(a) ? d : a);
|
|
44834
|
+
const worst = daily.reduce((a, d) => d.failed + d.missed > a.failed + a.missed ? d : a);
|
|
44835
|
+
const wn = worst.failed + worst.missed;
|
|
44836
|
+
return `${formatCount(tot)} runs in ${days} days: ${formatCount(t.ok)} ok, ${t.failed} failed, ${t.missed} missed. Busiest ${dayLabel(busy.date)} (${totalRuns(busy)}).${wn ? ` Most problems ${dayLabel(worst.date)} (${wn}).` : " No failed or missed runs."}`;
|
|
44837
|
+
}
|
|
44838
|
+
function heatLevel(v, max) {
|
|
44839
|
+
if (v <= 0 || max <= 0) return 0;
|
|
44840
|
+
const r = v / max;
|
|
44841
|
+
return r <= 0.25 ? 1 : r <= 0.5 ? 2 : r <= 0.75 ? 3 : 4;
|
|
44842
|
+
}
|
|
44843
|
+
var HEAT_DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
44844
|
+
var heatHourLabel = (h) => `${pad(h)}:00`;
|
|
44845
|
+
var heatCellLabel = (row, hour) => `${HEAT_DAYS[row]} ${heatHourLabel(hour)}`;
|
|
44846
|
+
function heatCells(heatmap) {
|
|
44847
|
+
const flat = [];
|
|
44848
|
+
heatmap.forEach((r, row) => r.forEach((value, hour) => flat.push({ row, hour, value })));
|
|
44849
|
+
let max = 0;
|
|
44850
|
+
let best = 0;
|
|
44851
|
+
flat.forEach((c, i) => {
|
|
44852
|
+
if (c.value > max) {
|
|
44853
|
+
max = c.value;
|
|
44854
|
+
best = i;
|
|
44855
|
+
}
|
|
44856
|
+
});
|
|
44857
|
+
return { cells: flat.map((c) => ({ ...c, level: heatLevel(c.value, max), label: heatCellLabel(c.row, c.hour) })), max, best };
|
|
44858
|
+
}
|
|
44859
|
+
function quietestHour(heatmap) {
|
|
44860
|
+
let hour = 0;
|
|
44861
|
+
let runs = Infinity;
|
|
44862
|
+
for (let h = 0; h < 24; h++) {
|
|
44863
|
+
const t = heatmap.reduce((a, r) => a + (r[h] ?? 0), 0);
|
|
44864
|
+
if (t < runs) {
|
|
44865
|
+
runs = t;
|
|
44866
|
+
hour = h;
|
|
44867
|
+
}
|
|
44868
|
+
}
|
|
44869
|
+
return { hour, runs: runs === Infinity ? 0 : runs };
|
|
44870
|
+
}
|
|
44871
|
+
function heatSummary(heatmap) {
|
|
44872
|
+
const { cells, max, best } = heatCells(heatmap);
|
|
44873
|
+
if (max === 0) return "No runs yet.";
|
|
44874
|
+
const b = cells[best];
|
|
44875
|
+
const q = quietestHour(heatmap);
|
|
44876
|
+
return `Busiest hour: ${b.label} with ${b.value} runs. Quietest hour: ${heatHourLabel(q.hour)} (${q.runs} runs).`;
|
|
44877
|
+
}
|
|
44878
|
+
function topFailingRows(jobs) {
|
|
44879
|
+
const sorted = jobs.map((j) => ({ ...j, total: j.failed + j.missed })).filter((j) => j.total > 0).sort((a, b) => b.total - a.total);
|
|
44880
|
+
const max = sorted[0]?.total ?? 1;
|
|
44881
|
+
return sorted.map((j, i) => ({
|
|
44882
|
+
...j,
|
|
44883
|
+
rank: i + 1,
|
|
44884
|
+
pct: j.total / max * 100,
|
|
44885
|
+
counts: [j.failed ? `${j.failed} failed` : "", j.missed ? `${j.missed} missed` : ""].filter(Boolean).join(" \xB7 ")
|
|
44886
|
+
}));
|
|
44887
|
+
}
|
|
44888
|
+
function machineRows(machines) {
|
|
44889
|
+
return machines.map((m) => {
|
|
44890
|
+
const rates = dailyRates(m.daily);
|
|
44891
|
+
const rate = successRate(m);
|
|
44892
|
+
const low = rates.length ? Math.min(...rates) : 100;
|
|
44893
|
+
return {
|
|
44894
|
+
id: m.id,
|
|
44895
|
+
name: m.name,
|
|
44896
|
+
env: m.env,
|
|
44897
|
+
rate,
|
|
44898
|
+
rateText: formatPercent(rate),
|
|
44899
|
+
rates,
|
|
44900
|
+
counts: `${m.failed} failed \xB7 ${m.missed} missed`,
|
|
44901
|
+
ariaLabel: `${m.name} daily success rate over ${m.daily.length} days, low ${formatPercent(low)}, now ${formatPercent(rates[rates.length - 1] ?? 100)}`
|
|
44902
|
+
};
|
|
44903
|
+
});
|
|
44904
|
+
}
|
|
44905
|
+
|
|
44906
|
+
// src/commands/usage-render.ts
|
|
44907
|
+
var ANSI = /\x1b\[[0-9;]*m/g;
|
|
44908
|
+
var vlen = (s) => s.replace(ANSI, "").length;
|
|
44909
|
+
var cleanLabel = (s) => s.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)?/g, "").replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\x00-\x1f\x7f-\x9f]/g, "");
|
|
44910
|
+
var padR = (s, w) => s + " ".repeat(Math.max(0, w - vlen(s)));
|
|
44911
|
+
var padL = (s, w) => " ".repeat(Math.max(0, w - vlen(s))) + s;
|
|
44912
|
+
var trunc = (s, w, u) => s.length <= w ? s : s.slice(0, Math.max(0, w - 1)) + (u ? "\u2026" : "~");
|
|
44913
|
+
function wrap(text, w) {
|
|
44914
|
+
const out = [];
|
|
44915
|
+
let line = "";
|
|
44916
|
+
for (const word of text.split(" ")) {
|
|
44917
|
+
if (line && line.length + 1 + word.length > w) {
|
|
44918
|
+
out.push(line);
|
|
44919
|
+
line = word;
|
|
44920
|
+
} else line = line ? `${line} ${word}` : word;
|
|
44921
|
+
}
|
|
44922
|
+
if (line) out.push(line);
|
|
44923
|
+
return out;
|
|
44924
|
+
}
|
|
44925
|
+
var GLYPH = {
|
|
44926
|
+
u: { full: "\u2588", empty: "\u2591", cap: "\u2502", ok: "\u2588", failed: "\u2592", missed: "\u2591", heat: ["\xB7", "\u2591", "\u2592", "\u2593", "\u2588"], spark: "\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588", rule: "\u2500", dot: "\xB7" },
|
|
44927
|
+
a: { full: "#", empty: "-", cap: "|", ok: "#", failed: "=", missed: ".", heat: [" ", ".", ":", "+", "#"], spark: "._-~=+*#", rule: "-", dot: "." }
|
|
44928
|
+
};
|
|
44929
|
+
var BIG = {
|
|
44930
|
+
"0": ["\u250C\u2500\u2510", "\u2502 \u2502", "\u2514\u2500\u2518"],
|
|
44931
|
+
"1": [" \u2577 ", " \u2502 ", " \u2575 "],
|
|
44932
|
+
"2": ["\u2576\u2500\u2510", "\u250C\u2500\u2518", "\u2514\u2500\u2574"],
|
|
44933
|
+
"3": ["\u2576\u2500\u2510", " \u2500\u2524", "\u2576\u2500\u2518"],
|
|
44934
|
+
"4": ["\u2577 \u2577", "\u2514\u2500\u2524", " \u2575"],
|
|
44935
|
+
"5": ["\u250C\u2500\u2574", "\u2514\u2500\u2510", "\u2576\u2500\u2518"],
|
|
44936
|
+
"6": ["\u250C\u2500\u2574", "\u251C\u2500\u2510", "\u2514\u2500\u2518"],
|
|
44937
|
+
"7": ["\u2576\u2500\u2510", " \u2502", " \u2575"],
|
|
44938
|
+
"8": ["\u250C\u2500\u2510", "\u251C\u2500\u2524", "\u2514\u2500\u2518"],
|
|
44939
|
+
"9": ["\u250C\u2500\u2510", "\u2514\u2500\u2524", "\u2576\u2500\u2518"],
|
|
44940
|
+
".": [" ", " ", "\u25AA "],
|
|
44941
|
+
"%": ["o \u2571", " \u2571 ", "\u2571 o"]
|
|
44942
|
+
};
|
|
44943
|
+
var ASCII_MAP = { "\u250C": "+", "\u2510": "+", "\u2514": "+", "\u2518": "+", "\u251C": "+", "\u2524": "+", "\u2500": "-", "\u2502": "|", "\u2577": ".", "\u2575": "'", "\u2576": "-", "\u2574": "-", "\u25AA": ".", "\u2571": "/" };
|
|
44944
|
+
function renderUsage(s, opts) {
|
|
44945
|
+
const W = Math.max(80, Math.min(120, Math.floor(opts.width)));
|
|
44946
|
+
const g = opts.unicode ? GLYPH.u : GLYPH.a;
|
|
44947
|
+
const now = opts.now ?? new Date(s.generatedAt);
|
|
44948
|
+
const sgr = (code) => (t) => opts.color ? `\x1B[${code}m${t}\x1B[0m` : t;
|
|
44949
|
+
const bold = sgr("1"), dim = sgr("2"), green = sgr("32"), amber = sgr("33"), red = sgr("31"), cyan = sgr("36");
|
|
44950
|
+
const toneColor = { calm: green, warning: amber, failed: red };
|
|
44951
|
+
const wide = W >= 100;
|
|
44952
|
+
const colW = wide ? Math.floor((W - 3) / 2) : W;
|
|
44953
|
+
const empty = isUsageEmpty(s);
|
|
44954
|
+
const title = (t, w) => `${bold(t)} ${dim(g.rule.repeat(Math.max(2, w - t.length - 1)))}`;
|
|
44955
|
+
const spark = (rates, lo = sparklineFloor(rates)) => rates.map((v) => g.spark[Math.max(0, Math.min(7, Math.round((v - lo) / (100 - lo || 1) * 7)))]).join("");
|
|
44956
|
+
const headroomPanel = () => {
|
|
44957
|
+
const barW = Math.max(10, Math.min(24, colW - 42));
|
|
44958
|
+
const row = (label, h) => {
|
|
44959
|
+
if (h.cap == null) return `${padR(label, 9)} ${padR(`${h.used}`, barW + 1)} ${padR(`${h.used} used`, 9)} ${dim(h.text)}`;
|
|
44960
|
+
const fill = Math.min(barW, Math.round(h.pct / 100 * barW));
|
|
44961
|
+
const c = toneColor[h.tone];
|
|
44962
|
+
const bar = c(g.full.repeat(fill)) + dim(g.empty.repeat(barW - fill)) + dim(g.cap);
|
|
44963
|
+
return `${padR(label, 9)} ${bar} ${padL(`${h.used} / ${h.cap}`, 7)} ${padR(h.text, 8)} ${c(h.tone === "calm" ? "calm" : h.tone === "warning" ? "warning" : (h.left ?? 0) <= 0 ? "" : "near limit")}`;
|
|
44964
|
+
};
|
|
44965
|
+
const f = headroomFooter(s.usedJobs, s.usedMachines, s.plan);
|
|
44966
|
+
const lines = [
|
|
44967
|
+
title(`Headroom \xB7 ${PLAN_NAMES[s.plan]} plan`, colW),
|
|
44968
|
+
row("Jobs", headroom("jobs", s.usedJobs, s.plan)),
|
|
44969
|
+
row("Machines", headroom("machines", s.usedMachines, s.plan)),
|
|
44970
|
+
""
|
|
44971
|
+
];
|
|
44972
|
+
for (const m of f.messages) lines.push(amber(m));
|
|
44973
|
+
lines.push(...wrap(f.note, colW).map(dim));
|
|
44974
|
+
if (f.showUpgrade) lines.push(`Upgrade: ${cyan(`${opts.vaultUrl ?? "https://vault.norc.app"}/settings/billing`)}`);
|
|
44975
|
+
if (f.messages.length) lines.push("Need more? Email hello@norc.app");
|
|
44976
|
+
return lines;
|
|
44977
|
+
};
|
|
44978
|
+
const healthPanel = () => {
|
|
44979
|
+
const rate = successRate(s.totals);
|
|
44980
|
+
const big = formatPercent(rate).split("").map((ch) => (BIG[ch] ?? [" ", " ", " "]).map((r) => opts.unicode ? r : [...r].map((c) => ASCII_MAP[c] ?? c).join("")));
|
|
44981
|
+
const rows = [0, 1, 2].map((i) => big.map((b) => b[i]).join(" "));
|
|
44982
|
+
const rc = rate >= 99 ? green : rate >= 95 ? amber : red;
|
|
44983
|
+
const chip = streakChip(s, now);
|
|
44984
|
+
const out2 = [title(`Health \xB7 ${s.days} days`, colW)];
|
|
44985
|
+
rows.forEach((r, i) => out2.push(`${rc(padR(r, 20))} ${i === 1 ? dim("success rate") : ""}`));
|
|
44986
|
+
out2.push("");
|
|
44987
|
+
out2.push(`${cyan(spark(dailyRates(s.daily)))} ${dim("daily success")}`);
|
|
44988
|
+
const cap = rateCaption(s.daily);
|
|
44989
|
+
if (cap) out2.push(dim(cap));
|
|
44990
|
+
if (chip.kind !== "none") out2.push((chip.kind === "streak" ? green : amber)(trunc(cleanLabel(chip.text), colW, opts.unicode)));
|
|
44991
|
+
out2.push(`${formatCount(totalRuns(s.totals))} runs \xB7 ${red(`${s.totals.failed} failed`)} \xB7 ${amber(`${s.totals.missed} missed`)} \xB7 median ${medianText(s.medianDurationSeconds)}`);
|
|
44992
|
+
return out2;
|
|
44993
|
+
};
|
|
44994
|
+
const runsPanel = () => {
|
|
44995
|
+
const H = 8;
|
|
44996
|
+
const days = s.daily;
|
|
44997
|
+
const plotW = W - 6;
|
|
44998
|
+
const colWd = Math.max(1, Math.min(6, Math.floor(plotW / days.length)));
|
|
44999
|
+
const barW = colWd >= 3 ? colWd - 1 : 1;
|
|
45000
|
+
const max = Math.max(1, ...days.map(totalRuns));
|
|
45001
|
+
const segs = days.map((d) => {
|
|
45002
|
+
const t = totalRuns(d);
|
|
45003
|
+
const h = t ? Math.max(1, Math.round(t / max * H)) : 0;
|
|
45004
|
+
const f = d.failed ? 1 : 0, m = d.missed ? 1 : 0;
|
|
45005
|
+
const f2 = d.failed ? Math.max(f, Math.round(d.failed / t * h)) : 0;
|
|
45006
|
+
const m2 = d.missed ? Math.max(m, Math.round(d.missed / t * h)) : 0;
|
|
45007
|
+
return { ok: Math.max(0, h - f2 - m2), failed: f2, missed: m2 };
|
|
45008
|
+
});
|
|
45009
|
+
const cell = (sg, r) => {
|
|
45010
|
+
const fromBottom = H - 1 - r;
|
|
45011
|
+
if (fromBottom < sg.ok) return green(g.ok.repeat(barW));
|
|
45012
|
+
if (fromBottom < sg.ok + sg.failed) return red(g.failed.repeat(barW));
|
|
45013
|
+
if (fromBottom < sg.ok + sg.failed + sg.missed) return amber(g.missed.repeat(barW));
|
|
45014
|
+
return " ".repeat(barW);
|
|
45015
|
+
};
|
|
45016
|
+
const lines = [title(`Runs per day \xB7 ${s.days} days`, W)];
|
|
45017
|
+
for (let r = 0; r < H; r++) {
|
|
45018
|
+
const label = r === 0 ? String(max) : r === H - 1 ? "0" : "";
|
|
45019
|
+
const body = segs.map((sg) => cell(sg, r) + " ".repeat(colWd - barW)).join("");
|
|
45020
|
+
lines.push(`${dim(padL(label, 4))} ${dim(g.cap)}${body}`);
|
|
45021
|
+
}
|
|
45022
|
+
const axis = Array.from({ length: days.length * colWd }, () => " ");
|
|
45023
|
+
const step = Math.ceil(6 / colWd);
|
|
45024
|
+
for (let i = 0; i < days.length; i += step) {
|
|
45025
|
+
const lab = days[i].date.slice(5);
|
|
45026
|
+
if (i * colWd + lab.length > axis.length) break;
|
|
45027
|
+
lab.split("").forEach((c, k) => {
|
|
45028
|
+
axis[i * colWd + k] = c;
|
|
45029
|
+
});
|
|
45030
|
+
}
|
|
45031
|
+
lines.push(`${" ".repeat(5)}${dim(opts.unicode ? "\u2514" : "+")}${dim(axis.join(""))}`);
|
|
45032
|
+
lines.push(` ${green(g.ok)} ok ${red(g.failed)} failed ${amber(g.missed)} missed`);
|
|
45033
|
+
lines.push(...wrap(runsSummarySentence(s.daily, s.days), W).map(dim));
|
|
45034
|
+
return lines;
|
|
45035
|
+
};
|
|
45036
|
+
const heatPanel = () => {
|
|
45037
|
+
const { cells } = heatCells(s.heatmap);
|
|
45038
|
+
const names = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
45039
|
+
const lines = [title("Activity \xB7 hour of day (UTC)", colW)];
|
|
45040
|
+
const ramp = [dim, cyan, cyan, cyan, bold];
|
|
45041
|
+
const cw = colW >= 54 ? 2 : 1;
|
|
45042
|
+
for (let r = 0; r < 7; r++) {
|
|
45043
|
+
const row = cells.slice(r * 24, r * 24 + 24).map((c) => ramp[c.level](g.heat[c.level].repeat(cw))).join("");
|
|
45044
|
+
lines.push(`${dim(names[r])} ${row}`);
|
|
45045
|
+
}
|
|
45046
|
+
const hours = Array.from({ length: 24 * cw + 2 }, () => " ");
|
|
45047
|
+
for (let h = 0; h < 24; h += cw === 2 ? 3 : 4) String(h).padStart(2, "0").split("").forEach((c, k) => {
|
|
45048
|
+
hours[h * cw + k] = c;
|
|
45049
|
+
});
|
|
45050
|
+
lines.push(` ${dim(hours.join(""))}`);
|
|
45051
|
+
lines.push(...wrap(empty ? "No runs yet." : heatSummary(s.heatmap), colW).map(dim));
|
|
45052
|
+
lines.push(dim(`less ${g.heat.join(" ")} more`));
|
|
45053
|
+
return lines;
|
|
45054
|
+
};
|
|
45055
|
+
const topPanel = () => {
|
|
45056
|
+
const rows = topFailingRows(s.topFailingJobs);
|
|
45057
|
+
const lines = [title("Top failing jobs", colW)];
|
|
45058
|
+
if (!rows.length) return [...lines, green("No failing jobs. Nice.")];
|
|
45059
|
+
const cw = Math.max(...rows.map((r) => r.counts.length));
|
|
45060
|
+
const nameW = Math.max(10, colW - 3 - 9 - cw - 2);
|
|
45061
|
+
for (const r of rows.slice(0, 6)) {
|
|
45062
|
+
const fill = Math.max(1, Math.round(r.pct / 100 * 8));
|
|
45063
|
+
const mn = trunc(cleanLabel(r.machineName), Math.max(4, Math.floor(nameW / 2)), opts.unicode);
|
|
45064
|
+
const label = trunc(cleanLabel(r.jobName), nameW - mn.length - 3, opts.unicode);
|
|
45065
|
+
lines.push(`${padL(String(r.rank), 2)} ${padR(`${label} ${dim(`(${mn})`)}`, nameW)} ${red(g.full.repeat(fill))}${dim(g.empty.repeat(8 - fill))} ${r.counts}`);
|
|
45066
|
+
}
|
|
45067
|
+
return lines;
|
|
45068
|
+
};
|
|
45069
|
+
const machinePanel = () => {
|
|
45070
|
+
const lines = [title("Machines", W)];
|
|
45071
|
+
const rows = machineRows(s.machines);
|
|
45072
|
+
if (!rows.length) return [...lines, dim("No machines yet. Run `norc pair` to add this one.")];
|
|
45073
|
+
for (const m of rows) {
|
|
45074
|
+
const nm = trunc(cleanLabel(m.env ? `${m.name} ${m.env}` : m.name), 18, opts.unicode);
|
|
45075
|
+
lines.push(`${padR(nm, 18)} ${cyan(spark(m.rates))} ${padL(m.rateText, 6)} ${dim(m.counts)}`);
|
|
45076
|
+
}
|
|
45077
|
+
return lines;
|
|
45078
|
+
};
|
|
45079
|
+
const ghostRuns = () => {
|
|
45080
|
+
const lines = [title(`Runs per day \xB7 ${s.days} days`, W)];
|
|
45081
|
+
const pat = [2, 4, 3, 6, 5, 7, 4, 6, 3, 5];
|
|
45082
|
+
for (let r = 0; r < 4; r++) lines.push(` ${dim(g.cap)}${dim(Array.from({ length: s.days }, (_, i) => (pat[i % pat.length] > 3 - r + 3 ? g.empty : " ").repeat(2)).join(""))}`);
|
|
45083
|
+
return lines;
|
|
45084
|
+
};
|
|
45085
|
+
const side = (l, r) => {
|
|
45086
|
+
const n = Math.max(l.length, r.length);
|
|
45087
|
+
return Array.from({ length: n }, (_, i) => `${padR(l[i] ?? "", colW)} ${r[i] ?? ""}`.trimEnd());
|
|
45088
|
+
};
|
|
45089
|
+
const pair = (l, r) => wide ? side(l, r) : [...l, "", ...r];
|
|
45090
|
+
const head2 = `${bold("norc usage")} ${dim(`${g.dot} last ${s.days} days ${g.dot} ${PLAN_NAMES[s.plan]} plan ${g.dot} ${s.generatedAt.slice(0, 16).replace("T", " ")}Z`)}`;
|
|
45091
|
+
const out = [head2, dim(g.rule.repeat(W)), ""];
|
|
45092
|
+
if (empty) {
|
|
45093
|
+
out.push(...headroomPanel(), "", ...ghostRuns(), "", ...heatPanel(), "", ...machinePanel(), "", bold("Your first run will show up here."));
|
|
45094
|
+
} else {
|
|
45095
|
+
out.push(...pair(headroomPanel(), healthPanel()), "", ...runsPanel(), "", ...pair(heatPanel(), topPanel()), "", ...machinePanel());
|
|
45096
|
+
}
|
|
45097
|
+
const text = out.map((l) => l.trimEnd()).join("\n") + "\n";
|
|
45098
|
+
return opts.unicode ? text : text.replace(/·/g, ".").replace(/—/g, "-").replace(/…/g, "~");
|
|
45099
|
+
}
|
|
45100
|
+
|
|
45101
|
+
// src/commands/usage.ts
|
|
45102
|
+
var USAGE2 = "usage: norc usage [--days 7|30] [--json] [--no-color] [--plain]";
|
|
45103
|
+
function utf8Locale(env, platform2) {
|
|
45104
|
+
const loc = env.LC_ALL || env.LC_CTYPE || env.LANG || "";
|
|
45105
|
+
return /utf-?8/i.test(loc) || platform2 === "win32" && Boolean(env.WT_SESSION);
|
|
45106
|
+
}
|
|
45107
|
+
async function cmdUsage(args, deps, log = console.log, err = console.error) {
|
|
45108
|
+
const known = /* @__PURE__ */ new Set(["--days", "--json", "--no-color", "--plain"]);
|
|
45109
|
+
let days = 30;
|
|
45110
|
+
for (let i = 0; i < args.length; i++) {
|
|
45111
|
+
const a = args[i];
|
|
45112
|
+
if (a === "--days") {
|
|
45113
|
+
const v = Number(args[++i]);
|
|
45114
|
+
if (v !== 7 && v !== 30) {
|
|
45115
|
+
err(`error: --days must be 7 or 30
|
|
45116
|
+
${USAGE2}`);
|
|
45117
|
+
return 2;
|
|
45118
|
+
}
|
|
45119
|
+
days = v;
|
|
45120
|
+
} else if (!known.has(a)) {
|
|
45121
|
+
err(`error: unknown option ${a}
|
|
45122
|
+
${USAGE2}`);
|
|
45123
|
+
return 2;
|
|
45124
|
+
}
|
|
45125
|
+
}
|
|
45126
|
+
const jwt = await deps.getJwt();
|
|
45127
|
+
if (!jwt) {
|
|
45128
|
+
err("error: this machine is not paired. Run `norc login`, then `norc pair`.");
|
|
45129
|
+
return 1;
|
|
45130
|
+
}
|
|
45131
|
+
let summary;
|
|
45132
|
+
try {
|
|
45133
|
+
summary = await fetchUsageDevice({ functionsUrl: deps.functionsUrl, deviceJwt: jwt, days, fetchImpl: deps.fetchImpl });
|
|
45134
|
+
} catch (e) {
|
|
45135
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
45136
|
+
if (/HTTP 404/.test(m)) err("error: the usage service is not available yet (device-usage is not deployed on this backend).");
|
|
45137
|
+
else if (/HTTP 401|HTTP 403/.test(m)) err("error: this machine is not authorised. Run `norc login`, then `norc pair`.");
|
|
45138
|
+
else if (/HTTP \d+/.test(m)) err(`error: ${m}`);
|
|
45139
|
+
else err(`error: could not reach norc (${m}). Check your connection and try again.`);
|
|
45140
|
+
return 1;
|
|
45141
|
+
}
|
|
45142
|
+
if (args.includes("--json")) {
|
|
45143
|
+
log(JSON.stringify(parseUsageSummary(summary), null, 2));
|
|
45144
|
+
return 0;
|
|
45145
|
+
}
|
|
45146
|
+
const color = deps.isTTY && !args.includes("--no-color") && !deps.env.NO_COLOR;
|
|
45147
|
+
const unicode = !args.includes("--plain") && utf8Locale(deps.env, deps.platform);
|
|
45148
|
+
log(renderUsage(summary, { width: deps.columns, color, unicode, vaultUrl: deps.vaultUrl }).trimEnd());
|
|
45149
|
+
return 0;
|
|
45150
|
+
}
|
|
45151
|
+
|
|
45152
|
+
// src/paired-device.ts
|
|
45153
|
+
async function savePairedDevice(device, cfgPath = configPath(), cachePath = envCachePath()) {
|
|
45154
|
+
await saveConfig({ device }, cfgPath, { keys: ["device"] });
|
|
45155
|
+
await clearEnvCache(cachePath);
|
|
45156
|
+
}
|
|
45157
|
+
|
|
45158
|
+
// src/user-session.ts
|
|
45159
|
+
var NO_USER_SESSION = "no user session on this machine: `norc env` needs one, and an API-key login only pairs the machine. Run `norc login --email <your-email>` (the pairing is kept).";
|
|
45160
|
+
function requireUserSession(config) {
|
|
45161
|
+
if (!config.session) throw new Error(NO_USER_SESSION);
|
|
45162
|
+
return config.session;
|
|
45163
|
+
}
|
|
45164
|
+
async function saveUserSession(session, path = configPath()) {
|
|
45165
|
+
await saveConfig({ session }, path, { keys: ["session"] });
|
|
45166
|
+
}
|
|
45167
|
+
async function logout(path = configPath(), cachePath = envCachePath(), opts = {}) {
|
|
45168
|
+
const config = await loadConfig(path);
|
|
45169
|
+
const had = { session: Boolean(config.session), device: Boolean(config.device) };
|
|
45170
|
+
if (config.session && opts.signOut) {
|
|
45171
|
+
let timer;
|
|
45172
|
+
await Promise.race([
|
|
45173
|
+
opts.signOut(config.session).catch(() => {
|
|
45174
|
+
}),
|
|
45175
|
+
new Promise((r) => {
|
|
45176
|
+
timer = setTimeout(r, opts.timeoutMs ?? 5e3);
|
|
45177
|
+
})
|
|
45178
|
+
]).catch(() => {
|
|
45179
|
+
});
|
|
45180
|
+
clearTimeout(timer);
|
|
45181
|
+
}
|
|
45182
|
+
await saveConfig({}, path, { keys: ["session", "device"], sweepAll: true });
|
|
45183
|
+
await clearEnvCache(cachePath);
|
|
45184
|
+
return had;
|
|
45185
|
+
}
|
|
45186
|
+
|
|
43794
45187
|
// src/commands/bridge.ts
|
|
43795
|
-
var
|
|
45188
|
+
var import_node_child_process6 = require("node:child_process");
|
|
45189
|
+
var import_node_crypto3 = require("node:crypto");
|
|
43796
45190
|
|
|
43797
45191
|
// src/enc-key.ts
|
|
43798
45192
|
async function loadOrCreateEncKey(config, persist) {
|
|
@@ -43804,27 +45198,19 @@ async function loadOrCreateEncKey(config, persist) {
|
|
|
43804
45198
|
}
|
|
43805
45199
|
|
|
43806
45200
|
// src/capability-key.ts
|
|
43807
|
-
var
|
|
43808
|
-
kty: "EC",
|
|
43809
|
-
crv: "P-256",
|
|
43810
|
-
alg: "ES256",
|
|
43811
|
-
use: "sig",
|
|
43812
|
-
kid: "09621c79-698f-4328-bdac-1c347546708e",
|
|
43813
|
-
x: "yRbJAsSJpAtBBWIXUg_5tVi0n574uZjComtLR9O6Jwk",
|
|
43814
|
-
y: "dVHs6ZeMH10d6IypZgM2-Q9i18_bf_Jj8vsybRPX0Fk"
|
|
43815
|
-
};
|
|
45201
|
+
var CAPABILITY_TRUSTED_KEYS = activeTrustedKeys();
|
|
43816
45202
|
|
|
43817
45203
|
// src/dupe-check.ts
|
|
43818
|
-
var
|
|
43819
|
-
var
|
|
45204
|
+
var import_promises4 = require("node:fs/promises");
|
|
45205
|
+
var import_node_child_process5 = require("node:child_process");
|
|
43820
45206
|
var import_node_util = require("node:util");
|
|
43821
|
-
var execFileAsync = (0, import_node_util.promisify)(
|
|
45207
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process5.execFile);
|
|
43822
45208
|
function defaultDupeCheckDeps() {
|
|
43823
45209
|
return {
|
|
43824
45210
|
platform: process.platform,
|
|
43825
45211
|
fileExists: async (p) => {
|
|
43826
45212
|
try {
|
|
43827
|
-
await (0,
|
|
45213
|
+
await (0, import_promises4.access)(p);
|
|
43828
45214
|
return true;
|
|
43829
45215
|
} catch {
|
|
43830
45216
|
return false;
|
|
@@ -43868,25 +45254,12 @@ async function checkForDesktopInstall(deps = defaultDupeCheckDeps()) {
|
|
|
43868
45254
|
return found ? WARNING : null;
|
|
43869
45255
|
}
|
|
43870
45256
|
|
|
43871
|
-
// src/machines.ts
|
|
43872
|
-
async function syncJobs(sb, entries) {
|
|
43873
|
-
const jobs = jobsOf(entries).filter((j) => typeof j.id === "string").map((j) => ({
|
|
43874
|
-
id: j.id,
|
|
43875
|
-
name: j.name ?? "",
|
|
43876
|
-
schedule: j.schedule,
|
|
43877
|
-
command: j.command,
|
|
43878
|
-
enabled: j.enabled ?? true
|
|
43879
|
-
}));
|
|
43880
|
-
const { error } = await sb.rpc("sync_account_jobs", { p_jobs: jobs, p_authoritative_empty: true });
|
|
43881
|
-
if (error) throw new Error(error.message);
|
|
43882
|
-
}
|
|
43883
|
-
|
|
43884
45257
|
// src/crontab-changes.ts
|
|
43885
45258
|
var import_node_fs2 = require("node:fs");
|
|
43886
|
-
var
|
|
43887
|
-
var
|
|
45259
|
+
var import_node_path5 = require("node:path");
|
|
45260
|
+
var import_node_os6 = require("node:os");
|
|
43888
45261
|
function crontabChangesPath() {
|
|
43889
|
-
return (0,
|
|
45262
|
+
return (0, import_node_path5.join)((0, import_node_os6.homedir)(), ".config", "norc", "crontab-changes.json");
|
|
43890
45263
|
}
|
|
43891
45264
|
function fileChangeStore(path) {
|
|
43892
45265
|
return {
|
|
@@ -43898,7 +45271,7 @@ function fileChangeStore(path) {
|
|
|
43898
45271
|
}
|
|
43899
45272
|
},
|
|
43900
45273
|
save: (v) => {
|
|
43901
|
-
(0, import_node_fs2.mkdirSync)((0,
|
|
45274
|
+
(0, import_node_fs2.mkdirSync)((0, import_node_path5.dirname)(path), { recursive: true, mode: 448 });
|
|
43902
45275
|
(0, import_node_fs2.writeFileSync)(path, v, { mode: 384 });
|
|
43903
45276
|
}
|
|
43904
45277
|
};
|
|
@@ -43916,56 +45289,137 @@ function trackLineChanges(io, path = crontabChangesPath()) {
|
|
|
43916
45289
|
};
|
|
43917
45290
|
}
|
|
43918
45291
|
|
|
45292
|
+
// src/remote-consent.ts
|
|
45293
|
+
var import_node_os7 = require("node:os");
|
|
45294
|
+
var import_promises5 = require("node:readline/promises");
|
|
45295
|
+
function sanitize(s, max = 160) {
|
|
45296
|
+
const clean2 = s.replace(/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff\u{e0000}-\u{e007f}]/gu, " ").trim();
|
|
45297
|
+
return clean2.length > max ? `${clean2.slice(0, max)}\u2026` : clean2;
|
|
45298
|
+
}
|
|
45299
|
+
function diffLines(before, after) {
|
|
45300
|
+
const eff = (t) => t.split("\n").map((l) => l.trimEnd()).filter((l) => l.trim() !== "");
|
|
45301
|
+
const only = (x, y) => {
|
|
45302
|
+
const left = /* @__PURE__ */ new Map();
|
|
45303
|
+
for (const l of y) left.set(l, (left.get(l) ?? 0) + 1);
|
|
45304
|
+
return x.filter((l) => {
|
|
45305
|
+
const n = left.get(l) ?? 0;
|
|
45306
|
+
if (n > 0) {
|
|
45307
|
+
left.set(l, n - 1);
|
|
45308
|
+
return false;
|
|
45309
|
+
}
|
|
45310
|
+
return true;
|
|
45311
|
+
});
|
|
45312
|
+
};
|
|
45313
|
+
const b = eff(before), a = eff(after);
|
|
45314
|
+
return { added: only(a, b), removed: only(b, a) };
|
|
45315
|
+
}
|
|
45316
|
+
function remoteEnabled(config) {
|
|
45317
|
+
return config.remote?.enabled === true;
|
|
45318
|
+
}
|
|
45319
|
+
function decideWrite(config, before, after, log = console.log) {
|
|
45320
|
+
const { added, removed } = diffLines(before, after);
|
|
45321
|
+
const eff = (t) => t.split("\n").map((l) => l.trimEnd()).filter((l) => l.trim() !== "");
|
|
45322
|
+
const reordered = added.length === 0 && removed.length === 0 && eff(before).join("\n") !== eff(after).join("\n");
|
|
45323
|
+
if (added.length === 0 && removed.length === 0 && !reordered) return true;
|
|
45324
|
+
if (!remoteEnabled(config)) {
|
|
45325
|
+
log("[norc bridge] remote change refused: remote writes are disabled on this host. Run `norc remote enable` to allow them.");
|
|
45326
|
+
return false;
|
|
45327
|
+
}
|
|
45328
|
+
if (reordered) log(`[norc bridge] remote change (${sanitize(config.remote?.account ?? "", 80)}) reordered existing lines`);
|
|
45329
|
+
for (const l of added.slice(0, 20)) log(`[norc bridge] remote change (${sanitize(config.remote?.account ?? "", 80)}) + ${sanitize(l)}`);
|
|
45330
|
+
for (const l of removed.slice(0, 20)) log(`[norc bridge] remote change (${sanitize(config.remote?.account ?? "", 80)}) - ${sanitize(l)}`);
|
|
45331
|
+
return true;
|
|
45332
|
+
}
|
|
45333
|
+
async function cmdRemote(args, config, save, io = defaultIo()) {
|
|
45334
|
+
const sub = args[0] ?? "status";
|
|
45335
|
+
if (sub === "status") {
|
|
45336
|
+
io.log(remoteEnabled(config) ? `remote writes: enabled for ${config.remote?.account} since ${config.remote?.enabledAt}` : "remote writes: disabled");
|
|
45337
|
+
return;
|
|
45338
|
+
}
|
|
45339
|
+
if (sub === "disable") {
|
|
45340
|
+
config.remote = { enabled: false, account: config.remote?.account ?? "", enabledAt: "" };
|
|
45341
|
+
await save(config);
|
|
45342
|
+
io.log("remote writes disabled.");
|
|
45343
|
+
return;
|
|
45344
|
+
}
|
|
45345
|
+
if (sub !== "enable") throw new Error("usage: norc remote enable|disable|status");
|
|
45346
|
+
const account = config.session?.email ?? "the account this machine is paired to";
|
|
45347
|
+
io.log(`This allows ${account} (via norc web, mobile, desktop, MCP or API keys) to read and write this machine's crontab and run jobs on ${(0, import_node_os7.hostname)()} as the current user.`);
|
|
45348
|
+
io.log("Every remote change is logged here with the exact command. Disable any time with `norc remote disable`.");
|
|
45349
|
+
if (!args.includes("--yes")) {
|
|
45350
|
+
if (!io.isTTY) throw new Error("not interactive: re-run in a terminal, or pass --yes");
|
|
45351
|
+
if ((await io.ask("Allow remote writes? [y/N] ")).toLowerCase() !== "y") {
|
|
45352
|
+
io.log("left disabled.");
|
|
45353
|
+
return;
|
|
45354
|
+
}
|
|
45355
|
+
}
|
|
45356
|
+
config.remote = { enabled: true, account, enabledAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
45357
|
+
await save(config);
|
|
45358
|
+
io.log("remote writes enabled.");
|
|
45359
|
+
}
|
|
45360
|
+
function defaultIo() {
|
|
45361
|
+
return {
|
|
45362
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
45363
|
+
log: (m) => console.log(m),
|
|
45364
|
+
ask: async (q) => {
|
|
45365
|
+
const rl = (0, import_promises5.createInterface)({ input: process.stdin, output: process.stdout });
|
|
45366
|
+
try {
|
|
45367
|
+
return (await rl.question(q)).trim();
|
|
45368
|
+
} finally {
|
|
45369
|
+
rl.close();
|
|
45370
|
+
}
|
|
45371
|
+
}
|
|
45372
|
+
};
|
|
45373
|
+
}
|
|
45374
|
+
|
|
43919
45375
|
// src/commands/bridge.ts
|
|
43920
|
-
var READ_ONLY = ["ping", "read_crontab", "list_jobs"];
|
|
45376
|
+
var READ_ONLY = ["ping", "read_crontab", "list_jobs", "read_managed", "crontab_hash"];
|
|
43921
45377
|
var MAX_REMEMBERED_NONCES = 20;
|
|
43922
|
-
function
|
|
45378
|
+
function replayGuard(config, machineId, persist) {
|
|
43923
45379
|
return {
|
|
43924
|
-
machineId,
|
|
43925
|
-
nowSec: () => Math.floor(Date.now() / 1e3),
|
|
43926
|
-
publicJwk: CAPABILITY_PUBLIC_JWK,
|
|
43927
|
-
lastGeneration: () => config.bridge?.generation ?? 0,
|
|
45380
|
+
lastGeneration: () => replayFor(config, machineId).generation,
|
|
43928
45381
|
setGeneration: (g) => {
|
|
43929
|
-
config.
|
|
45382
|
+
replayFor(config, machineId).generation = g;
|
|
43930
45383
|
persist(config);
|
|
43931
45384
|
},
|
|
43932
|
-
seenNonce: (n) => (config
|
|
45385
|
+
seenNonce: (n) => replayFor(config, machineId).nonces.includes(n),
|
|
43933
45386
|
rememberNonce: (n) => {
|
|
43934
|
-
const
|
|
43935
|
-
|
|
45387
|
+
const r = replayFor(config, machineId);
|
|
45388
|
+
r.nonces = [...r.nonces, n].slice(-MAX_REMEMBERED_NONCES);
|
|
43936
45389
|
persist(config);
|
|
45390
|
+
}
|
|
45391
|
+
};
|
|
45392
|
+
}
|
|
45393
|
+
function buildWriteIntentDeps(config, machineId, crontabIo, persist, refresh = async () => {
|
|
45394
|
+
}, envNames) {
|
|
45395
|
+
return {
|
|
45396
|
+
machineId,
|
|
45397
|
+
envNames,
|
|
45398
|
+
nowSec: () => Math.floor(Date.now() / 1e3),
|
|
45399
|
+
publicJwk: CAPABILITY_TRUSTED_KEYS,
|
|
45400
|
+
...replayGuard(config, machineId, persist),
|
|
45401
|
+
// NAT-002: headless hosts have no one to click a dialog, so the local opt-in
|
|
45402
|
+
// (`norc remote enable`, stored in the 0600 config) is the consent; every
|
|
45403
|
+
// applied change is logged with its exact diff. Default is OFF.
|
|
45404
|
+
requestConsent: async ({ before, after }) => {
|
|
45405
|
+
await refresh(config);
|
|
45406
|
+
return decideWrite(config, before, after);
|
|
43937
45407
|
},
|
|
43938
|
-
// ponytail: no human at a keyboard for a headless server — pairing itself
|
|
43939
|
-
// (`norc pair`, claimed from the account owner's web vault) IS the consent
|
|
43940
|
-
// to be remotely administered from then on. Desktop gates writes on a
|
|
43941
|
-
// native Yes/No dialog because a person might be sitting at that machine;
|
|
43942
|
-
// that threat model doesn't apply to an unattended box, so every
|
|
43943
|
-
// capability-verified write (already authorized server-side by the
|
|
43944
|
-
// device-command edge fn) is auto-approved here. Upgrade path if that
|
|
43945
|
-
// changes: a --require-consent flag gating on an interactive prompt.
|
|
43946
|
-
consentGranted: () => true,
|
|
43947
|
-
requestConsent: async () => true,
|
|
43948
45408
|
readCrontab: () => crontabIo.read(),
|
|
43949
45409
|
writeCrontab: (c) => crontabIo.write(c)
|
|
43950
45410
|
};
|
|
43951
45411
|
}
|
|
43952
|
-
function buildRawWriteIntentDeps(config, machineId, crontabIo, persist) {
|
|
45412
|
+
function buildRawWriteIntentDeps(config, machineId, crontabIo, persist, refresh = async () => {
|
|
45413
|
+
}) {
|
|
43953
45414
|
return {
|
|
43954
45415
|
machineId,
|
|
43955
45416
|
nowSec: () => Math.floor(Date.now() / 1e3),
|
|
43956
|
-
publicJwk:
|
|
43957
|
-
|
|
43958
|
-
|
|
43959
|
-
|
|
43960
|
-
|
|
45417
|
+
publicJwk: CAPABILITY_TRUSTED_KEYS,
|
|
45418
|
+
...replayGuard(config, machineId, persist),
|
|
45419
|
+
requestRawConsent: async ({ before, after }) => {
|
|
45420
|
+
await refresh(config);
|
|
45421
|
+
return decideWrite(config, before, after);
|
|
43961
45422
|
},
|
|
43962
|
-
seenNonce: (n) => (config.bridge?.nonces ?? []).includes(n),
|
|
43963
|
-
rememberNonce: (n) => {
|
|
43964
|
-
const nonces = [...config.bridge?.nonces ?? [], n].slice(-MAX_REMEMBERED_NONCES);
|
|
43965
|
-
config.bridge = { generation: config.bridge?.generation ?? 0, nonces, executeNonces: config.bridge?.executeNonces };
|
|
43966
|
-
persist(config);
|
|
43967
|
-
},
|
|
43968
|
-
requestRawConsent: async () => true,
|
|
43969
45423
|
readCrontab: () => crontabIo.read(),
|
|
43970
45424
|
writeCrontab: (c) => crontabIo.write(c)
|
|
43971
45425
|
};
|
|
@@ -43975,16 +45429,29 @@ function projectJobsRemoved(currentCrontab, jobIds) {
|
|
|
43975
45429
|
const remaining = jobsOf(parseCrontab(currentCrontab)).filter((j) => typeof j.id === "string" && !jobIds.includes(j.id)).map((j) => ({ ...j, name: j.name ?? "", enabled: j.enabled ?? true, createdAt: now, updatedAt: now }));
|
|
43976
45430
|
return renderJobsToCrontab(currentCrontab, remaining);
|
|
43977
45431
|
}
|
|
45432
|
+
async function confirmJobsGone(sb, ids) {
|
|
45433
|
+
const { data, error } = await sb.rpc("get_live_job_ids", {});
|
|
45434
|
+
if (error || !Array.isArray(data)) return [];
|
|
45435
|
+
const live = new Set(data.map((r) => r.job_id));
|
|
45436
|
+
return ids.filter((id) => !live.has(id));
|
|
45437
|
+
}
|
|
43978
45438
|
function findManagedJob(currentCrontab, jobId) {
|
|
43979
|
-
const
|
|
43980
|
-
return
|
|
45439
|
+
const entry = parseCrontab(currentCrontab).find((e) => e.kind === "job" && e.id === jobId);
|
|
45440
|
+
return entry ? { id: jobId, command: unwrapCommand(entry.command), envNames: wrappedEnvNames(entry.command) ?? [] } : null;
|
|
45441
|
+
}
|
|
45442
|
+
function reprojectEnvNames(currentCrontab, names) {
|
|
45443
|
+
const want = /* @__PURE__ */ new Map();
|
|
45444
|
+
for (const e of parseCrontab(currentCrontab)) {
|
|
45445
|
+
if (e.kind === "job" && e.id !== void 0) want.set(e.id, Object.hasOwn(names, e.id) ? names[e.id] : []);
|
|
45446
|
+
}
|
|
45447
|
+
return rewriteEnvNames(currentCrontab, want);
|
|
43981
45448
|
}
|
|
43982
45449
|
function pruneExpiredExecuteNonces(nonces, nowSec) {
|
|
43983
45450
|
return (nonces ?? []).filter((n) => n.expiresAt >= nowSec);
|
|
43984
45451
|
}
|
|
43985
45452
|
function spawnWrappedCommand(command) {
|
|
43986
45453
|
return new Promise((resolve, reject) => {
|
|
43987
|
-
const child = (0,
|
|
45454
|
+
const child = (0, import_node_child_process6.spawn)(withoutPkgEnv(command), { shell: true, detached: true, stdio: "ignore" });
|
|
43988
45455
|
child.once("spawn", () => {
|
|
43989
45456
|
child.unref();
|
|
43990
45457
|
resolve();
|
|
@@ -44007,7 +45474,6 @@ async function runBridge(env, crontabIo) {
|
|
|
44007
45474
|
await logStartupWarnings();
|
|
44008
45475
|
const config = await loadConfig();
|
|
44009
45476
|
if (!config.device) throw new Error("not paired \u2014 run `norc pair` first");
|
|
44010
|
-
const { machineId } = config.device;
|
|
44011
45477
|
const lineChanges = trackLineChanges(crontabIo);
|
|
44012
45478
|
void lineChanges.look();
|
|
44013
45479
|
setInterval(() => {
|
|
@@ -44015,7 +45481,7 @@ async function runBridge(env, crontabIo) {
|
|
|
44015
45481
|
}, 3e4);
|
|
44016
45482
|
let configSaveChain = Promise.resolve();
|
|
44017
45483
|
const persistConfig = () => {
|
|
44018
|
-
const save = configSaveChain.then(() => saveConfig(config));
|
|
45484
|
+
const save = configSaveChain.then(() => saveConfig(config, void 0, { keys: ["bridge", "enc"] }));
|
|
44019
45485
|
configSaveChain = save.catch(() => {
|
|
44020
45486
|
});
|
|
44021
45487
|
return save;
|
|
@@ -44023,12 +45489,43 @@ async function runBridge(env, crontabIo) {
|
|
|
44023
45489
|
const keyPair = await loadOrCreateEncKey(config, persistConfig);
|
|
44024
45490
|
let state = "disconnected";
|
|
44025
45491
|
let attempt = 0;
|
|
45492
|
+
let idleLogged = false;
|
|
44026
45493
|
while (true) {
|
|
45494
|
+
const onDisk = await readIdentity();
|
|
45495
|
+
if (onDisk === null) {
|
|
45496
|
+
if (!idleLogged) console.log("[norc bridge] no paired device (logged out?): idle, run `norc pair` to resume");
|
|
45497
|
+
idleLogged = true;
|
|
45498
|
+
await wait(IDLE_POLL_MS);
|
|
45499
|
+
continue;
|
|
45500
|
+
}
|
|
45501
|
+
idleLogged = false;
|
|
45502
|
+
if (onDisk) config.device = onDisk;
|
|
45503
|
+
const machineId = config.device.machineId;
|
|
45504
|
+
const builtFor = identityKey(config.device);
|
|
45505
|
+
let identityChanged = false;
|
|
45506
|
+
let endCycle = () => {
|
|
45507
|
+
};
|
|
45508
|
+
const stillCurrent = async () => {
|
|
45509
|
+
const id = await readIdentity();
|
|
45510
|
+
return id === void 0 || identityKey(id) === builtFor;
|
|
45511
|
+
};
|
|
45512
|
+
const watchIdentity = async () => {
|
|
45513
|
+
if (identityChanged) return false;
|
|
45514
|
+
if (await stillCurrent()) return true;
|
|
45515
|
+
identityChanged = true;
|
|
45516
|
+
console.log("[norc bridge] device identity changed on disk: reconnecting");
|
|
45517
|
+
endCycle();
|
|
45518
|
+
return false;
|
|
45519
|
+
};
|
|
44027
45520
|
let sb = null;
|
|
44028
45521
|
let heartbeat = null;
|
|
45522
|
+
let envRefresh = null;
|
|
44029
45523
|
const enqueueSync = serialize();
|
|
44030
45524
|
const queueSyncJobs = () => enqueueSync(() => syncJobsQuiet(sb, crontabIo));
|
|
44031
|
-
const
|
|
45525
|
+
const enqueueRaw = serialize();
|
|
45526
|
+
const enqueueMutation = (task) => enqueueRaw(async () => {
|
|
45527
|
+
if (await watchIdentity()) await task();
|
|
45528
|
+
});
|
|
44032
45529
|
try {
|
|
44033
45530
|
state = reduceConn(state, "connect");
|
|
44034
45531
|
const sess = await deviceSession(env.supabaseUrl, env.anonKey, void 0, keyPair.publicJwk);
|
|
@@ -44051,9 +45548,13 @@ async function runBridge(env, crontabIo) {
|
|
|
44051
45548
|
keyPair,
|
|
44052
45549
|
onDrop: (event) => console.warn("[norc bridge] dropped unauthenticated relay payload on", event)
|
|
44053
45550
|
});
|
|
44054
|
-
serveBridge(new SealedBridgeTransport(sec), lineChanges.io, { allow: [...READ_ONLY]
|
|
44055
|
-
|
|
44056
|
-
|
|
45551
|
+
serveBridge(new SealedBridgeTransport(sec), lineChanges.io, { allow: [...READ_ONLY], authorize: fullReadGate(async () => {
|
|
45552
|
+
await refreshRemote(config);
|
|
45553
|
+
return remoteEnabled(config);
|
|
45554
|
+
}, "remote reads are disabled on this host (run `norc remote enable`)") });
|
|
45555
|
+
const pullNames = () => deviceSession(env.supabaseUrl, env.anonKey, AbortSignal.timeout(1e4), keyPair.publicJwk).then((s) => pullEnvNames(fetch, s, 1e4)).catch(() => null);
|
|
45556
|
+
const deps = buildWriteIntentDeps(config, machineId, crontabIo, () => void persistConfig(), refreshRemote, pullNames);
|
|
45557
|
+
const rawDeps = buildRawWriteIntentDeps(config, machineId, crontabIo, () => void persistConfig(), refreshRemote);
|
|
44057
45558
|
sec.on("write-intent", (payload, from) => {
|
|
44058
45559
|
let msg;
|
|
44059
45560
|
try {
|
|
@@ -44110,7 +45611,7 @@ async function runBridge(env, crontabIo) {
|
|
|
44110
45611
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
44111
45612
|
const live = pruneExpiredExecuteNonces(config.bridge?.executeNonces, nowSec);
|
|
44112
45613
|
const verify = await verifyExecuteCapability(capability, {
|
|
44113
|
-
publicJwk:
|
|
45614
|
+
publicJwk: CAPABILITY_TRUSTED_KEYS,
|
|
44114
45615
|
machineId,
|
|
44115
45616
|
jobId,
|
|
44116
45617
|
nowSec,
|
|
@@ -44125,13 +45626,19 @@ async function runBridge(env, crontabIo) {
|
|
|
44125
45626
|
reject("unknown job");
|
|
44126
45627
|
return;
|
|
44127
45628
|
}
|
|
45629
|
+
await refreshRemote(config);
|
|
45630
|
+
if (!remoteEnabled(config)) {
|
|
45631
|
+
reject("remote execution is disabled on this host (norc remote enable)");
|
|
45632
|
+
return;
|
|
45633
|
+
}
|
|
45634
|
+
console.log(`[norc bridge] execute-now (${sanitize(config.remote?.account ?? "", 80)}) ${sanitize(job.command, 400)}`);
|
|
45635
|
+
replayFor(config, machineId);
|
|
44128
45636
|
config.bridge = {
|
|
44129
|
-
|
|
44130
|
-
nonces: config.bridge?.nonces ?? [],
|
|
45637
|
+
...config.bridge,
|
|
44131
45638
|
executeNonces: [...live, { nonce: verify.nonce, expiresAt: verify.nonceExp }]
|
|
44132
45639
|
};
|
|
44133
45640
|
await persistConfig();
|
|
44134
|
-
await spawnWrappedCommand(wrapCommand(job.id, job.command, process.platform === "win32" ? "windows" : "posix"));
|
|
45641
|
+
await spawnWrappedCommand(wrapCommand(job.id, job.command, process.platform === "win32" ? "windows" : "posix", job.envNames));
|
|
44135
45642
|
console.log("[norc bridge] execute-now-intent applied");
|
|
44136
45643
|
void sec.send("execute-now-applied", JSON.stringify({ jobId }), from).catch((e) => console.error("[norc bridge] failed to broadcast execute-now-applied", e));
|
|
44137
45644
|
} catch (e) {
|
|
@@ -44149,10 +45656,22 @@ async function runBridge(env, crontabIo) {
|
|
|
44149
45656
|
}
|
|
44150
45657
|
if (!msg || !Array.isArray(msg.jobIds) || !msg.jobIds.every((id) => typeof id === "string") || msg.jobIds.length === 0) return;
|
|
44151
45658
|
enqueueMutation(async () => {
|
|
45659
|
+
await refreshRemote(config);
|
|
45660
|
+
if (!remoteEnabled(config)) {
|
|
45661
|
+
console.warn("[norc bridge] jobs-deleted ignored: remote changes are disabled on this host");
|
|
45662
|
+
return;
|
|
45663
|
+
}
|
|
45664
|
+
const gone = await confirmJobsGone(sb, msg.jobIds);
|
|
45665
|
+
if (gone.length === 0) {
|
|
45666
|
+
console.warn("[norc bridge] jobs-deleted ignored: server still lists those jobs (or could not be asked)");
|
|
45667
|
+
return;
|
|
45668
|
+
}
|
|
44152
45669
|
for (let attempt2 = 0; attempt2 < 3; attempt2++) {
|
|
44153
45670
|
try {
|
|
44154
45671
|
const current = await crontabIo.read();
|
|
44155
|
-
|
|
45672
|
+
const next = projectJobsRemoved(current, gone);
|
|
45673
|
+
if (next !== current) console.log(`[norc bridge] jobs-deleted (${sanitize(config.remote?.account ?? "", 80)}): removing ${gone.length} job(s) the server no longer has`);
|
|
45674
|
+
await crontabIo.write(next);
|
|
44156
45675
|
queueSyncJobs();
|
|
44157
45676
|
return;
|
|
44158
45677
|
} catch (err) {
|
|
@@ -44163,6 +45682,7 @@ async function runBridge(env, crontabIo) {
|
|
|
44163
45682
|
});
|
|
44164
45683
|
});
|
|
44165
45684
|
const closed = new Promise((resolve) => {
|
|
45685
|
+
endCycle = resolve;
|
|
44166
45686
|
channel.subscribe((status, err) => {
|
|
44167
45687
|
console.log(`[norc bridge] channel status: ${status}${err ? ` (${err})` : ""}`);
|
|
44168
45688
|
if (status === "SUBSCRIBED") {
|
|
@@ -44170,9 +45690,19 @@ async function runBridge(env, crontabIo) {
|
|
|
44170
45690
|
attempt = 0;
|
|
44171
45691
|
void channel.track({ online_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
44172
45692
|
queueSyncJobs();
|
|
45693
|
+
if (heartbeat) clearInterval(heartbeat);
|
|
45694
|
+
if (envRefresh) clearInterval(envRefresh);
|
|
44173
45695
|
heartbeat = setInterval(() => {
|
|
44174
|
-
void
|
|
44175
|
-
|
|
45696
|
+
void watchIdentity().then((ok) => {
|
|
45697
|
+
if (ok) return deviceSession(env.supabaseUrl, env.anonKey, void 0, keyPair.publicJwk);
|
|
45698
|
+
});
|
|
45699
|
+
}, 6e4);
|
|
45700
|
+
const pullEnv2 = () => enqueueMutation(async () => {
|
|
45701
|
+
const names = await pullNames();
|
|
45702
|
+
if (names) await applyEnvNames(crontabIo, names);
|
|
45703
|
+
});
|
|
45704
|
+
pullEnv2();
|
|
45705
|
+
envRefresh = setInterval(pullEnv2, 5 * 6e4);
|
|
44176
45706
|
}
|
|
44177
45707
|
if (status === "CLOSED" || status === "CHANNEL_ERROR" || status === "TIMED_OUT") {
|
|
44178
45708
|
state = reduceConn(state, "error");
|
|
@@ -44187,9 +45717,14 @@ async function runBridge(env, crontabIo) {
|
|
|
44187
45717
|
console.error("[norc bridge] connect cycle failed:", e instanceof Error ? e.message : e);
|
|
44188
45718
|
} finally {
|
|
44189
45719
|
if (heartbeat) clearInterval(heartbeat);
|
|
45720
|
+
if (envRefresh) clearInterval(envRefresh);
|
|
44190
45721
|
if (sb) await sb.removeAllChannels().catch(() => {
|
|
44191
45722
|
});
|
|
44192
45723
|
}
|
|
45724
|
+
if (identityChanged) {
|
|
45725
|
+
attempt = 0;
|
|
45726
|
+
continue;
|
|
45727
|
+
}
|
|
44193
45728
|
const delay = backoffDelay(attempt++);
|
|
44194
45729
|
console.log(`[norc bridge] reconnecting in ${delay}ms`);
|
|
44195
45730
|
await wait(delay);
|
|
@@ -44203,28 +45738,50 @@ async function syncJobsQuiet(sb, crontabIo) {
|
|
|
44203
45738
|
console.error("[norc bridge] syncJobs failed:", e instanceof Error ? e.message : e);
|
|
44204
45739
|
}
|
|
44205
45740
|
}
|
|
45741
|
+
async function applyEnvNames(crontabIo, names) {
|
|
45742
|
+
try {
|
|
45743
|
+
const current = await crontabIo.read();
|
|
45744
|
+
const next = reprojectEnvNames(current, names);
|
|
45745
|
+
if (next === current) return;
|
|
45746
|
+
await crontabIo.write(next);
|
|
45747
|
+
console.log("[norc bridge] updated the env var names on managed crontab lines");
|
|
45748
|
+
} catch (e) {
|
|
45749
|
+
console.error("[norc bridge] updating env var names failed:", e instanceof Error ? e.message : e);
|
|
45750
|
+
}
|
|
45751
|
+
}
|
|
45752
|
+
var IDLE_POLL_MS = 3e4;
|
|
45753
|
+
async function readIdentity() {
|
|
45754
|
+
try {
|
|
45755
|
+
return (await loadConfigStrict()).device ?? null;
|
|
45756
|
+
} catch {
|
|
45757
|
+
return void 0;
|
|
45758
|
+
}
|
|
45759
|
+
}
|
|
45760
|
+
function identityKey(d) {
|
|
45761
|
+
return d ? `${d.machineId}:${(0, import_node_crypto3.createHash)("sha256").update(d.deviceToken).digest("hex").slice(0, 16)}` : "";
|
|
45762
|
+
}
|
|
44206
45763
|
function wait(ms) {
|
|
44207
45764
|
return new Promise((r) => setTimeout(r, ms));
|
|
44208
45765
|
}
|
|
44209
45766
|
|
|
44210
45767
|
// src/service.ts
|
|
44211
|
-
var
|
|
44212
|
-
var
|
|
45768
|
+
var import_promises6 = require("node:fs/promises");
|
|
45769
|
+
var import_node_child_process7 = require("node:child_process");
|
|
44213
45770
|
var import_node_util2 = require("node:util");
|
|
44214
|
-
var
|
|
44215
|
-
var
|
|
44216
|
-
var execFileAsync2 = (0, import_node_util2.promisify)(
|
|
45771
|
+
var import_node_os8 = require("node:os");
|
|
45772
|
+
var import_node_path6 = require("node:path");
|
|
45773
|
+
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process7.execFile);
|
|
44217
45774
|
function resolveBinaryPath(proc = process) {
|
|
44218
45775
|
return proc.pkg ? proc.execPath : proc.argv[1];
|
|
44219
45776
|
}
|
|
44220
45777
|
function defaultServiceDeps(binaryPath) {
|
|
44221
45778
|
return {
|
|
44222
|
-
platform: (0,
|
|
44223
|
-
home: (0,
|
|
45779
|
+
platform: (0, import_node_os8.platform)(),
|
|
45780
|
+
home: (0, import_node_os8.homedir)(),
|
|
44224
45781
|
binaryPath,
|
|
44225
|
-
mkdir:
|
|
44226
|
-
writeFile:
|
|
44227
|
-
rm:
|
|
45782
|
+
mkdir: import_promises6.mkdir,
|
|
45783
|
+
writeFile: import_promises6.writeFile,
|
|
45784
|
+
rm: import_promises6.rm,
|
|
44228
45785
|
exec: async (cmd, args) => {
|
|
44229
45786
|
await execFileAsync2(cmd, args);
|
|
44230
45787
|
}
|
|
@@ -44232,11 +45789,12 @@ function defaultServiceDeps(binaryPath) {
|
|
|
44232
45789
|
}
|
|
44233
45790
|
var SCHEDULED_TASK_NAME = "norc-cli-bridge";
|
|
44234
45791
|
function systemdUnitPath(home) {
|
|
44235
|
-
return (0,
|
|
45792
|
+
return (0, import_node_path6.join)(home, ".config", "systemd", "user", "norc.service");
|
|
44236
45793
|
}
|
|
44237
45794
|
function launchdPlistPath(home) {
|
|
44238
|
-
return (0,
|
|
45795
|
+
return (0, import_node_path6.join)(home, "Library", "LaunchAgents", "dev.norc.cli.plist");
|
|
44239
45796
|
}
|
|
45797
|
+
var xmlEscape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
44240
45798
|
function systemdUnit(binaryPath) {
|
|
44241
45799
|
return `[Unit]
|
|
44242
45800
|
Description=norc headless cron scheduler bridge
|
|
@@ -44245,7 +45803,7 @@ Wants=network-online.target
|
|
|
44245
45803
|
|
|
44246
45804
|
[Service]
|
|
44247
45805
|
Type=simple
|
|
44248
|
-
ExecStart
|
|
45806
|
+
ExecStart="${binaryPath.replace(/[\\"]/g, "\\$&").replace(/%/g, "%%").replace(/\$/g, "$$$$")}" bridge
|
|
44249
45807
|
Restart=on-failure
|
|
44250
45808
|
RestartSec=5
|
|
44251
45809
|
|
|
@@ -44261,7 +45819,7 @@ function launchdPlist(binaryPath) {
|
|
|
44261
45819
|
<key>Label</key><string>dev.norc.cli</string>
|
|
44262
45820
|
<key>ProgramArguments</key>
|
|
44263
45821
|
<array>
|
|
44264
|
-
<string>${binaryPath}</string>
|
|
45822
|
+
<string>${xmlEscape(binaryPath)}</string>
|
|
44265
45823
|
<string>bridge</string>
|
|
44266
45824
|
</array>
|
|
44267
45825
|
<key>RunAtLoad</key><true/>
|
|
@@ -44274,7 +45832,7 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
44274
45832
|
switch (deps.platform) {
|
|
44275
45833
|
case "linux": {
|
|
44276
45834
|
const path = systemdUnitPath(deps.home);
|
|
44277
|
-
await deps.mkdir((0,
|
|
45835
|
+
await deps.mkdir((0, import_node_path6.join)(deps.home, ".config", "systemd", "user"), { recursive: true });
|
|
44278
45836
|
await deps.writeFile(path, systemdUnit(deps.binaryPath));
|
|
44279
45837
|
await deps.exec("systemctl", ["--user", "daemon-reload"]);
|
|
44280
45838
|
await deps.exec("systemctl", ["--user", "enable", "--now", "norc.service"]);
|
|
@@ -44282,7 +45840,7 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
44282
45840
|
}
|
|
44283
45841
|
case "darwin": {
|
|
44284
45842
|
const path = launchdPlistPath(deps.home);
|
|
44285
|
-
await deps.mkdir((0,
|
|
45843
|
+
await deps.mkdir((0, import_node_path6.join)(deps.home, "Library", "LaunchAgents"), { recursive: true });
|
|
44286
45844
|
await deps.writeFile(path, launchdPlist(deps.binaryPath));
|
|
44287
45845
|
await deps.exec("launchctl", ["load", "-w", path]);
|
|
44288
45846
|
return;
|
|
@@ -44339,17 +45897,29 @@ var HELP = `norc \u2014 headless job scheduler CLI
|
|
|
44339
45897
|
Usage:
|
|
44340
45898
|
norc login --email <email> start email one-time-code login (prompts for an API key first if no email given; empty falls back to email)
|
|
44341
45899
|
norc login --key <api-key> log in + pair headlessly with a norc API key (vault \u2192 Settings \u2192 API Keys) \u2014 no email/browser
|
|
45900
|
+
(pairs only; \`norc env\` also needs \`norc login --email\`, both are kept)
|
|
44342
45901
|
norc pair pair this machine with your norc account (after norc login)
|
|
45902
|
+
norc logout remove this machine's user session and pairing (both kinds of login)
|
|
44343
45903
|
norc jobs list list jobs in this machine's crontab
|
|
44344
45904
|
norc jobs add <schedule> <cmd> add a job (schedule in 5-field cron syntax)
|
|
44345
45905
|
norc jobs rm <id> remove a job by id
|
|
44346
45906
|
norc jobs enable <id> enable a job
|
|
44347
45907
|
norc jobs disable <id> disable a job
|
|
45908
|
+
norc jobs add <schedule> <cmd> --env NAME [--env NAME2] also bind account env vars to the job
|
|
45909
|
+
norc env ls list env vars (name, state, bound jobs; never values)
|
|
45910
|
+
echo "$V" | norc env set NAME create/update a var; value from stdin or hidden prompt, never argv
|
|
45911
|
+
norc env archive NAME [--yes] stop delivering a var (lists the jobs it would break)
|
|
45912
|
+
norc env restore NAME resume delivery of an archived var
|
|
45913
|
+
norc env rm NAME [--yes] delete a var permanently (lists the jobs it would break, asks you to type
|
|
45914
|
+
the name); asks for your 2FA code or an emailed code to confirm it is you
|
|
44348
45915
|
norc gitops plan --file <path> [--json] diff a YAML file against live jobs (read-only)
|
|
44349
45916
|
norc gitops apply --file <path> apply the diff (create/update/delete to match the file)
|
|
44350
45917
|
norc run --job-id <id> -- <cmd> exec <cmd> and report its result (used internally by wrapped crontab entries)
|
|
44351
45918
|
norc runs --tail tail run history (not yet available)
|
|
45919
|
+
norc usage [--days 7|30] [--json] [--no-color] [--plain]
|
|
45920
|
+
usage dashboard in the terminal: headroom, health, runs, activity
|
|
44352
45921
|
norc bridge run the bridge daemon (stay online, admin from norc web)
|
|
45922
|
+
norc remote enable|disable|status allow/deny remote crontab writes + execute-now from your account (default: disabled)
|
|
44353
45923
|
norc service install register+start the per-user background service
|
|
44354
45924
|
norc service uninstall stop+remove the per-user background service
|
|
44355
45925
|
|
|
@@ -44363,7 +45933,7 @@ function supabase() {
|
|
|
44363
45933
|
return createClient(url, anon);
|
|
44364
45934
|
}
|
|
44365
45935
|
async function prompt(question) {
|
|
44366
|
-
const rl = (0,
|
|
45936
|
+
const rl = (0, import_promises7.createInterface)({ input: process.stdin, output: process.stdout });
|
|
44367
45937
|
try {
|
|
44368
45938
|
return (await rl.question(question)).trim();
|
|
44369
45939
|
} finally {
|
|
@@ -44373,23 +45943,22 @@ async function prompt(question) {
|
|
|
44373
45943
|
async function cmdLogin(args) {
|
|
44374
45944
|
const keyFlagIndex = args.indexOf("--key");
|
|
44375
45945
|
const emailFlagIndex = args.indexOf("--email");
|
|
44376
|
-
const
|
|
45946
|
+
const vaultUrl2 = vaultUrl();
|
|
45947
|
+
if (keyFlagIndex !== -1) console.error("warning: --key puts the API key on the command line (visible in `ps` and shell history). Prefer NORC_API_KEY or the interactive prompt.");
|
|
44377
45948
|
let apiKey = keyFlagIndex !== -1 ? args[keyFlagIndex + 1] : process.env.NORC_API_KEY;
|
|
44378
45949
|
const positionalEmail = emailFlagIndex !== -1 ? args[emailFlagIndex + 1] : void 0;
|
|
44379
45950
|
debugLog("login: --key present:", keyFlagIndex !== -1, "NORC_API_KEY set:", Boolean(process.env.NORC_API_KEY), "--email:", positionalEmail ?? "(none)");
|
|
44380
45951
|
if (!apiKey && !positionalEmail) {
|
|
44381
45952
|
debugLog("login: no --key/--email/NORC_API_KEY given, prompting for API key");
|
|
44382
|
-
apiKey = await promptSecret(`API key (create one at ${
|
|
45953
|
+
apiKey = await promptSecret(`API key (create one at ${vaultUrl2}/settings/api-keys \u2014 press enter to use email instead): `);
|
|
44383
45954
|
debugLog("login: prompt returned key:", redactSecret(apiKey));
|
|
44384
45955
|
}
|
|
44385
45956
|
if (apiKey) {
|
|
44386
|
-
debugLog("login: using API-key path, POST", `${
|
|
44387
|
-
const result2 = await pairWithApiKey(fetch,
|
|
45957
|
+
debugLog("login: using API-key path, POST", `${vaultUrl2}/api/v1/machines`, "key:", redactSecret(apiKey));
|
|
45958
|
+
const result2 = await pairWithApiKey(fetch, vaultUrl2, apiKey, (0, import_node_os9.hostname)());
|
|
44388
45959
|
debugLog("login: pairWithApiKey result:", result2.ok ? { ok: true, machineId: result2.machineId, deviceToken: redactSecret(result2.deviceToken) } : result2);
|
|
44389
45960
|
if (!result2.ok) throw new Error(result2.message);
|
|
44390
|
-
|
|
44391
|
-
config2.device = { machineId: result2.machineId, deviceToken: result2.deviceToken };
|
|
44392
|
-
await saveConfig(config2);
|
|
45961
|
+
await savePairedDevice({ machineId: result2.machineId, deviceToken: result2.deviceToken });
|
|
44393
45962
|
console.log(`logged in. machine id: ${result2.machineId}`);
|
|
44394
45963
|
return;
|
|
44395
45964
|
}
|
|
@@ -44406,10 +45975,8 @@ async function cmdLogin(args) {
|
|
|
44406
45975
|
const result = await verifyLogin(client, email, code);
|
|
44407
45976
|
debugLog("login: verifyLogin result:", result.ok ? { ok: true } : result);
|
|
44408
45977
|
if (!result.ok) throw new Error(result.message);
|
|
44409
|
-
|
|
44410
|
-
|
|
44411
|
-
await saveConfig(config);
|
|
44412
|
-
console.log("logged in. run `norc pair` next to register this machine.");
|
|
45978
|
+
await saveUserSession({ email, accessToken: result.accessToken, refreshToken: result.refreshToken });
|
|
45979
|
+
console.log((await loadConfig()).device ? "logged in. this machine stays paired; `norc env` now works here." : "logged in. run `norc pair` next to register this machine.");
|
|
44413
45980
|
}
|
|
44414
45981
|
async function cmdPair() {
|
|
44415
45982
|
const client = supabase();
|
|
@@ -44419,9 +45986,7 @@ async function cmdPair() {
|
|
|
44419
45986
|
console.log(qr);
|
|
44420
45987
|
console.log(`scan this QR with the norc mobile app, or enter the code in the norc web app to pair this machine: ${p.display}`);
|
|
44421
45988
|
} else if (p.phase === "paired") {
|
|
44422
|
-
|
|
44423
|
-
config.device = { machineId: p.machineId, deviceToken: p.deviceToken };
|
|
44424
|
-
await saveConfig(config);
|
|
45989
|
+
await savePairedDevice({ machineId: p.machineId, deviceToken: p.deviceToken });
|
|
44425
45990
|
console.log(`paired. machine id: ${p.machineId}`);
|
|
44426
45991
|
} else if (p.phase === "expired") {
|
|
44427
45992
|
console.log("pairing code expired \u2014 run `norc pair` again.");
|
|
@@ -44430,6 +45995,80 @@ async function cmdPair() {
|
|
|
44430
45995
|
}
|
|
44431
45996
|
});
|
|
44432
45997
|
}
|
|
45998
|
+
async function userClient() {
|
|
45999
|
+
const config = await loadConfig();
|
|
46000
|
+
const session = requireUserSession(config);
|
|
46001
|
+
const url = supabaseUrl();
|
|
46002
|
+
const sb = createClient(url, process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY, { auth: { persistSession: false, autoRefreshToken: false } });
|
|
46003
|
+
const { data, error } = await sb.auth.setSession({ access_token: session.accessToken, refresh_token: session.refreshToken });
|
|
46004
|
+
if (error || !data.session) throw new Error("session expired: run `norc login --email <your-email>` again (the pairing is kept)");
|
|
46005
|
+
if (data.session.access_token !== session.accessToken) {
|
|
46006
|
+
await saveUserSession({ ...session, accessToken: data.session.access_token, refreshToken: data.session.refresh_token });
|
|
46007
|
+
}
|
|
46008
|
+
return sb;
|
|
46009
|
+
}
|
|
46010
|
+
async function saveSession(sb) {
|
|
46011
|
+
const { data: { session } } = await sb.auth.getSession();
|
|
46012
|
+
if (!session) return;
|
|
46013
|
+
const config = await loadConfig();
|
|
46014
|
+
if (!config.session) return;
|
|
46015
|
+
await saveUserSession({ ...config.session, accessToken: session.access_token, refreshToken: session.refresh_token });
|
|
46016
|
+
}
|
|
46017
|
+
async function envDeps() {
|
|
46018
|
+
const sb = await userClient();
|
|
46019
|
+
const url = supabaseUrl();
|
|
46020
|
+
const anon = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
46021
|
+
const rl = () => (0, import_promises7.createInterface)({ input: process.stdin, output: process.stdout });
|
|
46022
|
+
return {
|
|
46023
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
46024
|
+
listVars: async () => {
|
|
46025
|
+
const { data, error } = await sb.from("env_vars").select("id,name,archived_at");
|
|
46026
|
+
if (error) throw new Error(error.message);
|
|
46027
|
+
return (data ?? []).map((r) => ({ id: r.id, name: r.name, archived: r.archived_at != null }));
|
|
46028
|
+
},
|
|
46029
|
+
plan: async () => {
|
|
46030
|
+
const { data, error } = await sb.from("accounts").select("plan, trial_ends_at").limit(1).maybeSingle();
|
|
46031
|
+
const row = data;
|
|
46032
|
+
const p = row?.plan;
|
|
46033
|
+
return error || p !== "free" && p !== "pro" && p !== "power" && p !== "team" ? null : effectivePlan(p, row?.trial_ends_at);
|
|
46034
|
+
},
|
|
46035
|
+
bindingNames: async () => {
|
|
46036
|
+
const { data, error } = await sb.from("job_env_bindings").select("name, jobs!inner(archived_at, machines!inner(archived_at, detached_at))").is("jobs.archived_at", null).is("jobs.machines.archived_at", null).is("jobs.machines.detached_at", null);
|
|
46037
|
+
if (error) throw new Error(error.message);
|
|
46038
|
+
return (data ?? []).map((r) => r.name);
|
|
46039
|
+
},
|
|
46040
|
+
impact: async (name) => {
|
|
46041
|
+
const { data, error } = await sb.rpc("env_var_impact", { p_name: name });
|
|
46042
|
+
if (error) throw new Error(error.message);
|
|
46043
|
+
return data ?? [];
|
|
46044
|
+
},
|
|
46045
|
+
write: async (body) => {
|
|
46046
|
+
const { data: { session } } = await sb.auth.getSession();
|
|
46047
|
+
const res = await fetch(`${url}/functions/v1/env-write`, {
|
|
46048
|
+
method: "POST",
|
|
46049
|
+
headers: { "Content-Type": "application/json", apikey: anon, Authorization: `Bearer ${session?.access_token ?? ""}` },
|
|
46050
|
+
body: JSON.stringify(body)
|
|
46051
|
+
});
|
|
46052
|
+
const json = await res.json().catch(() => ({}));
|
|
46053
|
+
return { status: res.status, body: json };
|
|
46054
|
+
},
|
|
46055
|
+
rpc: async (fn, id) => (await sb.rpc(fn, { p_id: id })).error?.message ?? null,
|
|
46056
|
+
deleteVar: async (id) => {
|
|
46057
|
+
const { error } = await sb.rpc("delete_env_var", { p_id: id });
|
|
46058
|
+
return error ? { message: error.message, code: error.code, hint: error.hint } : null;
|
|
46059
|
+
},
|
|
46060
|
+
...makeStepUpDeps(sb, fetch, url, anon, () => saveSession(sb)),
|
|
46061
|
+
readSecret: (q) => process.stdin.isTTY ? promptSecret(q) : readStdinValue(process.stdin),
|
|
46062
|
+
// EOF closes the interface; resolve null (cancel) instead of hanging or throwing.
|
|
46063
|
+
readLine: (q) => new Promise((resolve) => {
|
|
46064
|
+
const r = rl();
|
|
46065
|
+
r.once("close", () => resolve(null));
|
|
46066
|
+
r.question(q).then(resolve, () => resolve(null)).finally(() => r.close());
|
|
46067
|
+
}),
|
|
46068
|
+
out: (s) => console.log(s),
|
|
46069
|
+
err: (s) => console.error(s)
|
|
46070
|
+
};
|
|
46071
|
+
}
|
|
44433
46072
|
async function cmdJobs(args) {
|
|
44434
46073
|
const [sub, ...rest] = args;
|
|
44435
46074
|
switch (sub) {
|
|
@@ -44445,10 +46084,27 @@ async function cmdJobs(args) {
|
|
|
44445
46084
|
return;
|
|
44446
46085
|
}
|
|
44447
46086
|
case "add": {
|
|
44448
|
-
const [schedule, ...
|
|
44449
|
-
const command =
|
|
44450
|
-
|
|
44451
|
-
|
|
46087
|
+
const [schedule, ...parts] = rest;
|
|
46088
|
+
const { command, envNames } = splitTrailingEnv(parts);
|
|
46089
|
+
let user;
|
|
46090
|
+
if (!schedule || !command) throw new Error("usage: norc jobs add <schedule> <command> [--env NAME]... (--env flags go last)");
|
|
46091
|
+
const job = envNames.length === 0 ? await addJob(systemCrontabIo, schedule, command) : await addJobWithEnv(systemCrontabIo, schedule, command, envNames, {
|
|
46092
|
+
prepare: async () => {
|
|
46093
|
+
user = await userClient();
|
|
46094
|
+
},
|
|
46095
|
+
sync: async (extra) => {
|
|
46096
|
+
const url = supabaseUrl();
|
|
46097
|
+
const anon = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
46098
|
+
const sess = await deviceSession(url, anon);
|
|
46099
|
+
if (!sess) throw new Error("not paired \u2014 run `norc pair` first");
|
|
46100
|
+
const dev = createClient(url, anon, { auth: { persistSession: false }, global: { headers: { Authorization: `Bearer ${sess.token}` } } });
|
|
46101
|
+
await syncJobs(dev, [...parseCrontab(await systemCrontabIo.read()), ...extra ? [extra] : []]);
|
|
46102
|
+
},
|
|
46103
|
+
bind: async (id, names) => {
|
|
46104
|
+
const { error } = await user.rpc("set_job_env_bindings", { p_job_id: id, p_names: names });
|
|
46105
|
+
if (error) throw new Error(error.message);
|
|
46106
|
+
}
|
|
46107
|
+
});
|
|
44452
46108
|
console.log(`added job ${job.id}`);
|
|
44453
46109
|
return;
|
|
44454
46110
|
}
|
|
@@ -44505,12 +46161,26 @@ async function main() {
|
|
|
44505
46161
|
return cmdLogin(args);
|
|
44506
46162
|
case "pair":
|
|
44507
46163
|
return cmdPair();
|
|
46164
|
+
case "logout": {
|
|
46165
|
+
const had = await logout(void 0, void 0, {
|
|
46166
|
+
signOut: async (sess) => {
|
|
46167
|
+
const sb = createClient(supabaseUrl(), process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY, { auth: { persistSession: false, autoRefreshToken: false } });
|
|
46168
|
+
await sb.auth.setSession({ access_token: sess.accessToken, refresh_token: sess.refreshToken });
|
|
46169
|
+
await sb.auth.signOut({ scope: "local" });
|
|
46170
|
+
}
|
|
46171
|
+
});
|
|
46172
|
+
console.log(had.session || had.device ? `logged out: removed ${[had.session && "the user session", had.device && "this machine's pairing"].filter(Boolean).join(" and ")}. The machine stays listed in the vault; remove it there. A running norc service stops acting on its own; to remove it, run \`norc service uninstall\`.` : "not logged in; nothing to remove.");
|
|
46173
|
+
return;
|
|
46174
|
+
}
|
|
44508
46175
|
case "jobs":
|
|
44509
46176
|
return cmdJobs(args);
|
|
46177
|
+
case "env":
|
|
46178
|
+
process.exitCode = await cmdEnv(args, await envDeps());
|
|
46179
|
+
return;
|
|
44510
46180
|
case "gitops": {
|
|
44511
|
-
const
|
|
46181
|
+
const vaultUrl2 = vaultUrl();
|
|
44512
46182
|
const apiKey = process.env.NORC_API_KEY;
|
|
44513
|
-
process.exitCode = await cmdGitops(args, { fetchImpl: fetch, readFile: (p) => (0,
|
|
46183
|
+
process.exitCode = await cmdGitops(args, { fetchImpl: fetch, readFile: (p) => (0, import_promises8.readFile)(p, "utf8"), vaultUrl: vaultUrl2, apiKey });
|
|
44514
46184
|
return;
|
|
44515
46185
|
}
|
|
44516
46186
|
case "run":
|
|
@@ -44519,8 +46189,27 @@ async function main() {
|
|
|
44519
46189
|
case "runs":
|
|
44520
46190
|
console.log(tailRunsMessage());
|
|
44521
46191
|
return;
|
|
46192
|
+
case "usage": {
|
|
46193
|
+
const anonKey = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
46194
|
+
const base = supabaseUrl();
|
|
46195
|
+
process.exitCode = await cmdUsage(args, {
|
|
46196
|
+
fetchImpl: fetch,
|
|
46197
|
+
getJwt: async () => (await deviceSession(base, anonKey))?.token ?? null,
|
|
46198
|
+
functionsUrl: `${base}/functions/v1`,
|
|
46199
|
+
vaultUrl: vaultUrl(),
|
|
46200
|
+
columns: process.stdout.columns ?? 80,
|
|
46201
|
+
isTTY: Boolean(process.stdout.isTTY),
|
|
46202
|
+
env: process.env,
|
|
46203
|
+
platform: process.platform
|
|
46204
|
+
});
|
|
46205
|
+
return;
|
|
46206
|
+
}
|
|
44522
46207
|
case "bridge":
|
|
44523
46208
|
return cmdBridge();
|
|
46209
|
+
case "remote": {
|
|
46210
|
+
const config = await loadConfig();
|
|
46211
|
+
return cmdRemote(args, config, (c) => saveConfig(c, void 0, { keys: ["remote"] }));
|
|
46212
|
+
}
|
|
44524
46213
|
case "service": {
|
|
44525
46214
|
const [sub] = args;
|
|
44526
46215
|
if (sub === "install") {
|