@appstrate/core 2.1.0 → 2.1.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.
Files changed (2) hide show
  1. package/package.json +6 -3
  2. package/src/download.ts +54 -0
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@appstrate/core",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "type": "module",
5
- "files": ["src"],
5
+ "files": [
6
+ "src"
7
+ ],
6
8
  "exports": {
7
9
  "./logger": "./src/logger.ts",
8
10
  "./rate-limit": "./src/rate-limit.ts",
@@ -19,7 +21,8 @@
19
21
  "./update-check": "./src/update-check.ts",
20
22
  "./publish-manifest": "./src/publish-manifest.ts",
21
23
  "./dist-tags": "./src/dist-tags.ts",
22
- "./version-policy": "./src/version-policy.ts"
24
+ "./version-policy": "./src/version-policy.ts",
25
+ "./download": "./src/download.ts"
23
26
  },
24
27
  "dependencies": {
25
28
  "fflate": "^0.8.0",
@@ -0,0 +1,54 @@
1
+ import { computeIntegrity } from "./integrity.ts";
2
+
3
+ // ─────────────────────────────────────────────
4
+ // Integrity verification
5
+ // ─────────────────────────────────────────────
6
+
7
+ export interface IntegrityCheckResult {
8
+ valid: boolean;
9
+ computed: string;
10
+ }
11
+
12
+ /** Verify artifact integrity by computing SHA256 hash and comparing to expected value. */
13
+ export function verifyArtifactIntegrity(
14
+ data: Uint8Array,
15
+ expectedIntegrity: string,
16
+ ): IntegrityCheckResult {
17
+ const computed = computeIntegrity(data);
18
+ return { valid: computed === expectedIntegrity, computed };
19
+ }
20
+
21
+ // ─────────────────────────────────────────────
22
+ // Download filename
23
+ // ─────────────────────────────────────────────
24
+
25
+ /** Build a consistent download filename: scope-name-version.zip */
26
+ export function buildDownloadFilename(scope: string, name: string, version: string): string {
27
+ const cleanScope = scope.replace(/^@/, "");
28
+ return `${cleanScope}-${name}-${version}.zip`;
29
+ }
30
+
31
+ // ─────────────────────────────────────────────
32
+ // Download response headers
33
+ // ─────────────────────────────────────────────
34
+
35
+ export interface DownloadHeadersInput {
36
+ integrity: string;
37
+ yanked: boolean;
38
+ scope: string;
39
+ name: string;
40
+ version: string;
41
+ }
42
+
43
+ /** Build standard download response headers (Content-Type, Content-Disposition, X-Integrity, X-Yanked). */
44
+ export function buildDownloadHeaders(meta: DownloadHeadersInput): Record<string, string> {
45
+ const headers: Record<string, string> = {
46
+ "Content-Type": "application/zip",
47
+ "X-Integrity": meta.integrity,
48
+ "Content-Disposition": `attachment; filename="${buildDownloadFilename(meta.scope, meta.name, meta.version)}"`,
49
+ };
50
+ if (meta.yanked) {
51
+ headers["X-Yanked"] = "true";
52
+ }
53
+ return headers;
54
+ }