@secureci/cli 0.0.0-stage → 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.
package/dist/config.js ADDED
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CONFIG_KEYS = exports.DEFAULT_CONFIG = void 0;
37
+ exports.getConfigFilePath = getConfigFilePath;
38
+ exports.loadConfig = loadConfig;
39
+ exports.saveConfig = saveConfig;
40
+ exports.getDefaultContainerRuntime = getDefaultContainerRuntime;
41
+ exports.isValidConfigKey = isValidConfigKey;
42
+ exports.getConfigValue = getConfigValue;
43
+ exports.setConfigValue = setConfigValue;
44
+ exports.unsetConfigValue = unsetConfigValue;
45
+ exports.parseConfigValue = parseConfigValue;
46
+ exports.resolveNetworkDisabled = resolveNetworkDisabled;
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const YAML = __importStar(require("yaml"));
50
+ /** Built-in defaults, used when a key is absent from the config file. */
51
+ exports.DEFAULT_CONFIG = {
52
+ 'container-runtime': 'docker'
53
+ };
54
+ const CONTAINER_RUNTIME_VALUES = [
55
+ 'auto',
56
+ 'docker',
57
+ 'podman',
58
+ 'containerd',
59
+ 'host'
60
+ ];
61
+ function getHomeDir() {
62
+ return process.env.HOME || process.env.USERPROFILE || '/tmp';
63
+ }
64
+ function getConfigDir() {
65
+ return path.join(getHomeDir(), '.secureci');
66
+ }
67
+ function getConfigFilePath() {
68
+ return path.join(getConfigDir(), 'config.yml');
69
+ }
70
+ /** Load the global config file, returning `{}` if absent or unreadable. */
71
+ function loadConfig() {
72
+ const configFile = getConfigFilePath();
73
+ if (!fs.existsSync(configFile))
74
+ return {};
75
+ try {
76
+ const raw = fs.readFileSync(configFile, 'utf-8');
77
+ const parsed = YAML.parse(raw);
78
+ return parsed && typeof parsed === 'object' ? parsed : {};
79
+ }
80
+ catch {
81
+ return {};
82
+ }
83
+ }
84
+ /** Persist the given config object to the global config file. */
85
+ function saveConfig(config) {
86
+ const configDir = getConfigDir();
87
+ if (!fs.existsSync(configDir)) {
88
+ fs.mkdirSync(configDir, { recursive: true });
89
+ }
90
+ fs.writeFileSync(getConfigFilePath(), YAML.stringify(config));
91
+ }
92
+ /** Resolve the effective value for `container-runtime`: config, else built-in default. */
93
+ function getDefaultContainerRuntime(config = loadConfig()) {
94
+ const value = config['container-runtime'];
95
+ if (value === undefined)
96
+ return exports.DEFAULT_CONFIG['container-runtime'];
97
+ if (!CONTAINER_RUNTIME_VALUES.includes(value)) {
98
+ const hint = String(value) === 'none' ? ' ("none" was renamed to "host")' : '';
99
+ throw new Error(`Invalid container-runtime "${value}" in ${getConfigFilePath()}${hint}. Must be one of: ${CONTAINER_RUNTIME_VALUES.join(', ')}`);
100
+ }
101
+ return value;
102
+ }
103
+ exports.CONFIG_KEYS = [
104
+ 'container-runtime',
105
+ 'container-image',
106
+ 'container-timeout',
107
+ 'container-memory',
108
+ 'allow-network'
109
+ ];
110
+ /** `runner-images.<label>`: one entry of the runs-on -> image mapping. */
111
+ const RUNNER_IMAGE_KEY = /^runner-images\.(.+)$/;
112
+ /** A plain key, or `runner-images.<label>`. */
113
+ function isValidConfigKey(key) {
114
+ return (exports.CONFIG_KEYS.includes(key) ||
115
+ RUNNER_IMAGE_KEY.test(key));
116
+ }
117
+ /** Read a key (see isValidConfigKey) from a config object. */
118
+ function getConfigValue(config, key) {
119
+ const label = key.match(RUNNER_IMAGE_KEY)?.[1];
120
+ if (label !== undefined)
121
+ return config['runner-images']?.[label];
122
+ return config[key];
123
+ }
124
+ /** Parse `rawValue` for `key` and set it on `config`. Throws if invalid. */
125
+ function setConfigValue(config, key, rawValue) {
126
+ const label = key.match(RUNNER_IMAGE_KEY)?.[1];
127
+ if (label !== undefined) {
128
+ config['runner-images'] = { ...config['runner-images'], [label]: rawValue };
129
+ return rawValue;
130
+ }
131
+ const value = parseConfigValue(key, rawValue);
132
+ config[key] = value;
133
+ return value;
134
+ }
135
+ /** Remove `key` from `config`, dropping an emptied runner-images map. */
136
+ function unsetConfigValue(config, key) {
137
+ const label = key.match(RUNNER_IMAGE_KEY)?.[1];
138
+ if (label === undefined) {
139
+ delete config[key];
140
+ return;
141
+ }
142
+ const images = { ...config['runner-images'] };
143
+ delete images[label];
144
+ if (Object.keys(images).length > 0)
145
+ config['runner-images'] = images;
146
+ else
147
+ delete config['runner-images'];
148
+ }
149
+ /**
150
+ * Parse and validate a raw CLI string value for the given config key,
151
+ * returning the typed value to store. Throws on invalid input.
152
+ */
153
+ function parseConfigValue(key, rawValue) {
154
+ switch (key) {
155
+ case 'container-runtime':
156
+ if (!CONTAINER_RUNTIME_VALUES.includes(rawValue)) {
157
+ throw new Error(`Invalid value "${rawValue}" for container-runtime. Must be one of: ${CONTAINER_RUNTIME_VALUES.join(', ')}`);
158
+ }
159
+ return rawValue;
160
+ case 'container-timeout': {
161
+ const num = Number(rawValue);
162
+ if (!Number.isFinite(num) || num < 0) {
163
+ throw new Error(`Invalid value "${rawValue}" for container-timeout. Must be a non-negative number.`);
164
+ }
165
+ return num;
166
+ }
167
+ case 'allow-network':
168
+ if (rawValue !== 'true' && rawValue !== 'false') {
169
+ throw new Error(`Invalid value "${rawValue}" for allow-network. Must be "true" or "false".`);
170
+ }
171
+ return rawValue === 'true';
172
+ case 'container-image':
173
+ case 'container-memory':
174
+ return rawValue;
175
+ }
176
+ }
177
+ /**
178
+ * Whether container networking should be disabled. Networking is on by
179
+ * default (matching GitHub-hosted runners); `--no-network` turns it off and
180
+ * wins over everything, then `--allow-network`, then `allow-network` in the
181
+ * config file.
182
+ */
183
+ function resolveNetworkDisabled(flags, config = loadConfig()) {
184
+ if (flags.network === false)
185
+ return true;
186
+ if (flags.allowNetwork === true)
187
+ return false;
188
+ return config['allow-network'] === false;
189
+ }
190
+ //# sourceMappingURL=config.js.map
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./parser/workflow-parser"), exports);
19
+ __exportStar(require("./parser/validator"), exports);
20
+ __exportStar(require("./runner/dry-run"), exports);
21
+ __exportStar(require("./runner/executor"), exports);
22
+ __exportStar(require("./utils/logger"), exports);
23
+ //# sourceMappingURL=index.js.map
package/dist/init.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderInitWorkflow = renderInitWorkflow;
4
+ /**
5
+ * Render a ready-to-commit `.github/workflows/secureci.yml` that runs SecureCI
6
+ * on every pull request via the published `secure-ci/cli` action.
7
+ *
8
+ * The output is deterministic for a given set of options, so it can be
9
+ * regenerated and diffed. With uploads on (the default) the workflow asks for
10
+ * `security-events: write` and lets the action upload SARIF; with uploads off
11
+ * it keeps `contents: read` only and passes `upload-sarif: false`.
12
+ */
13
+ function renderInitWorkflow(options) {
14
+ const upload = options.upload !== false;
15
+ const contract = options.contract?.trim();
16
+ const lines = [
17
+ '# Validate GitHub Actions workflows with SecureCI on every pull request.',
18
+ '# Generated by `secureci init`; edit freely.',
19
+ 'name: SecureCI',
20
+ '',
21
+ 'on:',
22
+ ' - pull_request',
23
+ '',
24
+ 'permissions:',
25
+ ' contents: read'
26
+ ];
27
+ if (upload)
28
+ lines.push(' security-events: write');
29
+ lines.push('', 'jobs:', ' secureci:', ' runs-on: ubuntu-latest', ' steps:', ' - uses: actions/checkout@v4', ' - uses: secure-ci/cli@v1');
30
+ const withLines = [];
31
+ if (contract)
32
+ withLines.push(` contract: ${yamlScalar(contract)}`);
33
+ if (!upload)
34
+ withLines.push(' upload-sarif: false');
35
+ if (withLines.length > 0) {
36
+ lines.push(' with:', ...withLines);
37
+ }
38
+ lines.push('');
39
+ return lines.join('\n');
40
+ }
41
+ /** Quote a scalar only when YAML would otherwise misread it. */
42
+ function yamlScalar(value) {
43
+ return /^[A-Za-z0-9._/@-]+$/.test(value) ? value : JSON.stringify(value);
44
+ }
45
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.collectReferences = collectReferences;
37
+ exports.buildInventory = buildInventory;
38
+ exports.diffLock = diffLock;
39
+ exports.lockEntries = lockEntries;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const workflow_parser_1 = require("./parser/workflow-parser");
43
+ const repository_1 = require("./utils/repository");
44
+ const FULL_SHA = /^[0-9a-f]{40}$/i;
45
+ const MAX_DEPTH = 10;
46
+ function classify(uses, kind) {
47
+ const base = { uses, kind, pinned: false, path: '' };
48
+ if (uses.startsWith('docker://')) {
49
+ return { ...base, kind: 'docker' };
50
+ }
51
+ if (uses.startsWith('./') || uses.startsWith('../')) {
52
+ return { ...base, kind: 'local' };
53
+ }
54
+ const at = uses.lastIndexOf('@');
55
+ const ref = at === -1 ? undefined : uses.slice(at + 1);
56
+ const name = at === -1 ? uses : uses.slice(0, at);
57
+ const parts = name.split('/');
58
+ return {
59
+ ...base,
60
+ kind,
61
+ owner: parts[0],
62
+ repo: parts[1],
63
+ subpath: parts.length > 2 ? parts.slice(2).join('/') : undefined,
64
+ ref,
65
+ pinned: !!ref && FULL_SHA.test(ref)
66
+ };
67
+ }
68
+ /**
69
+ * Every `uses:` reference in a workflow, recursing into local composite
70
+ * actions (`./path`) and local reusable workflows (`jobs.<id>.uses: ./x.yml`)
71
+ * so wrapped references are still listed. Remote references are listed but
72
+ * not followed. Order is the walk order; each carries its call path.
73
+ */
74
+ function collectReferences(parsed) {
75
+ const root = (0, repository_1.repositoryRoot)(parsed.path);
76
+ const refs = [];
77
+ const resolveLocal = (uses, names) => {
78
+ const target = path.resolve(root, uses);
79
+ for (const candidate of [
80
+ target,
81
+ ...names.map((n) => path.join(target, n))
82
+ ]) {
83
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
84
+ return candidate;
85
+ }
86
+ }
87
+ return null;
88
+ };
89
+ const isLocal = (u) => u.startsWith('./') || u.startsWith('../');
90
+ const addStep = (step, at, stack) => {
91
+ if (!step.uses)
92
+ return;
93
+ const ref = classify(step.uses, 'action');
94
+ refs.push({ ...ref, path: at });
95
+ if (!isLocal(step.uses))
96
+ return;
97
+ const file = resolveLocal(step.uses, ['action.yml', 'action.yaml']);
98
+ if (!file || stack.includes(file) || stack.length >= MAX_DEPTH)
99
+ return;
100
+ let parsedAction;
101
+ try {
102
+ parsedAction = (0, workflow_parser_1.parseFile)(file);
103
+ }
104
+ catch {
105
+ return;
106
+ }
107
+ if (parsedAction.type === 'action' &&
108
+ parsedAction.file.runs.using === 'composite') {
109
+ (parsedAction.file.runs.steps ?? []).forEach((s, i) => addStep(s, `${at} > ${step.uses} > steps[${i}]`, [...stack, file]));
110
+ }
111
+ };
112
+ const addWorkflow = (workflow, at, stack) => {
113
+ for (const [jobId, job] of Object.entries(workflow.jobs ?? {})) {
114
+ const jobPath = `${at}jobs.${jobId}`;
115
+ if (job.uses) {
116
+ const ref = classify(job.uses, 'reusable-workflow');
117
+ refs.push({ ...ref, path: jobPath });
118
+ if (!isLocal(job.uses))
119
+ continue;
120
+ const file = resolveLocal(job.uses, []);
121
+ if (!file || stack.includes(file) || stack.length >= MAX_DEPTH)
122
+ continue;
123
+ try {
124
+ const called = (0, workflow_parser_1.parseFile)(file);
125
+ if (called.type === 'workflow') {
126
+ addWorkflow(called.file, `${jobPath} > ${job.uses} > `, [
127
+ ...stack,
128
+ file
129
+ ]);
130
+ }
131
+ }
132
+ catch {
133
+ // Unparseable reusable workflow: skip.
134
+ }
135
+ continue;
136
+ }
137
+ (job.steps ?? []).forEach((step, i) => addStep(step, `${jobPath}.steps[${i}]`, stack));
138
+ }
139
+ };
140
+ addWorkflow(parsed.file, '', [path.resolve(parsed.path)]);
141
+ return refs;
142
+ }
143
+ /**
144
+ * The inventory of a workflow: every reference, plus the distinct remote
145
+ * actions resolved to commit SHAs (an already-pinned ref resolves to
146
+ * itself; otherwise `resolveSha` is consulted).
147
+ */
148
+ async function buildInventory(parsed, resolveSha) {
149
+ const references = collectReferences(parsed);
150
+ const remote = references.filter((r) => r.kind === 'action' || r.kind === 'reusable-workflow');
151
+ const byUses = new Map();
152
+ for (const ref of remote) {
153
+ if (!ref.owner || !ref.repo)
154
+ continue;
155
+ let action = byUses.get(ref.uses);
156
+ if (!action) {
157
+ action = {
158
+ uses: ref.uses,
159
+ owner: ref.owner,
160
+ repo: ref.repo,
161
+ subpath: ref.subpath,
162
+ ref: ref.ref,
163
+ pinned: ref.pinned,
164
+ resolvedSha: ref.ref && FULL_SHA.test(ref.ref) ? ref.ref.toLowerCase() : undefined,
165
+ paths: []
166
+ };
167
+ byUses.set(ref.uses, action);
168
+ }
169
+ action.paths.push(ref.path);
170
+ }
171
+ if (resolveSha) {
172
+ for (const action of byUses.values()) {
173
+ if (!action.resolvedSha) {
174
+ action.resolvedSha = await resolveSha(action.uses);
175
+ }
176
+ }
177
+ }
178
+ return {
179
+ workflow: parsed.path,
180
+ actions: [...byUses.values()],
181
+ references
182
+ };
183
+ }
184
+ /** Compare current `uses -> sha` against a lockfile's recorded commits. */
185
+ function diffLock(current, lock) {
186
+ const drifted = [];
187
+ const added = [];
188
+ for (const [uses, sha] of Object.entries(current)) {
189
+ const known = lock.actions[uses];
190
+ if (known === undefined)
191
+ added.push(uses);
192
+ else if (known !== sha)
193
+ drifted.push({ uses, from: known, to: sha });
194
+ }
195
+ const removed = Object.keys(lock.actions).filter((uses) => !(uses in current));
196
+ return {
197
+ changed: drifted.length > 0 || added.length > 0 || removed.length > 0,
198
+ drifted,
199
+ added: added.sort(),
200
+ removed: removed.sort()
201
+ };
202
+ }
203
+ /** The `uses -> resolvedSha` map an inventory contributes to a lockfile. */
204
+ function lockEntries(inv) {
205
+ const entries = {};
206
+ for (const action of inv.actions) {
207
+ if (action.resolvedSha)
208
+ entries[action.uses] = action.resolvedSha;
209
+ }
210
+ return entries;
211
+ }
212
+ //# sourceMappingURL=inventory.js.map
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parsePipelineContract = parsePipelineContract;
37
+ const fs = __importStar(require("fs"));
38
+ const YAML = __importStar(require("yaml"));
39
+ /**
40
+ * Parse a pipeline contract file (`secureci validate --contract <file>`).
41
+ *
42
+ * Shape:
43
+ * ```yaml
44
+ * ordering: relative # or "strict" (default: relative)
45
+ * required:
46
+ * - uses: org/security-scan
47
+ * min-version: v1.2.0
48
+ * - uses: org/deploy
49
+ * forbidden:
50
+ * - uses: org/legacy-deploy
51
+ * ```
52
+ */
53
+ function parsePipelineContract(filePath) {
54
+ if (!fs.existsSync(filePath)) {
55
+ throw new Error(`Contract file not found: ${filePath}`);
56
+ }
57
+ const content = fs.readFileSync(filePath, 'utf-8');
58
+ let parsed;
59
+ try {
60
+ parsed = YAML.parse(content);
61
+ }
62
+ catch (error) {
63
+ throw new Error(`Failed to parse contract file: ${error instanceof Error ? error.message : 'Unknown error'}`);
64
+ }
65
+ if (parsed === null || parsed === undefined) {
66
+ return {};
67
+ }
68
+ if (typeof parsed !== 'object' || Array.isArray(parsed)) {
69
+ throw new Error('Contract file must be a YAML mapping with optional "ordering", "required", and "forbidden" sections');
70
+ }
71
+ const spec = parsed;
72
+ if (spec.ordering !== undefined &&
73
+ spec.ordering !== 'relative' &&
74
+ spec.ordering !== 'strict') {
75
+ throw new Error(`Contract "ordering" must be "relative" or "strict", got "${String(spec.ordering)}"`);
76
+ }
77
+ const result = {};
78
+ if (spec.ordering)
79
+ result.ordering = spec.ordering;
80
+ if (spec.required !== undefined) {
81
+ result.required = parseEntryList(spec.required, 'required');
82
+ }
83
+ if (spec.forbidden !== undefined) {
84
+ result.forbidden = parseEntryList(spec.forbidden, 'forbidden');
85
+ }
86
+ if (spec.pins !== undefined) {
87
+ if (typeof spec.pins !== 'object' || spec.pins === null) {
88
+ throw new Error('Contract "pins" must be a mapping');
89
+ }
90
+ const pins = spec.pins;
91
+ result.pins = {};
92
+ if (pins.required !== undefined) {
93
+ result.pins.required = pins.required === true;
94
+ }
95
+ if (pins.allow !== undefined) {
96
+ result.pins.allow = parseStringList(pins.allow, 'pins.allow');
97
+ }
98
+ }
99
+ if (spec['allowed-owners'] !== undefined) {
100
+ result.allowedOwners = parseStringList(spec['allowed-owners'], 'allowed-owners');
101
+ }
102
+ return result;
103
+ }
104
+ function parseStringList(value, section) {
105
+ if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
106
+ throw new Error(`Contract "${section}" must be a list of strings`);
107
+ }
108
+ return value;
109
+ }
110
+ function parseEntryList(value, section) {
111
+ if (!Array.isArray(value)) {
112
+ throw new Error(`Contract "${section}" must be a list of entries`);
113
+ }
114
+ return value.map((entry, idx) => {
115
+ if (typeof entry !== 'object' ||
116
+ entry === null ||
117
+ typeof entry.uses !== 'string') {
118
+ throw new Error(`Contract "${section}[${idx}]" must be a mapping with a string "uses" field`);
119
+ }
120
+ const e = entry;
121
+ const parsedEntry = { uses: e.uses };
122
+ if (e['min-version'] !== undefined) {
123
+ parsedEntry['min-version'] = String(e['min-version']);
124
+ }
125
+ if (e.version !== undefined) {
126
+ parsedEntry.version = String(e.version);
127
+ }
128
+ return parsedEntry;
129
+ });
130
+ }
131
+ //# sourceMappingURL=pipeline-contract-parser.js.map