@quatronic/qore 0.2.0-rc.8 → 0.2.0-test.6ec9d9f
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/cli.js +219 -98
- package/dist/qore-capabilities.json +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2ac9292b-9c15-5fb7-bdc6-c773ad369497")}catch(e){}}();
|
|
4
4
|
import { createRequire as __qoreCreateRequire } from "node:module"; const require = __qoreCreateRequire(import.meta.url);
|
|
5
5
|
import {
|
|
6
6
|
addSecretValues,
|
|
@@ -269,26 +269,26 @@ function byStatus(status2) {
|
|
|
269
269
|
return "QORE_INTERNAL";
|
|
270
270
|
}
|
|
271
271
|
async function problemToError(res) {
|
|
272
|
-
let
|
|
272
|
+
let body2 = {};
|
|
273
273
|
try {
|
|
274
|
-
|
|
274
|
+
body2 = await res.json();
|
|
275
275
|
} catch {
|
|
276
276
|
}
|
|
277
|
-
const serverCode =
|
|
277
|
+
const serverCode = body2.code;
|
|
278
278
|
const code = serverCode && BY_SERVER_CODE[serverCode] || byStatus(res.status);
|
|
279
279
|
const requestId = res.headers.get("x-request-id") ?? void 0;
|
|
280
280
|
const details = {};
|
|
281
|
-
if (
|
|
282
|
-
const detail2 = typeof
|
|
281
|
+
if (body2.detail && typeof body2.detail === "object") Object.assign(details, body2.detail);
|
|
282
|
+
const detail2 = typeof body2.detail === "string" && body2.detail ? body2.detail : void 0;
|
|
283
283
|
if (detail2) details.detail = detail2;
|
|
284
284
|
const retry = res.headers.get("retry-after");
|
|
285
285
|
if (retry && /^\d+$/.test(retry)) details.retryAfter = Number(retry);
|
|
286
286
|
const hint = code === "QORE_UPGRADE_REQUIRED" ? "Run: npm i -g @quatronic/qore" : code === "QORE_RATE_LIMITED" ? `Wait ${details.retryAfter ?? "a moment"} s and retry.` : code === "QORE_API_UNAVAILABLE" ? "Qore is temporarily unavailable; retry in a minute." : code === "QORE_APP_AMBIGUOUS" ? "Pass --app <slug>." : void 0;
|
|
287
|
-
const apps =
|
|
287
|
+
const apps = body2.detail?.apps;
|
|
288
288
|
const candidates = code === "QORE_APP_AMBIGUOUS" && Array.isArray(apps) ? apps.map((a) => ({ kind: "app", id: a.id, slug: a.slug, name: a.name })) : void 0;
|
|
289
289
|
if (candidates) delete details.apps;
|
|
290
|
-
const genericTitle = !
|
|
291
|
-
const message = genericTitle && detail2 ||
|
|
290
|
+
const genericTitle = !body2.title || body2.title === "HTTP error" || body2.title === serverCode;
|
|
291
|
+
const message = genericTitle && detail2 || body2.title || `Request failed (${res.status})`;
|
|
292
292
|
return new QoreError(code, message, {
|
|
293
293
|
status: res.status,
|
|
294
294
|
requestId,
|
|
@@ -660,7 +660,7 @@ var QoreApiClient = class {
|
|
|
660
660
|
this.o = o;
|
|
661
661
|
}
|
|
662
662
|
o;
|
|
663
|
-
async once(method, path2,
|
|
663
|
+
async once(method, path2, body2, force) {
|
|
664
664
|
const token = await this.o.token(force);
|
|
665
665
|
const headers = {
|
|
666
666
|
authorization: `Bearer ${token}`,
|
|
@@ -669,13 +669,13 @@ var QoreApiClient = class {
|
|
|
669
669
|
"qore-command": this.o.command,
|
|
670
670
|
"user-agent": `qore/${this.o.cliVersion} (${this.o.platform})`
|
|
671
671
|
};
|
|
672
|
-
if (
|
|
672
|
+
if (body2 !== void 0) headers["content-type"] = "application/json";
|
|
673
673
|
let res;
|
|
674
674
|
try {
|
|
675
675
|
res = await this.o.fetch(`${this.o.apiOrigin}${path2}`, {
|
|
676
676
|
method,
|
|
677
677
|
headers,
|
|
678
|
-
body:
|
|
678
|
+
body: body2 === void 0 ? void 0 : JSON.stringify(body2)
|
|
679
679
|
});
|
|
680
680
|
} catch (e) {
|
|
681
681
|
throw fetchError(e, new URL(this.o.apiOrigin).host);
|
|
@@ -684,10 +684,10 @@ var QoreApiClient = class {
|
|
|
684
684
|
this.o.onRequest?.(`${method} ${path2} \u2192 ${res.status}${rid ? ` (${rid})` : ""}`);
|
|
685
685
|
return res;
|
|
686
686
|
}
|
|
687
|
-
async request(method, path2,
|
|
688
|
-
let res = await this.once(method, path2,
|
|
687
|
+
async request(method, path2, body2, parse2 = (r) => r.json()) {
|
|
688
|
+
let res = await this.once(method, path2, body2, false);
|
|
689
689
|
if (res.status === 401) {
|
|
690
|
-
res = await this.once(method, path2,
|
|
690
|
+
res = await this.once(method, path2, body2, true);
|
|
691
691
|
if (res.status === 401) {
|
|
692
692
|
const skew = clockSkewSeconds(res.headers.get("date"), (this.o.now ?? (() => /* @__PURE__ */ new Date()))());
|
|
693
693
|
if (skew !== null && Math.abs(skew) > 60) {
|
|
@@ -714,8 +714,8 @@ var QoreApiClient = class {
|
|
|
714
714
|
getText(path2) {
|
|
715
715
|
return this.request("GET", path2, void 0, (r) => r.text());
|
|
716
716
|
}
|
|
717
|
-
post(path2,
|
|
718
|
-
return this.request("POST", path2,
|
|
717
|
+
post(path2, body2) {
|
|
718
|
+
return this.request("POST", path2, body2);
|
|
719
719
|
}
|
|
720
720
|
};
|
|
721
721
|
|
|
@@ -2497,12 +2497,13 @@ async function readRepoConfig(root) {
|
|
|
2497
2497
|
|
|
2498
2498
|
// src/core/env/fetch.ts
|
|
2499
2499
|
async function fetchLocalEnv(deps2, mc, app) {
|
|
2500
|
-
await ensureCapability(deps2, mc.portal.apiOrigin, "module.local-env");
|
|
2500
|
+
const meta = await ensureCapability(deps2, mc.portal.apiOrigin, "module.local-env");
|
|
2501
2501
|
try {
|
|
2502
2502
|
const local = await mc.session.api.get(
|
|
2503
2503
|
`/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/local-env?app_id=${encodeURIComponent(app.id)}`
|
|
2504
2504
|
);
|
|
2505
2505
|
deps2.registerSecrets(Object.values(local.env));
|
|
2506
|
+
if (!meta.capabilities.includes("module.local-env-rules")) delete local.rules;
|
|
2506
2507
|
return local;
|
|
2507
2508
|
} catch (e) {
|
|
2508
2509
|
if (!(e instanceof QoreError) || e.code !== "QORE_ACCESS_DENIED") throw e;
|
|
@@ -2519,14 +2520,50 @@ async function fetchLocalEnv(deps2, mc, app) {
|
|
|
2519
2520
|
}
|
|
2520
2521
|
|
|
2521
2522
|
// src/core/env/merge.ts
|
|
2523
|
+
var KEY_LINE = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
|
|
2524
|
+
var stripCr = (line2) => line2.replace(/\r$/, "");
|
|
2525
|
+
var expandDouble = (raw) => raw.replace(/\\[nr]/g, (e) => e === "\\n" ? "\n" : "\r");
|
|
2526
|
+
function readValue(lines, at, rest) {
|
|
2527
|
+
const quote = rest[0];
|
|
2528
|
+
if (quote === '"' || quote === "'" || quote === "`") {
|
|
2529
|
+
let raw = "";
|
|
2530
|
+
let chunk = rest.slice(1);
|
|
2531
|
+
for (let j = at; ; ) {
|
|
2532
|
+
const end2 = chunk.indexOf(quote);
|
|
2533
|
+
if (end2 >= 0) {
|
|
2534
|
+
raw += chunk.slice(0, end2);
|
|
2535
|
+
return { value: quote === '"' ? expandDouble(raw) : raw, last: j };
|
|
2536
|
+
}
|
|
2537
|
+
raw += chunk + "\n";
|
|
2538
|
+
j++;
|
|
2539
|
+
if (j >= lines.length) break;
|
|
2540
|
+
chunk = stripCr(lines[j] ?? "");
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
return { value: rest, last: at };
|
|
2544
|
+
}
|
|
2545
|
+
function readEntries(lines) {
|
|
2546
|
+
const entries = [];
|
|
2547
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2548
|
+
const m = stripCr(lines[i] ?? "").match(KEY_LINE);
|
|
2549
|
+
if (m?.[1] === void 0 || m[2] === void 0) continue;
|
|
2550
|
+
const { value, last } = readValue(lines, i, m[2]);
|
|
2551
|
+
entries.push({ key: m[1], value, first: i, last });
|
|
2552
|
+
i = last;
|
|
2553
|
+
}
|
|
2554
|
+
return entries;
|
|
2555
|
+
}
|
|
2522
2556
|
function parseEnv(contents) {
|
|
2523
2557
|
const map = /* @__PURE__ */ new Map();
|
|
2524
|
-
for (const
|
|
2525
|
-
const m = line2.replace(/\r$/, "").match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);
|
|
2526
|
-
if (m?.[1] !== void 0 && m[2] !== void 0) map.set(m[1], m[2]);
|
|
2527
|
-
}
|
|
2558
|
+
for (const { key: key2, value } of readEntries(contents.split("\n"))) map.set(key2, value);
|
|
2528
2559
|
return map;
|
|
2529
2560
|
}
|
|
2561
|
+
function renderValue(value) {
|
|
2562
|
+
if (!/[\r\n#"'`]|^\s|\s$/.test(value)) return value;
|
|
2563
|
+
if (!/["\\\r]/.test(value)) return `"${value.replace(/\n/g, "\\n")}"`;
|
|
2564
|
+
if (!value.includes("'")) return `'${value}'`;
|
|
2565
|
+
return `\`${value}\``;
|
|
2566
|
+
}
|
|
2530
2567
|
function isManagedKey(key2, managed) {
|
|
2531
2568
|
for (const pattern of managed) {
|
|
2532
2569
|
if (pattern.endsWith("*")) {
|
|
@@ -2571,25 +2608,35 @@ function planEnvUpdate({
|
|
|
2571
2608
|
}
|
|
2572
2609
|
return { merged, conflicts, added, unchanged, overwritten };
|
|
2573
2610
|
}
|
|
2611
|
+
var renderEntry = (key2, value, eol) => `${key2}=${renderValue(value)}`.replace(/\r?\n/g, eol);
|
|
2574
2612
|
function renderEnv(original, merged) {
|
|
2575
2613
|
const seen = /* @__PURE__ */ new Set();
|
|
2576
2614
|
const lines = original.split("\n");
|
|
2577
|
-
const
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2615
|
+
const eol = /\r?\n/.exec(original)?.[0] ?? "\n";
|
|
2616
|
+
const out = [];
|
|
2617
|
+
let next = 0;
|
|
2618
|
+
for (const { key: key2, value, first, last } of readEntries(lines)) {
|
|
2619
|
+
out.push(...lines.slice(next, first));
|
|
2620
|
+
next = last + 1;
|
|
2621
|
+
if (!merged.has(key2) || merged.get(key2) === value) {
|
|
2622
|
+
out.push(...lines.slice(first, next));
|
|
2623
|
+
if (merged.has(key2)) seen.add(key2);
|
|
2624
|
+
continue;
|
|
2625
|
+
}
|
|
2582
2626
|
seen.add(key2);
|
|
2583
|
-
|
|
2584
|
-
|
|
2627
|
+
const cr = lines[last]?.endsWith("\r") ? "\r" : "";
|
|
2628
|
+
out.push(renderEntry(key2, merged.get(key2) ?? "", `${cr}
|
|
2629
|
+
`) + cr);
|
|
2630
|
+
}
|
|
2631
|
+
out.push(...lines.slice(next));
|
|
2585
2632
|
const appended = [];
|
|
2586
2633
|
for (const [key2, value] of merged) {
|
|
2587
|
-
if (!seen.has(key2)) appended.push(
|
|
2634
|
+
if (!seen.has(key2)) appended.push(renderEntry(key2, value, eol));
|
|
2588
2635
|
}
|
|
2589
2636
|
let text2 = out.join("\n");
|
|
2590
2637
|
if (appended.length) {
|
|
2591
|
-
if (text2.length && !text2.endsWith("\n")) text2 +=
|
|
2592
|
-
text2 += appended.join(
|
|
2638
|
+
if (text2.length && !text2.endsWith("\n")) text2 += eol;
|
|
2639
|
+
text2 += appended.join(eol) + eol;
|
|
2593
2640
|
}
|
|
2594
2641
|
return text2;
|
|
2595
2642
|
}
|
|
@@ -2643,7 +2690,7 @@ function planPull(o) {
|
|
|
2643
2690
|
for (const key2 of o.localSecrets) {
|
|
2644
2691
|
const v = r.merged.get(key2);
|
|
2645
2692
|
if (v === void 0 || v === "" || v === '""' || v === "''") {
|
|
2646
|
-
r.merged.set(key2, o.random());
|
|
2693
|
+
r.merged.set(key2, o.random(key2));
|
|
2647
2694
|
generated.push(key2);
|
|
2648
2695
|
}
|
|
2649
2696
|
}
|
|
@@ -2686,6 +2733,13 @@ async function writeSecurely(target, text2) {
|
|
|
2686
2733
|
});
|
|
2687
2734
|
}
|
|
2688
2735
|
}
|
|
2736
|
+
function isGitIgnored(git, repoRoot, file) {
|
|
2737
|
+
return git.checkIgnore(repoRoot, file);
|
|
2738
|
+
}
|
|
2739
|
+
function notIgnoredWarning(file, repo) {
|
|
2740
|
+
const shown = repo ? join13(repo, file) : file;
|
|
2741
|
+
return `${shown} is not ignored by git. Add it to .gitignore; if it is already committed, run git ${repo ? `-C ${repo} ` : ""}rm --cached ${file}.`;
|
|
2742
|
+
}
|
|
2689
2743
|
async function syncEnvFile(o) {
|
|
2690
2744
|
const existing = await readOrNull(o.target);
|
|
2691
2745
|
const plan = planPull({
|
|
@@ -2699,7 +2753,7 @@ async function syncEnvFile(o) {
|
|
|
2699
2753
|
});
|
|
2700
2754
|
if (existing !== null && plan.text === existing) await chmod2(o.target, 384);
|
|
2701
2755
|
else await writeSecurely(o.target, plan.text);
|
|
2702
|
-
return { created: plan.created, kept: plan.kept };
|
|
2756
|
+
return { created: plan.created, kept: plan.kept, ignored: await isGitIgnored(o.git, o.repoRoot, o.target) };
|
|
2703
2757
|
}
|
|
2704
2758
|
|
|
2705
2759
|
// src/core/erd/source.ts
|
|
@@ -2713,7 +2767,7 @@ async function resolveDatabaseUrl(deps2, mc, app) {
|
|
|
2713
2767
|
const cfg = await readRepoConfig(mc.repoRoot);
|
|
2714
2768
|
const envFile = await resolveTarget(mc.repoRoot, cfg.envFile ?? moduleDefaults(mc.module.type).envFile);
|
|
2715
2769
|
const text2 = await readOrNull(envFile);
|
|
2716
|
-
const url2 = text2 === null ? void 0 : parseEnv(text2).get("DATABASE_URL")?.trim()
|
|
2770
|
+
const url2 = text2 === null ? void 0 : parseEnv(text2).get("DATABASE_URL")?.trim();
|
|
2717
2771
|
if (url2) {
|
|
2718
2772
|
deps2.registerSecrets([url2]);
|
|
2719
2773
|
return { url: url2, source: "env-file", envFile };
|
|
@@ -2770,9 +2824,9 @@ async function serveErd(o) {
|
|
|
2770
2824
|
const produce = o.routes[path2];
|
|
2771
2825
|
if (produce) {
|
|
2772
2826
|
try {
|
|
2773
|
-
const
|
|
2827
|
+
const body2 = JSON.stringify(await produce());
|
|
2774
2828
|
res.writeHead(200, { "content-type": TYPES[".json"], "cache-control": "no-store" });
|
|
2775
|
-
res.end(
|
|
2829
|
+
res.end(body2);
|
|
2776
2830
|
return;
|
|
2777
2831
|
} catch (e) {
|
|
2778
2832
|
try {
|
|
@@ -2787,9 +2841,9 @@ async function serveErd(o) {
|
|
|
2787
2841
|
const file = resolve6(root, `.${path2 === "/" ? "/index.html" : path2}`);
|
|
2788
2842
|
if (file !== root && !file.startsWith(root + sep3)) return end(res, 404);
|
|
2789
2843
|
try {
|
|
2790
|
-
const
|
|
2844
|
+
const body2 = await readFile6(file);
|
|
2791
2845
|
res.writeHead(200, { "content-type": TYPES[extname(file)] ?? "application/octet-stream" });
|
|
2792
|
-
res.end(
|
|
2846
|
+
res.end(body2);
|
|
2793
2847
|
} catch {
|
|
2794
2848
|
end(res, 404);
|
|
2795
2849
|
}
|
|
@@ -3412,7 +3466,7 @@ async function loadLastStart(deps2, root) {
|
|
|
3412
3466
|
function envPort(env, key2) {
|
|
3413
3467
|
const raw = env[key2];
|
|
3414
3468
|
if (raw === void 0) return null;
|
|
3415
|
-
const v = raw.trim()
|
|
3469
|
+
const v = raw.trim();
|
|
3416
3470
|
if (!/^\d+$/.test(v)) return null;
|
|
3417
3471
|
const n = Number(v);
|
|
3418
3472
|
return n >= 1024 && n <= 65535 ? n : null;
|
|
@@ -3431,7 +3485,9 @@ async function devEnv(deps2, o) {
|
|
|
3431
3485
|
fetched: local.env,
|
|
3432
3486
|
managed: local.managedKeys,
|
|
3433
3487
|
localSecrets: o.cfg.localSecrets ?? defaults.localSecrets,
|
|
3434
|
-
random: o.random
|
|
3488
|
+
random: (key2) => o.random(key2, local.rules?.[key2]),
|
|
3489
|
+
git: deps2.git,
|
|
3490
|
+
repoRoot: o.root
|
|
3435
3491
|
});
|
|
3436
3492
|
return {
|
|
3437
3493
|
env: local.env,
|
|
@@ -3453,7 +3509,27 @@ async function devEnv(deps2, o) {
|
|
|
3453
3509
|
});
|
|
3454
3510
|
}
|
|
3455
3511
|
const env = Object.fromEntries(parseEnv(text2));
|
|
3456
|
-
return { env, offline: true, envFile: target, port: envPort(env, "PORT"), dbPort: envPort(env, "DB_PORT"), created: false, kept: [] };
|
|
3512
|
+
return { env, offline: true, envFile: target, port: envPort(env, "PORT"), dbPort: envPort(env, "DB_PORT"), created: false, kept: [], ignored: null };
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
// src/core/env/secret.ts
|
|
3516
|
+
var DEFAULT_LENGTH = 64;
|
|
3517
|
+
function body(format, length, bytes) {
|
|
3518
|
+
if (length === 0) return "";
|
|
3519
|
+
if (format === "hex") return bytes(Math.ceil(length / 2)).toString("hex").slice(0, length);
|
|
3520
|
+
return bytes(Math.ceil(length * 3 / 4)).toString(format).slice(0, length);
|
|
3521
|
+
}
|
|
3522
|
+
function generateSecret(rules, bytes) {
|
|
3523
|
+
const prefix = rules?.startsWith ?? "";
|
|
3524
|
+
const suffix = rules?.endsWith ?? "";
|
|
3525
|
+
const format = rules?.format ?? "hex";
|
|
3526
|
+
let length = Math.max(rules?.minLength ?? 0, DEFAULT_LENGTH);
|
|
3527
|
+
if (rules?.maxLength !== void 0) length = Math.min(length, rules.maxLength);
|
|
3528
|
+
if (format === "base64" && length % 4) {
|
|
3529
|
+
const up = length + 4 - length % 4;
|
|
3530
|
+
length = rules?.maxLength === void 0 || up <= rules.maxLength ? up : length - length % 4;
|
|
3531
|
+
}
|
|
3532
|
+
return prefix + body(format, Math.max(0, length - prefix.length - suffix.length), bytes) + suffix;
|
|
3457
3533
|
}
|
|
3458
3534
|
|
|
3459
3535
|
// src/core/workspace/access.ts
|
|
@@ -3556,6 +3632,16 @@ function providerDown(o) {
|
|
|
3556
3632
|
action: { command: o.fix }
|
|
3557
3633
|
};
|
|
3558
3634
|
}
|
|
3635
|
+
function noLocalRole(o) {
|
|
3636
|
+
return {
|
|
3637
|
+
code: "dev.no-local-role",
|
|
3638
|
+
severity: "warn",
|
|
3639
|
+
module: o.slug,
|
|
3640
|
+
message: `You have no role on local in ${o.app} \u2014 signing in to ${o.slug} will be refused.`,
|
|
3641
|
+
why: o.known.length > 0 ? `Roles known on local: ${o.known.join(", ")}. Sign in again after taking one.` : "Local knows no roles yet; `qore roles use` also announces the roles in your code. Sign in again after taking one.",
|
|
3642
|
+
action: { command: `${o.cd}${o.known.length === 1 ? `qore roles use ${o.known[0]}` : "qore roles use <role>"}` }
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
3559
3645
|
|
|
3560
3646
|
// src/core/dev/project.ts
|
|
3561
3647
|
import { access, readFile as readFile7 } from "fs/promises";
|
|
@@ -4003,6 +4089,63 @@ async function leftoverOwnsPort(deps2, run4, port) {
|
|
|
4003
4089
|
return false;
|
|
4004
4090
|
}
|
|
4005
4091
|
|
|
4092
|
+
// src/core/roles/api.ts
|
|
4093
|
+
var CAPABILITY = "module.local-roles";
|
|
4094
|
+
var path = (mc, app) => `/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/local-roles?app_id=${encodeURIComponent(app.id)}`;
|
|
4095
|
+
async function fetchLocalRoles(deps2, mc, app) {
|
|
4096
|
+
await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
|
|
4097
|
+
return explained(mc, () => mc.session.api.get(path(mc, app)));
|
|
4098
|
+
}
|
|
4099
|
+
async function useLocalRoles(deps2, mc, app, roles, use) {
|
|
4100
|
+
await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
|
|
4101
|
+
return explained(mc, () => mc.session.api.post(path(mc, app), { roles, use }));
|
|
4102
|
+
}
|
|
4103
|
+
var ANNOUNCE_CAPABILITY = "module.local-roles-announce";
|
|
4104
|
+
async function announceLocalRoles(deps2, mc, app, roles) {
|
|
4105
|
+
await ensureCapability(deps2, mc.portal.apiOrigin, ANNOUNCE_CAPABILITY);
|
|
4106
|
+
return explained(mc, () => mc.session.api.post(path(mc, app), { roles }));
|
|
4107
|
+
}
|
|
4108
|
+
async function explained(mc, call) {
|
|
4109
|
+
try {
|
|
4110
|
+
return await call();
|
|
4111
|
+
} catch (e) {
|
|
4112
|
+
if (!(e instanceof QoreError)) throw e;
|
|
4113
|
+
if (e.serverCode === "app.access.denied") {
|
|
4114
|
+
throw withDetails(
|
|
4115
|
+
e,
|
|
4116
|
+
{ required: "write", have: mc.module.access },
|
|
4117
|
+
`You have ${mc.module.access} on ${mc.module.slug}; local roles need write. Ask a maintainer of the app's dev team for write access.`
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
4120
|
+
if (e.serverCode === "membership.permission.denied") {
|
|
4121
|
+
throw withDetails(e, {}, "Taking roles on this app needs write on one of its dev teams.");
|
|
4122
|
+
}
|
|
4123
|
+
if (e.serverCode === "auth.scope.insufficient") throw withDetails(e, {}, "Run `qore login` again.");
|
|
4124
|
+
if (e.serverCode === "app.no_platform_identity") {
|
|
4125
|
+
throw new QoreError("QORE_CONTEXT_UNSUPPORTED", "This app manages its own users; the portal hands out no roles for it", {
|
|
4126
|
+
hint: "Give yourself the role in the app's own user admin.",
|
|
4127
|
+
serverCode: e.serverCode,
|
|
4128
|
+
requestId: e.requestId
|
|
4129
|
+
});
|
|
4130
|
+
}
|
|
4131
|
+
throw e;
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
|
|
4135
|
+
// src/core/dev/localRole.ts
|
|
4136
|
+
async function localRoleFinding(deps2, mc, app, env, cd) {
|
|
4137
|
+
if (!env.KC_CLIENT_ID) return null;
|
|
4138
|
+
try {
|
|
4139
|
+
if (!(await metaFor(deps2, mc.portal.apiOrigin)).capabilities.includes("module.local-roles")) return null;
|
|
4140
|
+
const roles = await fetchLocalRoles(deps2, mc, app);
|
|
4141
|
+
if (roles.effective.length > 0) return null;
|
|
4142
|
+
return noLocalRole({ slug: mc.module.slug, app: app.slug, known: roles.roles.map((r) => r.slug), cd });
|
|
4143
|
+
} catch (e) {
|
|
4144
|
+
if (e instanceof QoreError) return null;
|
|
4145
|
+
throw e;
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4006
4149
|
// src/core/dev/providers.ts
|
|
4007
4150
|
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
4008
4151
|
function connPorts(env) {
|
|
@@ -4805,7 +4948,7 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
4805
4948
|
type: u.m.type,
|
|
4806
4949
|
moduleId: u.m.id,
|
|
4807
4950
|
cfg: u.cfg,
|
|
4808
|
-
random: () => randomBytes5
|
|
4951
|
+
random: (_key, rules) => generateSecret(rules, randomBytes5)
|
|
4809
4952
|
});
|
|
4810
4953
|
} catch (e) {
|
|
4811
4954
|
if (offlineCause && isOffline(e)) throw offlineCause;
|
|
@@ -4817,6 +4960,10 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
4817
4960
|
if (online && dev.offline) {
|
|
4818
4961
|
warn(`${slug}: the portal is unreachable \u2014 starting from ${relative6(rootReal, dev.envFile)} as last written; values may be stale.`, { module: slug });
|
|
4819
4962
|
}
|
|
4963
|
+
if (dev.ignored === false) {
|
|
4964
|
+
const repo = await realpath7(u.dir);
|
|
4965
|
+
warn(`${slug}: ${notIgnoredWarning(relative6(repo, dev.envFile), relative6(rootReal, repo))}`, { module: slug });
|
|
4966
|
+
}
|
|
4820
4967
|
if (dev.kept.length) {
|
|
4821
4968
|
warn(
|
|
4822
4969
|
`${slug}: ${dev.kept.length} key(s) differ locally and were kept: ${dev.kept.join(", ")} \u2014 qore env pull --use-portal takes the portal's values`,
|
|
@@ -4824,6 +4971,10 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
4824
4971
|
);
|
|
4825
4972
|
}
|
|
4826
4973
|
report({ module: slug, step: "env", status: "done", detail: relative6(rootReal, dev.envFile) });
|
|
4974
|
+
if (online && !dev.offline) {
|
|
4975
|
+
const role = await localRoleFinding(deps2, mcFor(u), appRef, dev.env, cdPrefix(deps2.home, u.dir));
|
|
4976
|
+
if (role) renderFinding(ctx, role);
|
|
4977
|
+
}
|
|
4827
4978
|
const services = servicesMissing(slug, dev.env, u.recipe, { servicesFlag: f.services, configured: u.cfg.dev?.services !== void 0 });
|
|
4828
4979
|
if (services) renderFinding(ctx, services);
|
|
4829
4980
|
try {
|
|
@@ -5079,14 +5230,15 @@ function parseWaitTimeout(raw) {
|
|
|
5079
5230
|
var str3 = (v) => typeof v === "string" && v.length > 0;
|
|
5080
5231
|
var SHELL_SAFE = /^[A-Za-z0-9_./,:@%+=-]*$/;
|
|
5081
5232
|
var shellQuote = (s) => SHELL_SAFE.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`;
|
|
5082
|
-
function
|
|
5083
|
-
if (/^[A-Za-z]:[\\/]|^\\\\/.test(dir2)) return `cd ${/\s/.test(dir2) ? `"${dir2}"` : dir2} &&
|
|
5233
|
+
function cdPrefix(home, dir2) {
|
|
5234
|
+
if (/^[A-Za-z]:[\\/]|^\\\\/.test(dir2)) return `cd ${/\s/.test(dir2) ? `"${dir2}"` : dir2} && `;
|
|
5084
5235
|
const h = home.length > 1 ? home.replace(/\/+$/, "") : home;
|
|
5085
5236
|
let target = shellQuote(dir2);
|
|
5086
5237
|
if (h && dir2 === h) target = "~";
|
|
5087
5238
|
else if (h && dir2.startsWith(h + "/")) target = `~/${shellQuote(dir2.slice(h.length + 1))}`;
|
|
5088
|
-
return `cd ${target} &&
|
|
5239
|
+
return `cd ${target} && `;
|
|
5089
5240
|
}
|
|
5241
|
+
var cdAndDev = (home, dir2) => `${cdPrefix(home, dir2)}qore dev`;
|
|
5090
5242
|
async function providerFindings(ctx, root, mc, app, env) {
|
|
5091
5243
|
const { deps: deps2 } = ctx;
|
|
5092
5244
|
try {
|
|
@@ -5234,7 +5386,7 @@ async function prepareModule(ctx, f, waitTimeout, p) {
|
|
|
5234
5386
|
type: c.module.type,
|
|
5235
5387
|
moduleId: c.module.id,
|
|
5236
5388
|
cfg,
|
|
5237
|
-
random: () => randomBytes6
|
|
5389
|
+
random: (_key, rules) => generateSecret(rules, randomBytes6)
|
|
5238
5390
|
});
|
|
5239
5391
|
} catch (e) {
|
|
5240
5392
|
if (c.offlineCause && isOffline(e)) throw c.offlineCause;
|
|
@@ -5242,6 +5394,7 @@ async function prepareModule(ctx, f, waitTimeout, p) {
|
|
|
5242
5394
|
}
|
|
5243
5395
|
const envFile = relative7(await realpath8(root), dev.envFile);
|
|
5244
5396
|
if (dev.offline) io2.err(`! The portal is unreachable \u2014 starting from ${envFile} as last written; values may be stale.`);
|
|
5397
|
+
if (dev.ignored === false) io2.err(`! ${notIgnoredWarning(envFile)}`);
|
|
5245
5398
|
if (dev.kept.length) {
|
|
5246
5399
|
io2.err(`! ${dev.kept.length} key(s) differ locally and were kept: ${dev.kept.join(", ")} \u2014 qore env pull --use-portal takes the portal's values`);
|
|
5247
5400
|
}
|
|
@@ -5253,6 +5406,8 @@ async function prepareModule(ctx, f, waitTimeout, p) {
|
|
|
5253
5406
|
if (c.online && !dev.offline) {
|
|
5254
5407
|
const provider = await providerFindings(ctx, root, c.online.mc, c.online.app, dev.env);
|
|
5255
5408
|
if (provider) renderFinding(ctx, provider);
|
|
5409
|
+
const role = await localRoleFinding(deps2, c.online.mc, c.online.app, dev.env, "");
|
|
5410
|
+
if (role) renderFinding(ctx, role);
|
|
5256
5411
|
}
|
|
5257
5412
|
const services = servicesMissing(slug, dev.env, recipe, { servicesFlag: f.services, configured: cfg.dev?.services !== void 0 });
|
|
5258
5413
|
if (services) renderFinding(ctx, services);
|
|
@@ -5600,15 +5755,15 @@ async function runDoctor(deps2, o = {}) {
|
|
|
5600
5755
|
const results = [];
|
|
5601
5756
|
const context = { kind: "none" };
|
|
5602
5757
|
const push = async (id, group, fn, module) => {
|
|
5603
|
-
let
|
|
5758
|
+
let body2;
|
|
5604
5759
|
try {
|
|
5605
|
-
|
|
5760
|
+
body2 = await fn();
|
|
5606
5761
|
} catch (e) {
|
|
5607
|
-
if (e instanceof ToolTimeout)
|
|
5762
|
+
if (e instanceof ToolTimeout) body2 = { status: "warn", label: e.message, details: { timeoutMs: e.ms } };
|
|
5608
5763
|
else if (isCancel(e, signal)) throw e;
|
|
5609
|
-
else
|
|
5764
|
+
else body2 = withError("fail", errorLabel(e), e);
|
|
5610
5765
|
}
|
|
5611
|
-
const r = { id, group, ...module ? { module } : {}, ...
|
|
5766
|
+
const r = { id, group, ...module ? { module } : {}, ...body2 };
|
|
5612
5767
|
results.push(r);
|
|
5613
5768
|
return r;
|
|
5614
5769
|
};
|
|
@@ -5796,7 +5951,7 @@ function registerEnv(program, ctx) {
|
|
|
5796
5951
|
managed: local.managedKeys,
|
|
5797
5952
|
localSecrets: cfg.localSecrets ?? defaults.localSecrets,
|
|
5798
5953
|
defaultChoice: f.usePortal ? "use-portal" : "keep",
|
|
5799
|
-
random: () =>
|
|
5954
|
+
random: (key2) => generateSecret(local.rules?.[key2], randomBytes7)
|
|
5800
5955
|
};
|
|
5801
5956
|
let plan = planPull(inputs);
|
|
5802
5957
|
if (plan.conflicts.length && io2.interactive && !f.usePortal) {
|
|
@@ -5843,6 +5998,7 @@ function registerEnv(program, ctx) {
|
|
|
5843
5998
|
renderJson(io2, { context: contextJson(mc, app), target: rel, ...names });
|
|
5844
5999
|
return;
|
|
5845
6000
|
}
|
|
6001
|
+
if (await isGitIgnored(deps2.git, mc.repoRoot, target) === false) io2.err(`! ${notIgnoredWarning(rel)}`);
|
|
5846
6002
|
if (plan.kept.length && !io2.interactive) {
|
|
5847
6003
|
io2.err(`! ${plan.kept.length} key(s) differ locally and were kept: ${plan.kept.join(", ")} \u2014 --use-portal takes the portal's values`);
|
|
5848
6004
|
}
|
|
@@ -6723,49 +6879,6 @@ function registerLogout(program, ctx) {
|
|
|
6723
6879
|
});
|
|
6724
6880
|
}
|
|
6725
6881
|
|
|
6726
|
-
// src/core/roles/api.ts
|
|
6727
|
-
var CAPABILITY = "module.local-roles";
|
|
6728
|
-
var path = (mc, app) => `/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/local-roles?app_id=${encodeURIComponent(app.id)}`;
|
|
6729
|
-
async function fetchLocalRoles(deps2, mc, app) {
|
|
6730
|
-
await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
|
|
6731
|
-
return explained(mc, () => mc.session.api.get(path(mc, app)));
|
|
6732
|
-
}
|
|
6733
|
-
async function useLocalRoles(deps2, mc, app, roles, use) {
|
|
6734
|
-
await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
|
|
6735
|
-
return explained(mc, () => mc.session.api.post(path(mc, app), { roles, use }));
|
|
6736
|
-
}
|
|
6737
|
-
var ANNOUNCE_CAPABILITY = "module.local-roles-announce";
|
|
6738
|
-
async function announceLocalRoles(deps2, mc, app, roles) {
|
|
6739
|
-
await ensureCapability(deps2, mc.portal.apiOrigin, ANNOUNCE_CAPABILITY);
|
|
6740
|
-
return explained(mc, () => mc.session.api.post(path(mc, app), { roles }));
|
|
6741
|
-
}
|
|
6742
|
-
async function explained(mc, call) {
|
|
6743
|
-
try {
|
|
6744
|
-
return await call();
|
|
6745
|
-
} catch (e) {
|
|
6746
|
-
if (!(e instanceof QoreError)) throw e;
|
|
6747
|
-
if (e.serverCode === "app.access.denied") {
|
|
6748
|
-
throw withDetails(
|
|
6749
|
-
e,
|
|
6750
|
-
{ required: "write", have: mc.module.access },
|
|
6751
|
-
`You have ${mc.module.access} on ${mc.module.slug}; local roles need write. Ask a maintainer of the app's dev team for write access.`
|
|
6752
|
-
);
|
|
6753
|
-
}
|
|
6754
|
-
if (e.serverCode === "membership.permission.denied") {
|
|
6755
|
-
throw withDetails(e, {}, "Taking roles on this app needs write on one of its dev teams.");
|
|
6756
|
-
}
|
|
6757
|
-
if (e.serverCode === "auth.scope.insufficient") throw withDetails(e, {}, "Run `qore login` again.");
|
|
6758
|
-
if (e.serverCode === "app.no_platform_identity") {
|
|
6759
|
-
throw new QoreError("QORE_CONTEXT_UNSUPPORTED", "This app manages its own users; the portal hands out no roles for it", {
|
|
6760
|
-
hint: "Give yourself the role in the app's own user admin.",
|
|
6761
|
-
serverCode: e.serverCode,
|
|
6762
|
-
requestId: e.requestId
|
|
6763
|
-
});
|
|
6764
|
-
}
|
|
6765
|
-
throw e;
|
|
6766
|
-
}
|
|
6767
|
-
}
|
|
6768
|
-
|
|
6769
6882
|
// src/core/roles/read.ts
|
|
6770
6883
|
import { join as join26 } from "path";
|
|
6771
6884
|
|
|
@@ -7519,6 +7632,14 @@ async function status(repoRoot) {
|
|
|
7519
7632
|
if (r.code !== 0) return { ok: false, stderr: r.stderr, command };
|
|
7520
7633
|
return parseStatus(r.stdout);
|
|
7521
7634
|
}
|
|
7635
|
+
async function checkIgnore(repoRoot, file) {
|
|
7636
|
+
try {
|
|
7637
|
+
const r = await runGit(["-C", repoRoot, "check-ignore", "-q", "--", file], repoRoot);
|
|
7638
|
+
return r.code === 0 ? true : r.code === 1 ? false : null;
|
|
7639
|
+
} catch {
|
|
7640
|
+
return null;
|
|
7641
|
+
}
|
|
7642
|
+
}
|
|
7522
7643
|
async function statOrThrow(path2) {
|
|
7523
7644
|
try {
|
|
7524
7645
|
return await stat7(path2);
|
|
@@ -7542,7 +7663,7 @@ async function inspect(dir2) {
|
|
|
7542
7663
|
const dirRemotes = isRepo ? await remotes(dir2) : [];
|
|
7543
7664
|
return { exists: true, empty: empty2, isRepo, remotes: dirRemotes };
|
|
7544
7665
|
}
|
|
7545
|
-
var systemGit = { remotes, clone, fetch, pullFfOnly, status, inspect };
|
|
7666
|
+
var systemGit = { remotes, clone, fetch, pullFfOnly, status, inspect, checkIgnore };
|
|
7546
7667
|
|
|
7547
7668
|
// src/platform/keychain.ts
|
|
7548
7669
|
import { Entry } from "@napi-rs/keyring";
|
|
@@ -8120,4 +8241,4 @@ if (!drained) {
|
|
|
8120
8241
|
process.exit();
|
|
8121
8242
|
}
|
|
8122
8243
|
//# sourceMappingURL=cli.js.map
|
|
8123
|
-
//# debugId=
|
|
8244
|
+
//# debugId=2ac9292b-9c15-5fb7-bdc6-c773ad369497
|