@appstrate/core 2.1.0 → 2.1.2

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/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@appstrate/core",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
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
+ }
package/src/validation.ts CHANGED
@@ -36,10 +36,14 @@ export const serviceRequirementSchema = z.looseObject({
36
36
  connectionMode: z.enum(["user", "admin"]).optional(),
37
37
  });
38
38
 
39
- export const PACKAGE_REF_REGEX = new RegExp(`^(?:@${SLUG_PATTERN}\\/)?${SLUG_PATTERN}$`);
39
+ // ─────────────────────────────────────────────
40
+ // Base manifest schema — common fields for all package types
41
+ // ─────────────────────────────────────────────
42
+
43
+ export const scopedNameRegex = new RegExp(`^@${SLUG_PATTERN}\\/${SLUG_PATTERN}$`);
40
44
 
41
- const packageRefString = z.string().min(1).regex(PACKAGE_REF_REGEX, {
42
- error: "Must be a valid slug or scoped name (@scope/name)",
45
+ const packageRefString = z.string().min(1).regex(scopedNameRegex, {
46
+ error: "Must be a scoped name (@scope/name)",
43
47
  });
44
48
 
45
49
  const semverRangeString = z.string().refine((val) => semver.validRange(val) !== null, {
@@ -53,11 +57,6 @@ const registryDependenciesSchema = z
53
57
  })
54
58
  .optional();
55
59
 
56
- // ─────────────────────────────────────────────
57
- // Base manifest schema — common fields for all package types
58
- // ─────────────────────────────────────────────
59
-
60
- export const scopedNameRegex = new RegExp(`^@${SLUG_PATTERN}\\/${SLUG_PATTERN}$`);
61
60
  export const packageTypeEnum = z.enum(["flow", "skill", "extension"]);
62
61
  export type PackageType = z.infer<typeof packageTypeEnum>;
63
62
 
@@ -91,8 +90,8 @@ export type FlowJsonSchemaObject = z.infer<typeof jsonSchemaObjectSchema>;
91
90
  const flowSharedFields = {
92
91
  requires: z.looseObject({
93
92
  services: z.array(serviceRequirementSchema),
94
- skills: z.array(packageRefString).optional(),
95
- extensions: z.array(packageRefString).optional(),
93
+ skills: z.record(packageRefString, z.string()).optional(),
94
+ extensions: z.record(packageRefString, z.string()).optional(),
96
95
  }),
97
96
  input: z
98
97
  .object({