@stacksjs/actions 0.75.593 → 0.75.597
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 +33 -0
- package/dist/library/installed.d.ts +2 -0
- package/dist/library/installed.js +1 -0
- package/dist/release-evidence.d.ts +16 -0
- package/dist/release-evidence.js +1 -1
- package/package.json +44 -44
package/README.md
CHANGED
|
@@ -92,6 +92,39 @@ safe derived download URL. The shared CI evaluator preserves the framework's
|
|
|
92
92
|
existing job selection and never-started-job retry policy; callers provide their
|
|
93
93
|
own workflow/job names. Ownership receipts are data, never historical code.
|
|
94
94
|
|
|
95
|
+
## Installed library payloads
|
|
96
|
+
|
|
97
|
+
Use the narrow `@stacksjs/actions/library/installed` entrypoint to verify a
|
|
98
|
+
caller-owned, stable installation against the native archive reader:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { libraryArchiveEntries } from '@stacksjs/actions/library/archive'
|
|
102
|
+
import { inspectInstalledLibraryPackage } from '@stacksjs/actions/library/installed'
|
|
103
|
+
|
|
104
|
+
const expected = await libraryArchiveEntries(archiveBytes)
|
|
105
|
+
const actual = inspectInstalledLibraryPackage(installedDirectory, expected, {
|
|
106
|
+
consumerRoot: isolatedConsumerDirectory,
|
|
107
|
+
allowBunTag: true, // Optional Bun file-archive installer marker only.
|
|
108
|
+
})
|
|
109
|
+
// Run product checks or serve browser fixtures using this complete actual Map.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Inspection checks every actual file and the complete expected key set, then
|
|
113
|
+
returns freshly read bytes. Missing, changed and unexpected files, symlinks,
|
|
114
|
+
special files, unsafe paths and consumer-root escapes fail closed. Standalone
|
|
115
|
+
inspection also checks nested `node_modules`; it has no arbitrary ignore list.
|
|
116
|
+
The optional root `.bun-tag` must be a regular 95-byte SHA-512 SRI marker and is
|
|
117
|
+
excluded from the returned archive payload. This checks its shape, not installer
|
|
118
|
+
authenticity. A marker already present in the expected archive must match its
|
|
119
|
+
expected bytes normally.
|
|
120
|
+
|
|
121
|
+
Default budgets are 100,000 entries (including directories/installer metadata),
|
|
122
|
+
128 nested directory levels, and 256 MiB of total and individual file bytes.
|
|
123
|
+
`maxEntries`, `maxDepth`, `maxBytes` and `maxFileBytes` accept positive safe
|
|
124
|
+
integers. The total includes allowed installer metadata. Inspection does not
|
|
125
|
+
establish registry/source ownership or provide a snapshot against concurrent
|
|
126
|
+
writers; use an isolated installation with no concurrent mutation.
|
|
127
|
+
|
|
95
128
|
## 🧪 Testing
|
|
96
129
|
|
|
97
130
|
```bash
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{inspectInstalledLibraryPackage}from"../release-evidence.js";
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspect a stable, caller-owned installation against libraryArchiveEntries().
|
|
3
|
+
* Returns every actual package file only after complete key-set/byte equality.
|
|
4
|
+
* Rejects links, special files, unsafe paths and budget overruns. Optional Bun
|
|
5
|
+
* installer metadata is checked and omitted from the returned archive payload.
|
|
6
|
+
* This verifies local bytes, not registry/source ownership or concurrent writers.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inspectInstalledLibraryPackage(directory: string, expected: ReadonlyMap<string, Uint8Array>, options?: InstalledLibraryPackageOptions): Map<string, Uint8Array>;
|
|
1
9
|
/** Validate data before using any value as a URL, filesystem path or command. */
|
|
2
10
|
export declare function validateReleaseEvidencePlan(value: unknown): asserts value is ReleaseEvidencePlan;
|
|
3
11
|
/**
|
|
@@ -7,6 +15,14 @@ export declare function validateReleaseEvidencePlan(value: unknown): asserts val
|
|
|
7
15
|
* this receipt is not an assertion that registry attestations were validated.
|
|
8
16
|
*/
|
|
9
17
|
export declare function verifyReleaseEvidence(plan: ReleaseEvidencePlan, options: ReleaseEvidenceOptions): Promise<ReleaseEvidenceReceipt>;
|
|
18
|
+
export declare interface InstalledLibraryPackageOptions {
|
|
19
|
+
consumerRoot?: string
|
|
20
|
+
allowBunTag?: boolean
|
|
21
|
+
maxEntries?: number
|
|
22
|
+
maxDepth?: number
|
|
23
|
+
maxBytes?: number
|
|
24
|
+
maxFileBytes?: number
|
|
25
|
+
}
|
|
10
26
|
export declare interface ReleaseSource {
|
|
11
27
|
repository: string
|
|
12
28
|
commit: string
|
package/dist/release-evidence.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{boundedBody,libraryArchiveEntries}from"./library/archive";import{createHash}from"node:crypto";import{lstatSync,readFileSync,readdirSync,realpathSync}from"node:fs";import{join,relative,resolve}from"node:path";import{runProjectScripts}from"./project-scripts";function fail(message){throw new Error(`Release verification blocked: ${message}`)}function hash(bytes){return createHash("sha256").update(bytes).digest("hex")}function nonemptyStrings(value){return Array.isArray(value)&&value.length>0&&value.every((item)=>typeof item==="string"&&item.length>0)}export function validateReleaseEvidencePlan(value){const plan=value;if(!plan||plan.schemaVersion!==1||!Array.isArray(plan.sources)||!plan.sources.length||!nonemptyStrings(plan.checks)||plan.checks.some((name)=>!/^[a-z0-9][\w:.-]*$/i.test(name))||new Set(plan.checks).size!==plan.checks.length)fail("Expected a version 1 plan with sources and named consumer checks");const packages=new Set;for(const source of plan.sources){if(!source||!/^[\w.-]+\/[\w.-]+$/.test(source.repository)||!/^[a-f0-9]{40}$/.test(source.commit)||typeof source.tag!=="string"||!source.tag||!Array.isArray(source.gates)||!source.gates.length||!Array.isArray(source.packages)||!source.packages.length)fail("Each source needs a repository, full commit, tag, release gates and packages");for(const gate of source.gates){if(!gate||!Number.isSafeInteger(gate.runId)||gate.runId<=0||!/^\.github\/workflows\/[\w.-]+\.ya?ml$/.test(gate.workflow)||!nonemptyStrings(gate.requiredJobs)||new Set(gate.requiredJobs).size!==gate.requiredJobs.length)fail("Each release gate needs an exact run, workflow and required jobs")}for(const pkg of source.packages){if(!pkg||!/^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/.test(pkg.name)||!/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(pkg.version)||!/^sha512-[A-Za-z0-9+/]{86}==$/.test(pkg.integrity)||packages.has(pkg.name))fail("Packages need unique names, exact versions and original SHA-512 archive identities");packages.add(pkg.name)}}}async function archiveFiles(bytes,limit){const entries=await libraryArchiveEntries(bytes,limit);return new Map([...entries].map(([name,bytes])=>[name,{sha256:hash(bytes),bytes:bytes.length}]))}function verifyInstalledFiles(directory,expected){const found=new Set;const hasBundledDependencies=[...expected.keys()].some((path)=>path.startsWith("node_modules/"));function visit(path,depth){if(depth>128)fail("Installed package directory depth exceeds its budget");for(const entry of readdirSync(join(directory,path),{withFileTypes:true})){if(!path&&entry.name==="node_modules"&&!hasBundledDependencies)continue;const name=path?`${path}/${entry.name}`:entry.name;if(found.size>=1e5)fail("Installed package has too many files");const fullPath=join(directory,name);if(entry.isDirectory())visit(name,depth+1);else{const identity=expected.get(name);const stat=lstatSync(fullPath);if(!identity||!stat.isFile()||stat.size!==identity.bytes||hash(readFileSync(fullPath))!==identity.sha256)fail(`Installed package file ${name} differs from the verified archive`);found.add(name)}}}visit("",0);if(found.size!==expected.size)fail("Installed package is missing files from the verified archive")}function installedState(plan,cwd,archives){const lock=readFileSync(join(cwd,"bun.lock"),"utf8");const parsed=Bun.JSONC.parse(lock);const nodeModules=realpathSync(join(cwd,"node_modules"));const manifests=[];for(const source of plan.sources){for(const pkg of source.packages){const locked=parsed.packages?.[pkg.name];if(locked?.[0]!==`${pkg.name}@${pkg.version}`||locked.at(-1)!==pkg.integrity)fail(`Consumer lock does not contain ${pkg.name}@${pkg.version} with the original archive identity`);const directory=realpathSync(join(cwd,"node_modules",pkg.name));const path=relative(nodeModules,directory);if(!path||path.startsWith("..")||resolve(nodeModules,path)!==directory)fail(`${pkg.name} resolves outside the installed consumer packages`);const raw=readFileSync(join(directory,"package.json"),"utf8");const manifest=JSON.parse(raw);if(manifest.name!==pkg.name||manifest.version!==pkg.version)fail(`Installed ${pkg.name} does not match tested version ${pkg.version}`);verifyInstalledFiles(directory,archives.get(pkg.name));manifests.push(hash(raw))}}return{lock,sha256:hash(lock),manifests:manifests.join(":")}}export async function verifyReleaseEvidence(plan,options){validateReleaseEvidencePlan(plan);const requestTimeoutMs=options.requestTimeoutMs??30000;const checkTimeoutMs=options.checkTimeoutMs??300000;const maxArchiveBytes=options.maxArchiveBytes??128*1024*1024;const maxExpandedBytes=options.maxExpandedBytes??128*1024*1024;for(const number of[requestTimeoutMs,checkTimeoutMs,maxArchiveBytes,maxExpandedBytes]){if(!Number.isSafeInteger(number)||number<=0)fail("Budgets must be positive safe integers")}const read=options.fetch??fetch;const archives=new Map;const receipt={schemaVersion:1,verifiedAt:"",sources:[],consumer:{lockfile:"bun.lock",sha256:"",bunVersion:"",checks:[]}};async function request(url,github,limit=1024*1024){const timeout=AbortSignal.timeout(requestTimeoutMs);const signal=options.signal?AbortSignal.any([options.signal,timeout]):timeout;signal.throwIfAborted();const response=await read(url,{method:"GET",redirect:"error",signal,headers:github?{Accept:"application/vnd.github+json",...options.token?{Authorization:`Bearer ${options.token}`}:{}}:{}});if(response.status!==200){await response.body?.cancel();fail(`${github?"Source evidence":"Published package"} request returned HTTP ${response.status}`)}return boundedBody(response,limit)}async function github(path){return JSON.parse(new TextDecoder().decode(await request(`https://api.github.com/repos/${path}`,true)))}for(const source of plan.sources){let ref=(await github(`${source.repository}/git/ref/tags/${encodeURIComponent(source.tag)}`)).object;for(let depth=0;ref?.type==="tag"&&depth<5;depth++)ref=(await github(`${source.repository}/git/tags/${ref.sha}`)).object;if(ref?.type!=="commit"||ref.sha!==source.commit)fail(`${source.tag} does not identify ${source.commit}`);const manifest=await github(`${source.repository}/contents/package.json?ref=${source.commit}`);if(manifest.encoding!=="base64"||typeof manifest.content!=="string")fail("Source package manifest is unavailable");const sourcePackage=JSON.parse(Buffer.from(manifest.content,"base64").toString("utf8"));const releaseScript=sourcePackage.scripts?.["release:patch"];if(typeof releaseScript!=="string"||!releaseScript.trim())fail(`${source.repository} has no existing release:patch command`);for(const gate of source.gates){const run=await github(`${source.repository}/actions/runs/${gate.runId}`);if(run.id!==gate.runId||run.repository?.full_name!==source.repository||run.path!==gate.workflow||run.head_sha!==source.commit)fail(`Release gate ${gate.runId} does not verify the exact source and workflow`);if(run.status!=="completed"||run.conclusion!=="success")fail(`Release gate ${gate.runId} is not successful`);const jobs=[];for(let page=1;page<=10;page++){const batch=await github(`${source.repository}/actions/runs/${gate.runId}/jobs?per_page=100&page=${page}`);if(!Array.isArray(batch.jobs))fail(`Release gate ${gate.runId} has no readable jobs`);jobs.push(...batch.jobs);if(batch.jobs.length<100)break;if(page===10)fail("Release job inventory exceeds its budget")}for(const name of gate.requiredJobs){const matches=jobs.filter((job)=>job.name===name);if(matches.length!==1||matches[0]?.status!=="completed"||matches[0]?.conclusion!=="success")fail(`Required release job ${name} did not pass exactly once`)}}const verified={...source,releaseCommand:"bun run release:patch",releaseScript,packages:[]};for(const pkg of source.packages){const metadata=JSON.parse(new TextDecoder().decode(await request(`https://registry.npmjs.org/${encodeURIComponent(pkg.name)}/${encodeURIComponent(pkg.version)}`,false)));if(metadata.name!==pkg.name||metadata.version!==pkg.version||metadata.dist?.integrity!==pkg.integrity)fail(`Published ${pkg.name}@${pkg.version} does not match the original archive identity`);if(metadata.gitHead!==undefined&&metadata.gitHead!==source.commit)fail(`Published ${pkg.name} names a different source commit`);if(!metadata.dist?.tarball)fail(`Published ${pkg.name} has no archive URL`);const tarball=new URL(metadata.dist.tarball);if(tarball.origin!=="https://registry.npmjs.org"||tarball.username||tarball.password)fail("Archive URL is outside the public npm registry");const bytes=await request(tarball.href,false,maxArchiveBytes);if(`sha512-${createHash("sha512").update(bytes).digest("base64")}`!==pkg.integrity)fail(`Published ${pkg.name}@${pkg.version} archive bytes failed SHA-512 verification`);const files=await archiveFiles(bytes,maxExpandedBytes);archives.set(pkg.name,files);const filesSha256=hash(JSON.stringify([...files].sort(([left],[right])=>left.localeCompare(right))));verified.packages.push({...pkg,tarball:tarball.href,bytes:bytes.byteLength,filesSha256})}receipt.sources.push(verified)}const initial=installedState(plan,options.cwd,archives);const checks=await runProjectScripts({cwd:options.cwd,scripts:plan.checks,signal:options.signal,timeoutMs:checkTimeoutMs});receipt.consumer.bunVersion=checks.bunVersion;receipt.consumer.checks=checks.checks;const final=installedState(plan,options.cwd,archives);if(final.sha256!==initial.sha256||final.manifests!==initial.manifests)fail("Consumer checks changed the verified lockfile or package identities");receipt.consumer.sha256=initial.sha256;options.signal?.throwIfAborted();receipt.verifiedAt=new Date().toISOString();return receipt}
|
|
1
|
+
import{boundedBody,libraryArchiveEntries,safeArchivePath}from"./library/archive.js";import{createHash}from"node:crypto";import{closeSync,constants,fstatSync,lstatSync,openSync,opendirSync,readFileSync,readSync,realpathSync}from"node:fs";import{isAbsolute,join,relative,resolve}from"node:path";export function inspectInstalledLibraryPackage(directory,expected,options={}){return verifyInstalledFiles(directory,expected,options)}function contained(root,path){const child=relative(root,path);return!!child&&child!==".."&&!child.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!isAbsolute(child)}function verifyInstalledFiles(directory,expected,options={},separateDependencies=false){const maxEntries=options.maxEntries??1e5;const maxDepth=options.maxDepth??128;const maxBytes=options.maxBytes??256*1024*1024;const maxFileBytes=options.maxFileBytes??maxBytes;for(const limit of[maxEntries,maxDepth,maxBytes,maxFileBytes]){if(!Number.isSafeInteger(limit)||limit<=0)fail("Installed package budgets must be positive safe integers")}if(expected.size>maxEntries)fail("Installed package expected inventory exceeds its budget");const identities=new Map;let expectedBytes=0;for(const[name,entry]of expected){const size=entry instanceof Uint8Array?entry.byteLength:entry?.bytes;if(!Number.isSafeInteger(size)||size<0||size>maxFileBytes||expectedBytes+size>maxBytes)fail("Installed package expected inventory exceeds its budget");const identity=entry instanceof Uint8Array?{sha256:hash(entry),bytes:size}:entry;if(!safeArchivePath(name)||!identity||!Number.isSafeInteger(identity.bytes)||identity.bytes<0||!/^[a-f0-9]{64}$/.test(identity.sha256))fail("Installed package expected inventory has an unsafe path or identity");expectedBytes+=identity.bytes;identities.set(name,identity)}const rootStat=lstatSync(directory);if(!rootStat.isDirectory()||rootStat.isSymbolicLink())fail("Installed package root must be a real directory");const root=realpathSync(directory);if(options.consumerRoot&&!contained(realpathSync(options.consumerRoot),root))fail("Installed package resolves outside its consumer root");const actual=new Map;const hasBundledDependencies=[...expected.keys()].some((name)=>name.startsWith("node_modules/"));let entries=0;let bytesRead=0;function visit(path,depth){if(depth>maxDepth)fail("Installed package directory depth exceeds its budget");const fullDirectory=join(root,path);const before=lstatSync(fullDirectory);if(!before.isDirectory()||before.isSymbolicLink()||realpathSync(fullDirectory)!==fullDirectory)fail("Installed package directory is a link or escapes its root");const handle=opendirSync(fullDirectory);try{for(let entry=handle.readSync();entry;entry=handle.readSync()){if(++entries>maxEntries)fail("Installed package entry count exceeds its budget");const name=path?`${path}/${entry.name}`:entry.name;if(!safeArchivePath(name))fail("Installed package contains an unsafe path");if(separateDependencies&&!path&&entry.name==="node_modules"&&!hasBundledDependencies)continue;const fullPath=join(root,name);const stat=lstatSync(fullPath);if(stat.isSymbolicLink())fail(`Installed package file ${name} is a symbolic link`);if(!separateDependencies&&name===".bun-tag"&&!stat.isFile())fail(`Installed package file ${name} is not a regular file`);if(stat.isDirectory()){visit(name,depth+1);continue}if(!stat.isFile())fail(`Installed package file ${name} is not a regular file`);const identity=identities.get(name);const bunTag=!identity&&name===".bun-tag"&&options.allowBunTag===true;if(!identity&&!bunTag)fail(`Installed package file ${name} differs from the verified archive`);if(stat.size>maxFileBytes||bytesRead+stat.size>maxBytes)fail("Installed package file bytes exceed their budget");if(identity&&stat.size!==identity.bytes||bunTag&&stat.size!==95)fail(`Installed package file ${name} differs from the verified archive`);const fd=openSync(fullPath,constants.O_RDONLY|(constants.O_NOFOLLOW??0)|(constants.O_NONBLOCK??0));let bytes;try{const opened=fstatSync(fd);if(!opened.isFile()||opened.dev!==stat.dev||opened.ino!==stat.ino||opened.size!==stat.size)fail(`Installed package file ${name} changed during inspection`);bytes=new Uint8Array(stat.size);let offset=0;while(offset<bytes.length){const count=readSync(fd,bytes,offset,bytes.length-offset,null);if(!count)fail(`Installed package file ${name} changed during inspection`);offset+=count}const after=fstatSync(fd);if(readSync(fd,new Uint8Array(1),0,1,null)||after.size!==stat.size||after.mtimeMs!==opened.mtimeMs||after.ctimeMs!==opened.ctimeMs)fail(`Installed package file ${name} changed during inspection`)}finally{closeSync(fd)}bytesRead+=bytes.length;if(bunTag){if(!/^sha512-[A-Za-z0-9+/]{86}==$/.test(new TextDecoder().decode(bytes)))fail("Installed package has invalid Bun installer metadata")}else{if(hash(bytes)!==identity.sha256)fail(`Installed package file ${name} differs from the verified archive`);actual.set(name,bytes)}}}finally{handle.closeSync()}const after=lstatSync(fullDirectory);if(!after.isDirectory()||after.dev!==before.dev||after.ino!==before.ino||after.mtimeMs!==before.mtimeMs||after.ctimeMs!==before.ctimeMs||realpathSync(fullDirectory)!==fullDirectory)fail("Installed package directory changed during inspection")}visit("",0);if(actual.size!==expected.size)fail("Installed package is missing files from the verified archive");if(realpathSync(directory)!==root)fail("Installed package root changed during inspection");return actual}function fail(message){throw new Error(`Release verification blocked: ${message}`)}function hash(bytes){return createHash("sha256").update(bytes).digest("hex")}function nonemptyStrings(value){return Array.isArray(value)&&value.length>0&&value.every((item)=>typeof item==="string"&&item.length>0)}export function validateReleaseEvidencePlan(value){const plan=value;if(!plan||plan.schemaVersion!==1||!Array.isArray(plan.sources)||!plan.sources.length||!nonemptyStrings(plan.checks)||plan.checks.some((name)=>!/^[a-z0-9][\w:.-]*$/i.test(name))||new Set(plan.checks).size!==plan.checks.length)fail("Expected a version 1 plan with sources and named consumer checks");const packages=new Set;for(const source of plan.sources){if(!source||!/^[\w.-]+\/[\w.-]+$/.test(source.repository)||!/^[a-f0-9]{40}$/.test(source.commit)||typeof source.tag!=="string"||!source.tag||!Array.isArray(source.gates)||!source.gates.length||!Array.isArray(source.packages)||!source.packages.length)fail("Each source needs a repository, full commit, tag, release gates and packages");for(const gate of source.gates){if(!gate||!Number.isSafeInteger(gate.runId)||gate.runId<=0||!/^\.github\/workflows\/[\w.-]+\.ya?ml$/.test(gate.workflow)||!nonemptyStrings(gate.requiredJobs)||new Set(gate.requiredJobs).size!==gate.requiredJobs.length)fail("Each release gate needs an exact run, workflow and required jobs")}for(const pkg of source.packages){if(!pkg||!/^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/.test(pkg.name)||!/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(pkg.version)||!/^sha512-[A-Za-z0-9+/]{86}==$/.test(pkg.integrity)||packages.has(pkg.name))fail("Packages need unique names, exact versions and original SHA-512 archive identities");packages.add(pkg.name)}}}async function archiveFiles(bytes,limit){const entries=await libraryArchiveEntries(bytes,limit);return new Map([...entries].map(([name,bytes])=>[name,{sha256:hash(bytes),bytes:bytes.length}]))}function installedState(plan,cwd,archives,maxBytes){const lock=readFileSync(join(cwd,"bun.lock"),"utf8");const parsed=Bun.JSONC.parse(lock);const nodeModules=realpathSync(join(cwd,"node_modules"));const manifests=[];for(const source of plan.sources){for(const pkg of source.packages){const locked=parsed.packages?.[pkg.name];if(locked?.[0]!==`${pkg.name}@${pkg.version}`||locked.at(-1)!==pkg.integrity)fail(`Consumer lock does not contain ${pkg.name}@${pkg.version} with the original archive identity`);const directory=realpathSync(join(cwd,"node_modules",pkg.name));const path=relative(nodeModules,directory);if(!path||path.startsWith("..")||resolve(nodeModules,path)!==directory)fail(`${pkg.name} resolves outside the installed consumer packages`);const raw=readFileSync(join(directory,"package.json"),"utf8");const manifest=JSON.parse(raw);if(manifest.name!==pkg.name||manifest.version!==pkg.version)fail(`Installed ${pkg.name} does not match tested version ${pkg.version}`);verifyInstalledFiles(directory,archives.get(pkg.name),{maxBytes},true);manifests.push(hash(raw))}}return{lock,sha256:hash(lock),manifests:manifests.join(":")}}export async function verifyReleaseEvidence(plan,options){validateReleaseEvidencePlan(plan);const requestTimeoutMs=options.requestTimeoutMs??30000;const checkTimeoutMs=options.checkTimeoutMs??300000;const maxArchiveBytes=options.maxArchiveBytes??128*1024*1024;const maxExpandedBytes=options.maxExpandedBytes??128*1024*1024;for(const number of[requestTimeoutMs,checkTimeoutMs,maxArchiveBytes,maxExpandedBytes]){if(!Number.isSafeInteger(number)||number<=0)fail("Budgets must be positive safe integers")}const read=options.fetch??fetch;const archives=new Map;const receipt={schemaVersion:1,verifiedAt:"",sources:[],consumer:{lockfile:"bun.lock",sha256:"",bunVersion:"",checks:[]}};async function request(url,github,limit=1024*1024){const timeout=AbortSignal.timeout(requestTimeoutMs);const signal=options.signal?AbortSignal.any([options.signal,timeout]):timeout;signal.throwIfAborted();const response=await read(url,{method:"GET",redirect:"error",signal,headers:github?{Accept:"application/vnd.github+json",...options.token?{Authorization:`Bearer ${options.token}`}:{}}:{}});if(response.status!==200){await response.body?.cancel();fail(`${github?"Source evidence":"Published package"} request returned HTTP ${response.status}`)}return boundedBody(response,limit)}async function github(path){return JSON.parse(new TextDecoder().decode(await request(`https://api.github.com/repos/${path}`,true)))}for(const source of plan.sources){let ref=(await github(`${source.repository}/git/ref/tags/${encodeURIComponent(source.tag)}`)).object;for(let depth=0;ref?.type==="tag"&&depth<5;depth++)ref=(await github(`${source.repository}/git/tags/${ref.sha}`)).object;if(ref?.type!=="commit"||ref.sha!==source.commit)fail(`${source.tag} does not identify ${source.commit}`);const manifest=await github(`${source.repository}/contents/package.json?ref=${source.commit}`);if(manifest.encoding!=="base64"||typeof manifest.content!=="string")fail("Source package manifest is unavailable");const sourcePackage=JSON.parse(Buffer.from(manifest.content,"base64").toString("utf8"));const releaseScript=sourcePackage.scripts?.["release:patch"];if(typeof releaseScript!=="string"||!releaseScript.trim())fail(`${source.repository} has no existing release:patch command`);for(const gate of source.gates){const run=await github(`${source.repository}/actions/runs/${gate.runId}`);if(run.id!==gate.runId||run.repository?.full_name!==source.repository||run.path!==gate.workflow||run.head_sha!==source.commit)fail(`Release gate ${gate.runId} does not verify the exact source and workflow`);if(run.status!=="completed"||run.conclusion!=="success")fail(`Release gate ${gate.runId} is not successful`);const jobs=[];for(let page=1;page<=10;page++){const batch=await github(`${source.repository}/actions/runs/${gate.runId}/jobs?per_page=100&page=${page}`);if(!Array.isArray(batch.jobs))fail(`Release gate ${gate.runId} has no readable jobs`);jobs.push(...batch.jobs);if(batch.jobs.length<100)break;if(page===10)fail("Release job inventory exceeds its budget")}for(const name of gate.requiredJobs){const matches=jobs.filter((job)=>job.name===name);if(matches.length!==1||matches[0]?.status!=="completed"||matches[0]?.conclusion!=="success")fail(`Required release job ${name} did not pass exactly once`)}}const verified={...source,releaseCommand:"bun run release:patch",releaseScript,packages:[]};for(const pkg of source.packages){const metadata=JSON.parse(new TextDecoder().decode(await request(`https://registry.npmjs.org/${encodeURIComponent(pkg.name)}/${encodeURIComponent(pkg.version)}`,false)));if(metadata.name!==pkg.name||metadata.version!==pkg.version||metadata.dist?.integrity!==pkg.integrity)fail(`Published ${pkg.name}@${pkg.version} does not match the original archive identity`);if(metadata.gitHead!==undefined&&metadata.gitHead!==source.commit)fail(`Published ${pkg.name} names a different source commit`);if(!metadata.dist?.tarball)fail(`Published ${pkg.name} has no archive URL`);const tarball=new URL(metadata.dist.tarball);if(tarball.origin!=="https://registry.npmjs.org"||tarball.username||tarball.password)fail("Archive URL is outside the public npm registry");const bytes=await request(tarball.href,false,maxArchiveBytes);if(`sha512-${createHash("sha512").update(bytes).digest("base64")}`!==pkg.integrity)fail(`Published ${pkg.name}@${pkg.version} archive bytes failed SHA-512 verification`);const files=await archiveFiles(bytes,maxExpandedBytes);archives.set(pkg.name,files);const filesSha256=hash(JSON.stringify([...files].sort(([left],[right])=>left.localeCompare(right))));verified.packages.push({...pkg,tarball:tarball.href,bytes:bytes.byteLength,filesSha256})}receipt.sources.push(verified)}const initial=installedState(plan,options.cwd,archives,maxExpandedBytes);const{runProjectScripts}=await import("./project-scripts.js");const checks=await runProjectScripts({cwd:options.cwd,scripts:plan.checks,signal:options.signal,timeoutMs:checkTimeoutMs});receipt.consumer.bunVersion=checks.bunVersion;receipt.consumer.checks=checks.checks;const final=installedState(plan,options.cwd,archives,maxExpandedBytes);if(final.sha256!==initial.sha256||final.manifests!==initial.manifests)fail("Consumer checks changed the verified lockfile or package identities");receipt.consumer.sha256=initial.sha256;options.signal?.throwIfAborted();receipt.verifiedAt=new Date().toISOString();return receipt}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/actions",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.597",
|
|
6
6
|
"description": "The Stacks actions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -68,56 +68,56 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@babel/parser": "^8.1.2",
|
|
70
70
|
"@babel/types": "^8.1.2",
|
|
71
|
-
"@stacksjs/action-runner": "0.75.
|
|
72
|
-
"@stacksjs/ai": "0.75.
|
|
73
|
-
"@stacksjs/analytics": "0.75.
|
|
74
|
-
"@stacksjs/api": "0.75.
|
|
75
|
-
"@stacksjs/auth": "0.75.
|
|
76
|
-
"@stacksjs/build": "0.75.
|
|
71
|
+
"@stacksjs/action-runner": "0.75.597",
|
|
72
|
+
"@stacksjs/ai": "0.75.597",
|
|
73
|
+
"@stacksjs/analytics": "0.75.597",
|
|
74
|
+
"@stacksjs/api": "0.75.597",
|
|
75
|
+
"@stacksjs/auth": "0.75.597",
|
|
76
|
+
"@stacksjs/build": "0.75.597",
|
|
77
77
|
"@stacksjs/bumpx": "^0.2.26",
|
|
78
78
|
"@stacksjs/bunpress": "^0.2.15",
|
|
79
|
-
"@stacksjs/cli": "0.75.
|
|
80
|
-
"@stacksjs/cloud": "0.75.
|
|
81
|
-
"@stacksjs/cms": "0.75.
|
|
82
|
-
"@stacksjs/components": "^0.2.
|
|
83
|
-
"@stacksjs/config": "0.75.
|
|
84
|
-
"@stacksjs/database": "0.75.
|
|
85
|
-
"@stacksjs/desktop-build": "0.75.
|
|
86
|
-
"@stacksjs/dns": "0.75.
|
|
87
|
-
"@stacksjs/docs": "0.75.
|
|
88
|
-
"@stacksjs/enums": "0.75.
|
|
89
|
-
"@stacksjs/env": "0.75.
|
|
90
|
-
"@stacksjs/error-handling": "0.75.
|
|
91
|
-
"@stacksjs/github": "0.75.
|
|
79
|
+
"@stacksjs/cli": "0.75.597",
|
|
80
|
+
"@stacksjs/cloud": "0.75.597",
|
|
81
|
+
"@stacksjs/cms": "0.75.597",
|
|
82
|
+
"@stacksjs/components": "^0.2.889",
|
|
83
|
+
"@stacksjs/config": "0.75.597",
|
|
84
|
+
"@stacksjs/database": "0.75.597",
|
|
85
|
+
"@stacksjs/desktop-build": "0.75.597",
|
|
86
|
+
"@stacksjs/dns": "0.75.597",
|
|
87
|
+
"@stacksjs/docs": "0.75.597",
|
|
88
|
+
"@stacksjs/enums": "0.75.597",
|
|
89
|
+
"@stacksjs/env": "0.75.597",
|
|
90
|
+
"@stacksjs/error-handling": "0.75.597",
|
|
91
|
+
"@stacksjs/github": "0.75.597",
|
|
92
92
|
"@stacksjs/gitit": "^0.2.5",
|
|
93
|
-
"@stacksjs/i18n": "0.75.
|
|
94
|
-
"@stacksjs/image": "0.75.
|
|
95
|
-
"@stacksjs/logging": "0.75.
|
|
93
|
+
"@stacksjs/i18n": "0.75.597",
|
|
94
|
+
"@stacksjs/image": "0.75.597",
|
|
95
|
+
"@stacksjs/logging": "0.75.597",
|
|
96
96
|
"@stacksjs/logsmith": "^0.2.11",
|
|
97
|
-
"@stacksjs/mobile": "0.75.
|
|
98
|
-
"@stacksjs/orm": "0.75.
|
|
99
|
-
"@stacksjs/path": "0.75.
|
|
100
|
-
"@stacksjs/payments": "0.75.
|
|
101
|
-
"@stacksjs/queue": "0.75.
|
|
102
|
-
"@stacksjs/registry": "0.75.
|
|
103
|
-
"@stacksjs/router": "0.75.
|
|
97
|
+
"@stacksjs/mobile": "0.75.597",
|
|
98
|
+
"@stacksjs/orm": "0.75.597",
|
|
99
|
+
"@stacksjs/path": "0.75.597",
|
|
100
|
+
"@stacksjs/payments": "0.75.597",
|
|
101
|
+
"@stacksjs/queue": "0.75.597",
|
|
102
|
+
"@stacksjs/registry": "0.75.597",
|
|
103
|
+
"@stacksjs/router": "0.75.597",
|
|
104
104
|
"@stacksjs/rpx": "^0.11.54",
|
|
105
|
-
"@stacksjs/scheduler": "0.75.
|
|
106
|
-
"@stacksjs/search-engine": "0.75.
|
|
107
|
-
"@stacksjs/security": "0.75.
|
|
108
|
-
"@stacksjs/server": "0.75.
|
|
109
|
-
"@stacksjs/sites": "0.75.
|
|
110
|
-
"@stacksjs/storage": "0.75.
|
|
111
|
-
"@stacksjs/strings": "0.75.
|
|
112
|
-
"@stacksjs/stx": "^0.2.
|
|
105
|
+
"@stacksjs/scheduler": "0.75.597",
|
|
106
|
+
"@stacksjs/search-engine": "0.75.597",
|
|
107
|
+
"@stacksjs/security": "0.75.597",
|
|
108
|
+
"@stacksjs/server": "0.75.597",
|
|
109
|
+
"@stacksjs/sites": "0.75.597",
|
|
110
|
+
"@stacksjs/storage": "0.75.597",
|
|
111
|
+
"@stacksjs/strings": "0.75.597",
|
|
112
|
+
"@stacksjs/stx": "^0.2.889",
|
|
113
113
|
"@stacksjs/tlsx": "^0.13.19",
|
|
114
114
|
"@stacksjs/ts-cloud": "^0.16.129",
|
|
115
115
|
"@stacksjs/ts-md": "^0.1.1",
|
|
116
|
-
"@stacksjs/tunnel": "0.75.
|
|
117
|
-
"@stacksjs/types": "0.75.
|
|
118
|
-
"@stacksjs/utils": "0.75.
|
|
119
|
-
"@stacksjs/whois": "0.75.
|
|
120
|
-
"bun-plugin-stx": "^0.2.
|
|
116
|
+
"@stacksjs/tunnel": "0.75.597",
|
|
117
|
+
"@stacksjs/types": "0.75.597",
|
|
118
|
+
"@stacksjs/utils": "0.75.597",
|
|
119
|
+
"@stacksjs/whois": "0.75.597",
|
|
120
|
+
"bun-plugin-stx": "^0.2.889",
|
|
121
121
|
"pickier": "^0.1.92"
|
|
122
122
|
},
|
|
123
123
|
"peerDependencies": {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
}
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
|
-
"@stacksjs/validation": "0.75.
|
|
132
|
+
"@stacksjs/validation": "0.75.597",
|
|
133
133
|
"better-dx": "^0.2.39"
|
|
134
134
|
}
|
|
135
135
|
}
|