@effected/sbom 0.1.0

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.
@@ -0,0 +1,145 @@
1
+ import { Schema } from "effect";
2
+
3
+ //#region src/SlsaProvenance.ts
4
+ /**
5
+ * The SLSA Provenance v1 predicate type URI.
6
+ *
7
+ * @public
8
+ */
9
+ const SLSA_PROVENANCE_V1 = "https://slsa.dev/provenance/v1";
10
+ /**
11
+ * The SLSA build type identifying a GitHub Actions workflow build.
12
+ *
13
+ * @remarks
14
+ * A published **SLSA build-type identifier** — it names a provenance shape, not
15
+ * an Actions runtime detail — which is why it lives with the provenance model
16
+ * rather than in `@effected/github-actions`.
17
+ *
18
+ * @see {@link https://github.com/slsa-framework/github-actions-buildtypes/tree/main/workflow/v1 | workflow/v1}
19
+ *
20
+ * @public
21
+ */
22
+ const GITHUB_BUILD_TYPE = "https://actions.github.io/buildtypes/workflow/v1";
23
+ /**
24
+ * How the build was invoked, and what it was invoked from.
25
+ *
26
+ * @public
27
+ */
28
+ var SlsaBuildDefinition = class extends Schema.Class("SlsaBuildDefinition")({
29
+ /** The build type URI — {@link GITHUB_BUILD_TYPE} for an Actions workflow. */
30
+ buildType: Schema.String,
31
+ /** Parameters an external party controls: for Actions, the workflow itself. */
32
+ externalParameters: Schema.Struct({
33
+ /** The workflow the build ran. */
34
+ workflow: Schema.Struct({
35
+ /** The git ref the workflow ran on. */
36
+ ref: Schema.String,
37
+ /** The repository's browsable URL. */
38
+ repository: Schema.String,
39
+ /** The workflow file's path within the repository. */
40
+ path: Schema.String
41
+ }) }),
42
+ /** Parameters the build platform controls. */
43
+ internalParameters: Schema.Struct({
44
+ /** The Actions-specific half, spelled in the claim names the platform uses. */
45
+ github: Schema.Struct({
46
+ /** The event that triggered the workflow. */
47
+ event_name: Schema.String,
48
+ /** The repository's numeric id. */
49
+ repository_id: Schema.String,
50
+ /** The repository owner's numeric id. */
51
+ repository_owner_id: Schema.String,
52
+ /** `github-hosted` or `self-hosted`. */
53
+ runner_environment: Schema.String
54
+ }) }),
55
+ /** The artifacts the build consumed — for Actions, the commit it built. */
56
+ resolvedDependencies: Schema.Array(Schema.Struct({
57
+ /** A URI naming the dependency. */
58
+ uri: Schema.String,
59
+ /** Algorithm to digest; `gitCommit` for a repository. */
60
+ digest: Schema.Record(Schema.String, Schema.String)
61
+ }))
62
+ }) {};
63
+ /**
64
+ * Who ran the build, and the record of that run.
65
+ *
66
+ * @public
67
+ */
68
+ var SlsaRunDetails = class extends Schema.Class("SlsaRunDetails")({
69
+ /** The build platform's identity. */
70
+ builder: Schema.Struct({
71
+ /** A URI identifying the builder — the reusable workflow, for Actions. */
72
+ id: Schema.String }),
73
+ /** Metadata about this particular run. */
74
+ metadata: Schema.Struct({
75
+ /** A URI locating the run that produced the artifact. */
76
+ invocationId: Schema.String })
77
+ }) {};
78
+ /**
79
+ * The workflow file's path, with the repository prefix and the `@ref` suffix
80
+ * removed: `owner/repo/.github/workflows/x.yml@main` → `.github/workflows/x.yml`.
81
+ *
82
+ * Reproduces upstream's extraction exactly, first occurrence and first `@`
83
+ * included — a divergence here is a divergence in the emitted predicate.
84
+ */
85
+ const workflowPathOf = (input) => input.workflowRef.replace(`${input.repository}/`, "").split("@")[0] ?? "";
86
+ /**
87
+ * A SLSA Provenance v1 predicate.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { SlsaProvenance } from "@effected/sbom";
92
+ *
93
+ * const provenance = SlsaProvenance.forGitHubWorkflow(claims);
94
+ * ```
95
+ *
96
+ * @public
97
+ */
98
+ var SlsaProvenance = class SlsaProvenance extends Schema.Class("SlsaProvenance")({
99
+ /** What was built, and from what. */
100
+ buildDefinition: SlsaBuildDefinition,
101
+ /** Who built it, and when. */
102
+ runDetails: SlsaRunDetails
103
+ }) {
104
+ /** The predicate type URI a statement carrying this must declare. */
105
+ static predicateType = SLSA_PROVENANCE_V1;
106
+ /** The build type this package's GitHub-workflow constructor stamps. */
107
+ static buildType = GITHUB_BUILD_TYPE;
108
+ /**
109
+ * Provenance for a GitHub Actions `workflow/v1` build.
110
+ *
111
+ * @remarks
112
+ * **Total** — a pure projection of its argument. Every value it needs is
113
+ * already in the input; nothing is read from the environment and nothing can
114
+ * fail.
115
+ */
116
+ static forGitHubWorkflow(input) {
117
+ return SlsaProvenance.make({
118
+ buildDefinition: SlsaBuildDefinition.make({
119
+ buildType: GITHUB_BUILD_TYPE,
120
+ externalParameters: { workflow: {
121
+ ref: input.ref,
122
+ repository: `${input.serverUrl}/${input.repository}`,
123
+ path: workflowPathOf(input)
124
+ } },
125
+ internalParameters: { github: {
126
+ event_name: input.eventName,
127
+ repository_id: input.repositoryId,
128
+ repository_owner_id: input.repositoryOwnerId,
129
+ runner_environment: input.runnerEnvironment
130
+ } },
131
+ resolvedDependencies: [{
132
+ uri: `git+${input.serverUrl}/${input.repository}@${input.ref}`,
133
+ digest: { gitCommit: input.sha }
134
+ }]
135
+ }),
136
+ runDetails: SlsaRunDetails.make({
137
+ builder: { id: `${input.serverUrl}/${input.jobWorkflowRef}` },
138
+ metadata: { invocationId: `${input.serverUrl}/${input.repository}/actions/runs/${input.runId}/attempts/${input.runAttempt}` }
139
+ })
140
+ });
141
+ }
142
+ };
143
+
144
+ //#endregion
145
+ export { GITHUB_BUILD_TYPE, SLSA_PROVENANCE_V1, SlsaBuildDefinition, SlsaProvenance, SlsaRunDetails };