@malloydata/malloyyo 0.2.40 → 0.2.42
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/README.md +43 -7
- package/dist/frame-inpage-entry.tsx +8 -2
- package/dist/index.js +116 -56
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,10 @@ malloyyo logout main
|
|
|
61
61
|
|
|
62
62
|
Login is **per-instance** (it authenticates you to a URL, for all datasets on it), so the
|
|
63
63
|
argument is a *target or URL*, not a dataset — and it's optional when the config is
|
|
64
|
-
unambiguous. It
|
|
64
|
+
unambiguous. It asks the instance for two permissions, which the consent screen names:
|
|
65
|
+
publishing models, and querying them. (A claude.ai connection to the same instance asks
|
|
66
|
+
only to query, so it cannot publish — and a login stored before publishing had a
|
|
67
|
+
permission of its own needs one more `malloyyo login` to gain it.) It uses the instance's OAuth flow (Authorization Code + PKCE, loopback redirect)
|
|
65
68
|
and stores a refreshable token in `~/.config/malloyyo/credentials.json` (mode 0600), keyed by
|
|
66
69
|
instance URL — so you can be logged in to several instances at once. Tokens auto-refresh.
|
|
67
70
|
|
|
@@ -91,11 +94,43 @@ create it under a slugified variant that later publishes wouldn't find.
|
|
|
91
94
|
|
|
92
95
|
`publish` exits non-zero on a server-side compile failure, so it's safe to gate CI on.
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
your `malloyyo login` session. So interactively you just `login` once; in CI you set the env
|
|
96
|
-
var and never touch the browser.
|
|
97
|
+
## API tokens (`MALLOYYO_TOKEN`)
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
For CI, or anywhere there is no browser to sign in with. Mint one in the instance's UI —
|
|
100
|
+
**your name → tokens**, or `<instance-url>/settings/tokens` — and hand it over in the
|
|
101
|
+
environment:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
export MALLOYYO_TOKEN=myo_main_…
|
|
105
|
+
malloyyo publish # no login, no browser, no --token
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Every member of an instance can mint their own; you do not have to be an admin. A token is
|
|
109
|
+
shown **once**, at creation — it is stored hashed, so a lost one is revoked and replaced
|
|
110
|
+
rather than recovered. It carries the scopes you tick:
|
|
111
|
+
|
|
112
|
+
| Scope | What it opens |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `publish` | `malloyyo publish` and `malloyyo status` |
|
|
115
|
+
| `mcp` | querying the instance's published models over MCP |
|
|
116
|
+
|
|
117
|
+
A token never carries more than you do. Publishing works on datasets **you own** (admins may
|
|
118
|
+
publish to any), creating a dataset with `--create-dataset` stays admin-only, and every
|
|
119
|
+
request re-checks your account — so revoking the token, or the account, takes effect on the
|
|
120
|
+
next request rather than at expiry. Expiry is your choice at mint time, including **never**:
|
|
121
|
+
a credential that lapses on its own breaks the pipeline at the worst moment, and the token
|
|
122
|
+
list shows when each was last used so a forgotten one is still visible.
|
|
123
|
+
|
|
124
|
+
**Token precedence:** `--token` flag → the `malloyyo_token` env var named in the config →
|
|
125
|
+
`$MALLOYYO_TOKEN` → your `malloyyo login` session. The config's own variable wins over
|
|
126
|
+
`MALLOYYO_TOKEN` because someone publishing to two instances from one shell needs a
|
|
127
|
+
credential per instance, and one variable can only hold one of them. Both variables sit
|
|
128
|
+
above the stored login, so an export in your shell profile quietly shadows `malloyyo login`
|
|
129
|
+
— `login` warns when that variable is set, and any auth failure names the source it used.
|
|
130
|
+
|
|
131
|
+
See [API tokens](https://github.com/malloydata/malloyyo/blob/main/docs/api-tokens.md) for
|
|
132
|
+
the CI recipe, rotation, and a troubleshooting table, and
|
|
133
|
+
`docs/model-publishing-design.md` in the repo for the publish design.
|
|
99
134
|
|
|
100
135
|
## Malloyyo-hosted instances (`malloyyo cloud`)
|
|
101
136
|
|
|
@@ -148,8 +183,9 @@ export MALLOYYO_CLIENT_SECRET=...
|
|
|
148
183
|
|
|
149
184
|
That is the whole of it — there is nothing else to configure.
|
|
150
185
|
|
|
151
|
-
It is separate from
|
|
152
|
-
|
|
186
|
+
It is separate from the two instance credentials — `malloyyo login` and `$MALLOYYO_TOKEN`,
|
|
187
|
+
both of which authenticate *you* to one instance. This one identifies your account to
|
|
188
|
+
Malloyyo itself, and each command trades it for a short-lived access
|
|
153
189
|
token carrying only the permissions that command needs: a `list` cannot create, and only
|
|
154
190
|
`secrets set` can write secrets. The trade happens against Malloyyo's own API, so the CLI
|
|
155
191
|
talks to nothing else. Your secret is held in memory for that request and is never logged,
|
|
@@ -35,10 +35,16 @@ const givensToUrl = (dashboard, givens) => {
|
|
|
35
35
|
|
|
36
36
|
mountInPage({
|
|
37
37
|
root: document.getElementById("root"),
|
|
38
|
-
// Governed query — the shell's trusted
|
|
38
|
+
// Governed query — the shell's trusted api/run (the same endpoint the iframe
|
|
39
39
|
// broker forwards to). Returns the raw result the runtime normalizes.
|
|
40
|
+
//
|
|
41
|
+
// RELATIVE. A leading slash resolves against the ORIGIN, so behind anything
|
|
42
|
+
// serving this page under a prefix — code-server's `/proxy/<port>/`, a
|
|
43
|
+
// Codespaces forwarded port — the POST went to the proxy's own root and came
|
|
44
|
+
// back `405 Method Not Allowed` from the proxy rather than reaching the dev
|
|
45
|
+
// server at all. Resolved against the document, it is correct at any depth.
|
|
40
46
|
run: (req, givens) =>
|
|
41
|
-
fetch("
|
|
47
|
+
fetch("api/run", {
|
|
42
48
|
method: "POST",
|
|
43
49
|
headers: { "content-type": "application/json" },
|
|
44
50
|
body: JSON.stringify({ d: name, query: req.query, malloy: req.malloy, givens }),
|
package/dist/index.js
CHANGED
|
@@ -2881,7 +2881,7 @@ function clearCreds(url6) {
|
|
|
2881
2881
|
}
|
|
2882
2882
|
|
|
2883
2883
|
// package.json
|
|
2884
|
-
var version = "0.2.
|
|
2884
|
+
var version = "0.2.42";
|
|
2885
2885
|
|
|
2886
2886
|
// src/http.ts
|
|
2887
2887
|
var USER_AGENT = `malloyyo/${version}`;
|
|
@@ -2902,6 +2902,7 @@ async function apiFetch(url6, init = {}) {
|
|
|
2902
2902
|
|
|
2903
2903
|
// src/oauth.ts
|
|
2904
2904
|
var LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2905
|
+
var LOGIN_SCOPE = "mcp publish";
|
|
2905
2906
|
async function discover(baseUrl) {
|
|
2906
2907
|
const res = await apiFetch(`${baseUrl}/api/oauth/discovery/authorization-server`);
|
|
2907
2908
|
if (!res.ok) throw new Error(`OAuth discovery failed at ${baseUrl}: ${res.status} ${res.statusText}`);
|
|
@@ -3021,7 +3022,11 @@ async function login(baseUrl, opts = {}) {
|
|
|
3021
3022
|
redirect_uri: redirectUri,
|
|
3022
3023
|
code_challenge: challenge,
|
|
3023
3024
|
code_challenge_method: "S256",
|
|
3024
|
-
|
|
3025
|
+
// What this CLI does: publish models, and query them (`malloyyo mcp`
|
|
3026
|
+
// against a hosted instance). A claude.ai connection asks for "mcp"
|
|
3027
|
+
// alone and cannot publish — so a login here is not interchangeable
|
|
3028
|
+
// with one, and must say so.
|
|
3029
|
+
scope: LOGIN_SCOPE,
|
|
3025
3030
|
state
|
|
3026
3031
|
}).toString();
|
|
3027
3032
|
if (opts.noBrowser || browserless()) {
|
|
@@ -3063,6 +3068,13 @@ async function login(baseUrl, opts = {}) {
|
|
|
3063
3068
|
expiresAt: Date.now() + (grant.expires_in ?? 86400) * 1e3
|
|
3064
3069
|
};
|
|
3065
3070
|
saveCreds(baseUrl, creds);
|
|
3071
|
+
if (process.env[TOKEN_ENV]) {
|
|
3072
|
+
console.log(
|
|
3073
|
+
`
|
|
3074
|
+
Note: $${TOKEN_ENV} is set in this shell and takes precedence over the
|
|
3075
|
+
login just stored. Unset it to use this login.`
|
|
3076
|
+
);
|
|
3077
|
+
}
|
|
3066
3078
|
return creds;
|
|
3067
3079
|
} finally {
|
|
3068
3080
|
close();
|
|
@@ -3090,14 +3102,21 @@ async function refresh(baseUrl, creds) {
|
|
|
3090
3102
|
saveCreds(baseUrl, updated);
|
|
3091
3103
|
return updated;
|
|
3092
3104
|
}
|
|
3093
|
-
|
|
3105
|
+
var TOKEN_ENV = "MALLOYYO_TOKEN";
|
|
3106
|
+
function looksLikeInstanceToken(value) {
|
|
3107
|
+
return /^myo_[a-z0-9]+_[A-Za-z0-9_-]{20,}$/.test(value);
|
|
3108
|
+
}
|
|
3109
|
+
function tokenSource(target, opts, env = process.env) {
|
|
3094
3110
|
if (opts.tokenFlag) return "flag";
|
|
3095
|
-
if (target.tokenEnv &&
|
|
3111
|
+
if (target.tokenEnv && env[target.tokenEnv]) return "env";
|
|
3112
|
+
if (env[TOKEN_ENV]) return "global-env";
|
|
3096
3113
|
return "login";
|
|
3097
3114
|
}
|
|
3098
|
-
async function getAccessToken(target, opts) {
|
|
3115
|
+
async function getAccessToken(target, opts, env = process.env) {
|
|
3099
3116
|
if (opts.tokenFlag) return opts.tokenFlag;
|
|
3100
|
-
if (target.tokenEnv &&
|
|
3117
|
+
if (target.tokenEnv && env[target.tokenEnv]) return env[target.tokenEnv];
|
|
3118
|
+
const ambient = env[TOKEN_ENV];
|
|
3119
|
+
if (ambient) return ambient;
|
|
3101
3120
|
let creds = loadCreds(target.url);
|
|
3102
3121
|
if (!creds) {
|
|
3103
3122
|
throw new Error(`Not authenticated for ${target.url}.
|
|
@@ -3382,6 +3401,7 @@ function siblingList(current, all, href) {
|
|
|
3382
3401
|
// src/dashboard.ts
|
|
3383
3402
|
var resolveFrameEntry = () => path6.join(resolveRuntimeDir(), "..", "frame-entry.tsx");
|
|
3384
3403
|
var resolveInPageEntry = () => path6.join(resolveRuntimeDir(), "..", "frame-inpage-entry.tsx");
|
|
3404
|
+
var inlineScript = (js) => js.replace(/<\/(script)/gi, String.raw`<\/$1`);
|
|
3385
3405
|
var esc2 = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
3386
3406
|
function makeBundler() {
|
|
3387
3407
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -3457,9 +3477,26 @@ function makeInPageBundler() {
|
|
|
3457
3477
|
};
|
|
3458
3478
|
}
|
|
3459
3479
|
var html = (body, title) => `<!doctype html><html><head><meta charset="utf-8"><title>${esc2(title)}</title><meta name="viewport" content="width=device-width,initial-scale=1"><style>${NAV_CSS}</style></head><body style="margin:0">${body}</body></html>`;
|
|
3460
|
-
var
|
|
3480
|
+
var dashLink = (n) => `?d=${encodeURIComponent(n)}`;
|
|
3481
|
+
var DEV_PATHS = {
|
|
3482
|
+
/** Sibling dashboard, for the switcher in the nav bar. */
|
|
3483
|
+
dashboard: dashLink,
|
|
3484
|
+
/** In-page (tag-only) bundle. */
|
|
3485
|
+
inPage: (n) => `inpage.js?d=${encodeURIComponent(n)}`,
|
|
3486
|
+
/** Artifact bundle, for a dashboard with a Dashboard.tsx. */
|
|
3487
|
+
bundle: (n) => `bundle.js?d=${encodeURIComponent(n)}`,
|
|
3488
|
+
/** The sandboxed artifact document. Same origin as the shell, relative like
|
|
3489
|
+
everything else — the iframe is isolated by its OPAQUE origin (the
|
|
3490
|
+
`allow-scripts`-only sandbox), not by living on a second port. */
|
|
3491
|
+
frame: (n) => `frame?d=${encodeURIComponent(n)}`,
|
|
3492
|
+
/** Live-reload stream. */
|
|
3493
|
+
events: "events",
|
|
3494
|
+
/** The privileged query broker the parent shell brokers postMessage into. */
|
|
3495
|
+
run: "api/run"
|
|
3496
|
+
};
|
|
3497
|
+
var devSiblings = (dash, all) => siblingList(dash.name, all, dashLink);
|
|
3461
3498
|
function navHtml2(dash, all) {
|
|
3462
|
-
return navHtml(dash.name, all,
|
|
3499
|
+
return navHtml(dash.name, all, dashLink);
|
|
3463
3500
|
}
|
|
3464
3501
|
function inPageShell(dash, all, givenSpecs, initialGivens, initialUrlState, tileSpecs) {
|
|
3465
3502
|
const info = {
|
|
@@ -3474,21 +3511,20 @@ function inPageShell(dash, all, givenSpecs, initialGivens, initialUrlState, tile
|
|
|
3474
3511
|
autorun: dash.autorun
|
|
3475
3512
|
};
|
|
3476
3513
|
return html(
|
|
3477
|
-
navHtml2(dash, all) + `<div id="root"></div><script>window.__DASHBOARD__=${safeJson(info)};window.__DASHBOARDS__=${safeJson(devSiblings(dash, all))};window.__GIVENS__=${safeJson(givenSpecs)};window.__INITIAL_GIVENS__=${safeJson(initialGivens)};window.__INITIAL_URLSTATE__=${safeJson(initialUrlState)}</script><script>try{new EventSource('
|
|
3514
|
+
navHtml2(dash, all) + `<div id="root"></div><script>window.__DASHBOARD__=${safeJson(info)};window.__DASHBOARDS__=${safeJson(devSiblings(dash, all))};window.__GIVENS__=${safeJson(givenSpecs)};window.__INITIAL_GIVENS__=${safeJson(initialGivens)};window.__INITIAL_URLSTATE__=${safeJson(initialUrlState)}</script><script>try{new EventSource('${DEV_PATHS.events}').onmessage=()=>location.reload();}catch(e){}</script><script src="${DEV_PATHS.inPage(dash.name)}"></script>`,
|
|
3478
3515
|
dash.title
|
|
3479
3516
|
);
|
|
3480
3517
|
}
|
|
3481
|
-
function parentShell(dash,
|
|
3518
|
+
function parentShell(dash, all, initialGivens, initialUrlState) {
|
|
3482
3519
|
const givensQs = Object.entries({ ...initialGivens, ...initialUrlState }).map(([k, v]) => `&${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("");
|
|
3483
3520
|
const d = safeJson(dash.name);
|
|
3484
|
-
const fb = safeJson(frameBase);
|
|
3485
3521
|
const nav = navHtml2(dash, all);
|
|
3486
3522
|
return html(
|
|
3487
3523
|
`<div style="display:flex;flex-direction:column;height:100vh">` + nav + // allow-popups(+escape-sandbox): let a # link mark open its target in a
|
|
3488
3524
|
// normal new tab on click instead of being blocked by the sandbox.
|
|
3489
|
-
`<iframe id="f" sandbox="allow-scripts allow-
|
|
3525
|
+
`<iframe id="f" sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox" src="${DEV_PATHS.frame(dash.name)}${givensQs}" style="border:0;flex:1;width:100%"></iframe></div><script>
|
|
3490
3526
|
const f=document.getElementById('f');
|
|
3491
|
-
try{new EventSource('
|
|
3527
|
+
try{new EventSource('${DEV_PATHS.events}').onmessage=()=>location.reload();}catch(e){}
|
|
3492
3528
|
// The shareable URL has TWO namespaces the frame syncs independently:
|
|
3493
3529
|
// '$NAME' = a given (the governed query contract), '~key' = a custom
|
|
3494
3530
|
// component's useUrlState view-state. Each write must re-emit the other's
|
|
@@ -3503,7 +3539,7 @@ function shareUrl(dashboard){
|
|
|
3503
3539
|
return u.pathname+u.search;
|
|
3504
3540
|
}
|
|
3505
3541
|
window.addEventListener('message',async(e)=>{
|
|
3506
|
-
if(e.source!==f.contentWindow
|
|
3542
|
+
if(e.source!==f.contentWindow)return;
|
|
3507
3543
|
const m=e.data;
|
|
3508
3544
|
if(m&&m.type==='givens'){
|
|
3509
3545
|
G=m.givens||{};
|
|
@@ -3525,11 +3561,11 @@ window.addEventListener('message',async(e)=>{
|
|
|
3525
3561
|
if(!m||m.type!=='run')return;
|
|
3526
3562
|
let out;
|
|
3527
3563
|
try{
|
|
3528
|
-
const res=await fetch('
|
|
3564
|
+
const res=await fetch('${DEV_PATHS.run}',{method:'POST',headers:{'content-type':'application/json'},
|
|
3529
3565
|
body:JSON.stringify({d:${d},query:m.query,malloy:m.malloy,givens:m.givens,dashboard:m.dashboard})});
|
|
3530
3566
|
out=await res.json();
|
|
3531
3567
|
}catch(err){ out={ok:false,problems:[{message:String(err)}]}; }
|
|
3532
|
-
f.contentWindow.postMessage({type:'result',id:m.id,...out}
|
|
3568
|
+
f.contentWindow.postMessage({type:'result',id:m.id,...out},'*');
|
|
3533
3569
|
});
|
|
3534
3570
|
</script>`,
|
|
3535
3571
|
dash.title
|
|
@@ -3541,7 +3577,7 @@ function givensFromUrl(url6) {
|
|
|
3541
3577
|
function urlStateFromUrl(url6) {
|
|
3542
3578
|
return urlStateFromSearch(url6.search);
|
|
3543
3579
|
}
|
|
3544
|
-
function frameDoc(dash, all, givenSpecs, initialGivens, initialUrlState, tileSpecs) {
|
|
3580
|
+
function frameDoc(dash, all, givenSpecs, initialGivens, initialUrlState, bundleJs, tileSpecs) {
|
|
3545
3581
|
const info = {
|
|
3546
3582
|
name: dash.name,
|
|
3547
3583
|
query: dash.query,
|
|
@@ -3556,7 +3592,7 @@ function frameDoc(dash, all, givenSpecs, initialGivens, initialUrlState, tileSpe
|
|
|
3556
3592
|
autorun: dash.autorun
|
|
3557
3593
|
};
|
|
3558
3594
|
return html(
|
|
3559
|
-
`<div id="root"></div><script>window.__DASHBOARD__=${safeJson(info)};window.__DASHBOARDS__=${safeJson(devSiblings(dash, all))};window.__GIVENS__=${safeJson(givenSpecs)};window.__INITIAL_GIVENS__=${safeJson(initialGivens)};window.__INITIAL_URLSTATE__=${safeJson(initialUrlState)}</script><script
|
|
3595
|
+
`<div id="root"></div><script>window.__DASHBOARD__=${safeJson(info)};window.__DASHBOARDS__=${safeJson(devSiblings(dash, all))};window.__GIVENS__=${safeJson(givenSpecs)};window.__INITIAL_GIVENS__=${safeJson(initialGivens)};window.__INITIAL_URLSTATE__=${safeJson(initialUrlState)}</script><script>${inlineScript(bundleJs)}</script>`,
|
|
3560
3596
|
dash.title
|
|
3561
3597
|
);
|
|
3562
3598
|
}
|
|
@@ -3569,8 +3605,6 @@ async function serveDashboard(opts) {
|
|
|
3569
3605
|
await initConnections();
|
|
3570
3606
|
const root = path6.resolve(opts.root ?? process.cwd());
|
|
3571
3607
|
const port = opts.port ?? 4173;
|
|
3572
|
-
const framePort = port + 1;
|
|
3573
|
-
const frameBase = `http://localhost:${framePort}`;
|
|
3574
3608
|
const runner = await makeRunner(root);
|
|
3575
3609
|
if (!runner.entryExists()) {
|
|
3576
3610
|
throw new Error(`No index.malloy at ${root} \u2014 run this from a Malloy model repo.`);
|
|
@@ -3618,34 +3652,39 @@ async function serveDashboard(opts) {
|
|
|
3618
3652
|
console.error(` (file watch unavailable: ${e.message} \u2014 edits won't auto-reload)`);
|
|
3619
3653
|
}
|
|
3620
3654
|
const handler = async (req, res) => {
|
|
3621
|
-
const
|
|
3622
|
-
const url6 = new URL(req.url ?? "/", `http://localhost:${onFramePort ? framePort : port}`);
|
|
3655
|
+
const url6 = new URL(req.url ?? "/", `http://localhost:${port}`);
|
|
3623
3656
|
const send = (code, type, body, extra = {}) => {
|
|
3624
3657
|
res.writeHead(code, { "content-type": type, ...extra });
|
|
3625
3658
|
res.end(body);
|
|
3626
3659
|
};
|
|
3627
3660
|
try {
|
|
3628
|
-
if (
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
if (!g.ok) {
|
|
3633
|
-
return send(
|
|
3634
|
-
200,
|
|
3635
|
-
"text/html; charset=utf-8",
|
|
3636
|
-
html(`<pre style="color:crimson;padding:16px">model error: ${esc2(g.error)}</pre>`, dash.title)
|
|
3637
|
-
);
|
|
3638
|
-
}
|
|
3661
|
+
if (url6.pathname === "/frame") {
|
|
3662
|
+
const dash = pick(url6);
|
|
3663
|
+
const g = await resolveGivens(dash);
|
|
3664
|
+
if (!g.ok) {
|
|
3639
3665
|
return send(
|
|
3640
3666
|
200,
|
|
3641
3667
|
"text/html; charset=utf-8",
|
|
3642
|
-
|
|
3668
|
+
html(`<pre style="color:crimson;padding:16px">model error: ${esc2(g.error)}</pre>`, dash.title)
|
|
3643
3669
|
);
|
|
3644
3670
|
}
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3671
|
+
return send(
|
|
3672
|
+
200,
|
|
3673
|
+
"text/html; charset=utf-8",
|
|
3674
|
+
frameDoc(
|
|
3675
|
+
dash,
|
|
3676
|
+
dashboards,
|
|
3677
|
+
g.union,
|
|
3678
|
+
givensFromUrl(url6),
|
|
3679
|
+
urlStateFromUrl(url6),
|
|
3680
|
+
await bundle(dash),
|
|
3681
|
+
g.tiles
|
|
3682
|
+
),
|
|
3683
|
+
{ "cache-control": "no-store" }
|
|
3684
|
+
);
|
|
3685
|
+
}
|
|
3686
|
+
if (url6.pathname === "/bundle.js") {
|
|
3687
|
+
return send(200, "application/javascript; charset=utf-8", await bundle(pick(url6)));
|
|
3649
3688
|
}
|
|
3650
3689
|
if (url6.pathname === "/events") {
|
|
3651
3690
|
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
|
|
@@ -3668,17 +3707,24 @@ async function serveDashboard(opts) {
|
|
|
3668
3707
|
return send(
|
|
3669
3708
|
200,
|
|
3670
3709
|
"text/html; charset=utf-8",
|
|
3671
|
-
inPageShell(dash, dashboards, g.union, givensFromUrl(url6), urlStateFromUrl(url6), g.tiles)
|
|
3710
|
+
inPageShell(dash, dashboards, g.union, givensFromUrl(url6), urlStateFromUrl(url6), g.tiles),
|
|
3711
|
+
{ "cache-control": "no-store" }
|
|
3672
3712
|
);
|
|
3673
3713
|
}
|
|
3674
3714
|
return send(
|
|
3675
3715
|
200,
|
|
3676
3716
|
"text/html; charset=utf-8",
|
|
3677
|
-
parentShell(dash,
|
|
3717
|
+
parentShell(dash, dashboards, givensFromUrl(url6), urlStateFromUrl(url6)),
|
|
3718
|
+
{ "cache-control": "no-store" }
|
|
3678
3719
|
);
|
|
3679
3720
|
}
|
|
3680
3721
|
if (url6.pathname === "/inpage.js") {
|
|
3681
|
-
return send(
|
|
3722
|
+
return send(
|
|
3723
|
+
200,
|
|
3724
|
+
"application/javascript; charset=utf-8",
|
|
3725
|
+
await inPageBundle(),
|
|
3726
|
+
{ "cache-control": "no-store" }
|
|
3727
|
+
);
|
|
3682
3728
|
}
|
|
3683
3729
|
if (url6.pathname === "/api/run" && req.method === "POST") {
|
|
3684
3730
|
const { d, query, malloy, givens } = JSON.parse(await readBody(req));
|
|
@@ -3694,12 +3740,10 @@ async function serveDashboard(opts) {
|
|
|
3694
3740
|
}
|
|
3695
3741
|
};
|
|
3696
3742
|
const shellServer = http2.createServer(handler);
|
|
3697
|
-
const frameServer = http2.createServer(handler);
|
|
3698
3743
|
await new Promise((r) => shellServer.listen(port, r));
|
|
3699
|
-
await new Promise((r) => frameServer.listen(framePort, r));
|
|
3700
3744
|
console.error(`
|
|
3701
3745
|
malloyyo dashboard dev \u2014 model: ${root}`);
|
|
3702
|
-
console.error(` http://localhost:${port}
|
|
3746
|
+
console.error(` http://localhost:${port}/`);
|
|
3703
3747
|
for (const d of dashboards) {
|
|
3704
3748
|
const kind = d.tsxPath ? "custom (iframe)" : "tag-only (in-page)";
|
|
3705
3749
|
console.error(` \u2022 ${d.name} (${kind}) \u2192 http://localhost:${port}/?d=${d.name}`);
|
|
@@ -5312,20 +5356,34 @@ ${SECRETS_SET_HELP}
|
|
|
5312
5356
|
function shortSha(sha) {
|
|
5313
5357
|
return sha ? sha.slice(0, 7) : "";
|
|
5314
5358
|
}
|
|
5315
|
-
function authHint(status2, t, source) {
|
|
5359
|
+
function authHint(status2, t, source, foreignValue = false) {
|
|
5316
5360
|
const login2 = `malloyyo login ${t.name}`;
|
|
5361
|
+
const mint = `${t.url}/settings/tokens`;
|
|
5317
5362
|
if (status2 === 403) {
|
|
5318
|
-
|
|
5319
|
-
The
|
|
5320
|
-
|
|
5321
|
-
|
|
5363
|
+
const why = `
|
|
5364
|
+
The credential is valid, but it isn't allowed to do this on ${t.url}.
|
|
5365
|
+
The model surface needs the "publish" scope, on an account that owns the
|
|
5366
|
+
dataset (or is an admin there).`;
|
|
5367
|
+
return source === "login" ? why + `
|
|
5368
|
+
A login stored before that scope existed carries only "mcp". Run: ${login2}` : why + `
|
|
5369
|
+
Mint a token carrying it at: ${mint}`;
|
|
5370
|
+
}
|
|
5371
|
+
const wrongSecret = foreignValue ? `
|
|
5372
|
+
(that value isn't shaped like a Malloyyo token \u2014 is the variable still
|
|
5373
|
+
set to something else, like a warehouse password?)` : "";
|
|
5322
5374
|
switch (source) {
|
|
5323
5375
|
case "flag":
|
|
5324
5376
|
return `
|
|
5325
|
-
That token came from --token.
|
|
5377
|
+
That token came from --token. Mint one at ${mint}, or run: ${login2}${wrongSecret}`;
|
|
5326
5378
|
case "env":
|
|
5327
5379
|
return `
|
|
5328
|
-
That token came from $${t.tokenEnv}.
|
|
5380
|
+
That token came from $${t.tokenEnv}. Mint a replacement at ${mint},
|
|
5381
|
+
or unset it and run: ${login2}${wrongSecret}`;
|
|
5382
|
+
case "global-env":
|
|
5383
|
+
return `
|
|
5384
|
+
That token came from $${TOKEN_ENV}. It may be revoked, or minted for a
|
|
5385
|
+
different instance. Mint one for ${t.url} at: ${mint}
|
|
5386
|
+
Or unset the variable and run: ${login2}${wrongSecret}`;
|
|
5329
5387
|
default:
|
|
5330
5388
|
return `
|
|
5331
5389
|
Your saved login for ${t.url} is expired or revoked.
|
|
@@ -5357,9 +5415,10 @@ function failureHint(out, t) {
|
|
|
5357
5415
|
return "";
|
|
5358
5416
|
}
|
|
5359
5417
|
}
|
|
5360
|
-
function requestFailed(what, res, out, t, source) {
|
|
5418
|
+
function requestFailed(what, res, out, t, source, bearer) {
|
|
5361
5419
|
const detail = out.error ?? `${res.status} ${res.statusText}`;
|
|
5362
|
-
const
|
|
5420
|
+
const foreign = (source === "env" || source === "global-env") && !!bearer && !looksLikeInstanceToken(bearer);
|
|
5421
|
+
const hint = res.status === 401 || res.status === 403 ? authHint(res.status, t, source, foreign) : failureHint(out, t);
|
|
5363
5422
|
return new Error(`${what} failed: ${detail}${hint}`);
|
|
5364
5423
|
}
|
|
5365
5424
|
var PUBLISH_HELP = `Target resolution:
|
|
@@ -5372,7 +5431,8 @@ var PUBLISH_HELP = `Target resolution:
|
|
|
5372
5431
|
|
|
5373
5432
|
-i takes what \`login\` takes: a URL, or the name of a configured target
|
|
5374
5433
|
whose url should be borrowed. Authenticate the same way as always:
|
|
5375
|
-
\`malloyyo login <url>\`, or
|
|
5434
|
+
\`malloyyo login <url>\`, or set $MALLOYYO_TOKEN (mint one at
|
|
5435
|
+
<url>/settings/tokens \u2014 that is what CI wants), or pass --token.`;
|
|
5376
5436
|
async function publish(target, dir, opts) {
|
|
5377
5437
|
const root = resolve3(dir);
|
|
5378
5438
|
const t = resolvePublishTarget(root, target, {
|
|
@@ -5415,7 +5475,7 @@ async function publish(target, dir, opts) {
|
|
|
5415
5475
|
});
|
|
5416
5476
|
const out = await res.json().catch(() => ({}));
|
|
5417
5477
|
if (!res.ok || !out.ok) {
|
|
5418
|
-
throw requestFailed("publish", res, out, t, source);
|
|
5478
|
+
throw requestFailed("publish", res, out, t, source, bearer);
|
|
5419
5479
|
}
|
|
5420
5480
|
if (out.created) {
|
|
5421
5481
|
console.log(`\u2713 created dataset ${out.dataset ?? t.dataset} (private) \u2014 ${t.url}/datasets/${out.dataset ?? t.dataset}`);
|
|
@@ -5433,7 +5493,7 @@ async function status(target, opts) {
|
|
|
5433
5493
|
});
|
|
5434
5494
|
if (!res.ok) {
|
|
5435
5495
|
const body = await res.json().catch(() => ({}));
|
|
5436
|
-
throw requestFailed("status", res, body, t, source);
|
|
5496
|
+
throw requestFailed("status", res, body, t, source, bearer);
|
|
5437
5497
|
}
|
|
5438
5498
|
const s = await res.json();
|
|
5439
5499
|
const git = s.git;
|