@steve31415/baselib 3.35.0 → 3.36.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/deploy/deploy.js +17 -3
- package/dist/s2s.d.ts +6 -2
- package/dist/s2s.js +11 -0
- package/package.json +1 -1
package/dist/deploy/deploy.js
CHANGED
|
@@ -15,6 +15,20 @@ import { acquireLock, clearHold, publishRetainedAssets, readHold, readReleaseRec
|
|
|
15
15
|
import { consistentBaseSha, readServingState, SHA40 } from './plan.js';
|
|
16
16
|
const RELEASE_DEADLINE_MS = 25 * 60_000;
|
|
17
17
|
const IMAGE_DIGEST = /@sha256:[0-9a-f]{64}$/;
|
|
18
|
+
const MAX_DIRTY_PATHS = 20;
|
|
19
|
+
/** The clean-worktree refusal, naming what made the tree dirty (`git status
|
|
20
|
+
* --porcelain` lines) so the reader need not go and look (2026-10-11: games'
|
|
21
|
+
* deploy checkout held untracked Cloudflare-era build outputs). */
|
|
22
|
+
function dirtyWorktreeMessage(porcelain) {
|
|
23
|
+
const lines = porcelain.split('\n').filter((l) => l.trim() !== '');
|
|
24
|
+
const shown = lines.slice(0, MAX_DIRTY_PATHS);
|
|
25
|
+
const more = lines.length - shown.length;
|
|
26
|
+
return [
|
|
27
|
+
'deploys require a clean worktree; uncommitted or untracked files:',
|
|
28
|
+
...shown.map((l) => ` ${l}`),
|
|
29
|
+
...(more > 0 ? [` … and ${more} more`] : []),
|
|
30
|
+
].join('\n');
|
|
31
|
+
}
|
|
18
32
|
export async function runDeploy(options) {
|
|
19
33
|
const log = options.log ?? ((m) => console.error(`[pw-deploy] ${m}`));
|
|
20
34
|
const runner = options.runner;
|
|
@@ -37,9 +51,9 @@ export async function runDeploy(options) {
|
|
|
37
51
|
throw new Error('deploys run from main');
|
|
38
52
|
const dirty = (await must(runner, 'git', ['status', '--porcelain=v1', '--untracked-files=all'], {
|
|
39
53
|
cwd: options.repoRoot,
|
|
40
|
-
})).stdout
|
|
41
|
-
if (dirty)
|
|
42
|
-
throw new Error(
|
|
54
|
+
})).stdout;
|
|
55
|
+
if (dirty.trim())
|
|
56
|
+
throw new Error(dirtyWorktreeMessage(dirty));
|
|
43
57
|
const sha = (await must(runner, 'git', ['rev-parse', 'HEAD'], { cwd: options.repoRoot })).stdout.trim();
|
|
44
58
|
const originMain = (await must(runner, 'git', ['rev-parse', 'origin/main'], { cwd: options.repoRoot })).stdout.trim();
|
|
45
59
|
if (sha !== originMain)
|
package/dist/s2s.d.ts
CHANGED
|
@@ -7,8 +7,12 @@ import { type Logger } from './log-core.js';
|
|
|
7
7
|
* disables the always-allow rule (fail closed). */
|
|
8
8
|
export declare function codingAgentSa(): string | undefined;
|
|
9
9
|
/** caller service-account email → allowed "METHOD /path" patterns.
|
|
10
|
-
* Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*"
|
|
11
|
-
*
|
|
10
|
+
* Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*",
|
|
11
|
+
* a prefix: the bare path and everything under it), a single-segment
|
|
12
|
+
* wildcard anywhere else ("GET /api/tasks/*\/card": exactly one non-empty
|
|
13
|
+
* segment in that position, so one task-scoped method can be granted without
|
|
14
|
+
* the whole prefix — 2026-10-12, Radar's grant on Coder's card and decide
|
|
15
|
+
* routes), or "*" for everything. */
|
|
12
16
|
export type Grants = Record<string, string[]>;
|
|
13
17
|
export interface ServiceCaller {
|
|
14
18
|
type: 's2s';
|
package/dist/s2s.js
CHANGED
|
@@ -40,9 +40,20 @@ export function grantAllows(grants, email, method, path) {
|
|
|
40
40
|
const prefix = p.slice(0, -1); // keep the trailing slash
|
|
41
41
|
return want.startsWith(prefix) || want === p.slice(0, -2);
|
|
42
42
|
}
|
|
43
|
+
if (p.includes('/*/'))
|
|
44
|
+
return segmentsMatch(p, want);
|
|
43
45
|
return want === p;
|
|
44
46
|
});
|
|
45
47
|
}
|
|
48
|
+
/** "METHOD /a/*\/b" against "METHOD /a/x/b": the same number of segments,
|
|
49
|
+
* each equal or a `*` standing for exactly one non-empty segment. */
|
|
50
|
+
function segmentsMatch(pattern, want) {
|
|
51
|
+
const ps = pattern.split('/');
|
|
52
|
+
const ws = want.split('/');
|
|
53
|
+
if (ps.length !== ws.length)
|
|
54
|
+
return false;
|
|
55
|
+
return ps.every((seg, i) => (seg === '*' ? ws[i].length > 0 : seg === ws[i]));
|
|
56
|
+
}
|
|
46
57
|
// Fixed-window per-identity rate limiter — a sanity check against runaway
|
|
47
58
|
// loops and mischief, not a precision tool (per-instance state only).
|
|
48
59
|
export class RateLimiter {
|
package/package.json
CHANGED