clavarium 0.2.76-next.1 → 0.2.78-next.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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/accounts.mjs +9 -5
- package/server/gitkeeper.mjs +30 -1
- package/web/app.js +10 -1
- package/web/index.html +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.78-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.78-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/accounts.mjs
CHANGED
|
@@ -27,10 +27,14 @@ import { consentUrl, exchangeCode, extractCode, thunderbird, scopeFor, pkcePair,
|
|
|
27
27
|
|
|
28
28
|
/* The loopback the provider sends the code back to; nothing listens there. The
|
|
29
29
|
person's browser lands on a page that will not load, and they copy the whole
|
|
30
|
-
address -- which carries the code -- back into Clavarium.
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
address -- which carries the code -- back into Clavarium. The same address
|
|
31
|
+
trades the code, so it only has to stay constant. Google's desktop client
|
|
32
|
+
accepts any 127.0.0.1 port; Microsoft (Azure) rejects a 127.0.0.1 whose exact
|
|
33
|
+
port is not registered but accepts http://localhost with ANY port for a public
|
|
34
|
+
client, so Microsoft uses localhost. */
|
|
33
35
|
const REDIRECT = 'http://127.0.0.1:47813/';
|
|
36
|
+
const REDIRECT_LOCALHOST = 'http://localhost:47813/';
|
|
37
|
+
const redirectFor = (provider) => (provider === 'microsoft' ? REDIRECT_LOCALHOST : REDIRECT);
|
|
34
38
|
const PENDING_MS = 10 * 60_000;
|
|
35
39
|
const PENDING_MAX = 20;
|
|
36
40
|
|
|
@@ -85,7 +89,7 @@ export class Accounts {
|
|
|
85
89
|
const { clientId } = thunderbird(prov);
|
|
86
90
|
const state = newState();
|
|
87
91
|
const { verifier, challenge } = pkcePair();
|
|
88
|
-
const url = consentUrl(prov, { clientId, redirectUri:
|
|
92
|
+
const url = consentUrl(prov, { clientId, redirectUri: redirectFor(prov), scope: scopeFor(prov, chosen), state, codeChallenge: challenge, loginHint: address });
|
|
89
93
|
this.#pending.set(state, { provider: prov, user: address, kinds: chosen, verifier, at: Date.now() });
|
|
90
94
|
return { url };
|
|
91
95
|
}
|
|
@@ -103,7 +107,7 @@ export class Accounts {
|
|
|
103
107
|
try { code = extractCode(redirected, { state }); } catch (e) { throw new Refusal(400, e.message); }
|
|
104
108
|
const { clientId, clientSecret } = thunderbird(p.provider);
|
|
105
109
|
let refreshToken;
|
|
106
|
-
try { ({ refreshToken } = await exchangeCode(p.provider, { clientId, clientSecret, redirectUri:
|
|
110
|
+
try { ({ refreshToken } = await exchangeCode(p.provider, { clientId, clientSecret, redirectUri: redirectFor(p.provider), code, codeVerifier: p.verifier, fetch: this.#fetch })); }
|
|
107
111
|
catch (e) { throw new Refusal(502, `The connection could not be completed: ${e.message}`); }
|
|
108
112
|
if (!refreshToken) throw new Refusal(502, 'The account returned no lasting token; allow offline access and try again.');
|
|
109
113
|
/* The token is kept host-only: it can never be attached to a conversation,
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -211,9 +211,15 @@ const seeCommits = (name, head, base, n) => (short(head) && short(base) && Numbe
|
|
|
211
211
|
long a finished run is kept for the request that asks again just after. */
|
|
212
212
|
export const CHECK_WAIT_MS = 20_000;
|
|
213
213
|
export const CHECK_KEEP_MS = 60_000;
|
|
214
|
+
/* A send (the push to the remote) runs in the background, like a check: one
|
|
215
|
+
request waits at most this long, then hears { status: 'sending' } and asks
|
|
216
|
+
again (join), so a long push never outruns the proxy. The push itself is
|
|
217
|
+
already bounded (PUSH_MS); a finished send is kept this long for the asking. */
|
|
218
|
+
export const SENDING_WAIT_MS = 20_000;
|
|
219
|
+
export const SENDING_KEEP_MS = 60_000;
|
|
214
220
|
|
|
215
221
|
export class GitKeeper {
|
|
216
|
-
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map();
|
|
222
|
+
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map(); #sending = new Map();
|
|
217
223
|
|
|
218
224
|
/* `review`: GitReview (reads, the reference, Send). `checks`: GitChecks.
|
|
219
225
|
`alerts`: what tells the owner's phone. `tellAgent(repository, line,
|
|
@@ -556,7 +562,30 @@ export class GitKeeper {
|
|
|
556
562
|
|
|
557
563
|
/* Send, from the page: as GitReview.push, and refused when the owner
|
|
558
564
|
requires passing checks and none passed for this commit and branch. */
|
|
565
|
+
/* The push runs in the background; the request waits at most SENDING_WAIT_MS,
|
|
566
|
+
then returns { status: 'sending' } and the page asks again with `join: true`
|
|
567
|
+
until it ends -- so a slow push never blocks the request past the proxy's
|
|
568
|
+
patience. The push itself is still bounded (PUSH_MS), so it cannot run on
|
|
569
|
+
for hours. A send already going is joined; one just ended is re-run only
|
|
570
|
+
on a fresh click (no `join`), and re-sending the same commit is a no-op. */
|
|
559
571
|
async send(name, body) {
|
|
572
|
+
const r = this.#repository(name);
|
|
573
|
+
const key = `${r.name}\n${body?.head ?? ''}\n${body?.target ?? ''}`;
|
|
574
|
+
let entry = this.#sending.get(key);
|
|
575
|
+
if (!entry || (entry.done && body?.join !== true)) {
|
|
576
|
+
const made = { done: false, result: undefined, error: undefined };
|
|
577
|
+
made.run = this.#doSend(r.name, body)
|
|
578
|
+
.then((result) => { made.result = result; }, (error) => { made.error = error; })
|
|
579
|
+
.finally(() => { made.done = true; setTimeout(() => { if (this.#sending.get(key) === made) this.#sending.delete(key); }, SENDING_KEEP_MS).unref?.(); });
|
|
580
|
+
entry = made; this.#sending.set(key, made);
|
|
581
|
+
}
|
|
582
|
+
const ms = Number.isFinite(body?.wait) ? Math.max(0, Math.min(body.wait, SENDING_WAIT_MS)) : SENDING_WAIT_MS;
|
|
583
|
+
await Promise.race([entry.run, new Promise((res) => { setTimeout(res, ms).unref?.(); })]);
|
|
584
|
+
if (!entry.done) return { status: 'sending' };
|
|
585
|
+
if (entry.error) throw entry.error;
|
|
586
|
+
return entry.result;
|
|
587
|
+
}
|
|
588
|
+
async #doSend(name, body) {
|
|
560
589
|
const r = this.#repository(name);
|
|
561
590
|
if (this.settings(r.name).requireForSend) {
|
|
562
591
|
const target = body?.target || undefined;
|
package/web/app.js
CHANGED
|
@@ -3815,7 +3815,16 @@
|
|
|
3815
3815
|
for (const r of p) {
|
|
3816
3816
|
r.sending = true; paint();
|
|
3817
3817
|
try {
|
|
3818
|
-
|
|
3818
|
+
/* The push runs in the background: the first request starts it, and
|
|
3819
|
+
while it says "sending" the page asks again (join) until it ends --
|
|
3820
|
+
a long push never looks like a failure or a restart. */
|
|
3821
|
+
let sent;
|
|
3822
|
+
for (let first = true; ; first = false) {
|
|
3823
|
+
sent = await post(`${API}/git/${r.name}/push`, first
|
|
3824
|
+
? { head: r.out.head, target: r.out.target, ...(r.out.guards?.confirm ? { sure: true } : {}) }
|
|
3825
|
+
: { head: r.out.head, target: r.out.target, join: true });
|
|
3826
|
+
if (sent?.status !== 'sending') break;
|
|
3827
|
+
}
|
|
3819
3828
|
r.sent = { ok: true, text: sent.already ? `✓ Already in ${sent.branch}` : sent.commits > 0 ? `✓ Sent to ${sent.branch}` : `✓ Made ${sent.branch}` };
|
|
3820
3829
|
} catch (error) { r.sent = { ok: false, text: /^Not sent/.test(error.message) ? error.message : `Not sent: ${error.message}` }; }
|
|
3821
3830
|
r.sending = false; paint();
|
package/web/index.html
CHANGED
|
@@ -548,7 +548,7 @@
|
|
|
548
548
|
<div class="row"><button type="button" id="connexion-open" class="primary">Open the sign-in page</button></div>
|
|
549
549
|
<div id="connexion-paste" hidden>
|
|
550
550
|
<label for="connexion-code">After you allow, the page will not load — copy its full address and paste it here</label>
|
|
551
|
-
<div class="row"><input id="connexion-code" spellcheck="false" autocapitalize="off" placeholder="http://127.0.0.1..."><button type="button" id="connexion-connect" class="primary">Connect</button></div>
|
|
551
|
+
<div class="row"><input id="connexion-code" spellcheck="false" autocapitalize="off" placeholder="http://localhost... or http://127.0.0.1..."><button type="button" id="connexion-connect" class="primary">Connect</button></div>
|
|
552
552
|
</div>
|
|
553
553
|
<p id="connexion-error" class="error" role="alert" hidden></p>
|
|
554
554
|
</form>
|