@playcraft/build 0.1.89 → 0.1.90
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/audio-source-files.d.ts +5 -0
- package/dist/audio-source-files.js +135 -0
- package/dist/base-builder.js +41 -2
- package/dist/delivery/agent-build-runner.d.ts +44 -0
- package/dist/delivery/agent-build-runner.js +365 -0
- package/dist/delivery/agent-build-source.d.ts +8 -0
- package/dist/delivery/agent-build-source.js +25 -0
- package/dist/delivery/artifact-descriptor.d.ts +31 -0
- package/dist/delivery/artifact-descriptor.js +237 -0
- package/dist/delivery/artifact-package.d.ts +43 -0
- package/dist/delivery/artifact-package.js +283 -0
- package/dist/delivery/build-plan.d.ts +4 -0
- package/dist/delivery/build-plan.js +189 -0
- package/dist/delivery/build-plan.types.d.ts +51 -0
- package/dist/delivery/build-plan.types.js +1 -0
- package/dist/delivery/command-isolation.d.ts +7 -0
- package/dist/delivery/command-isolation.js +252 -0
- package/dist/delivery/commands.d.ts +5 -0
- package/dist/delivery/commands.js +137 -0
- package/dist/delivery/files.d.ts +9 -0
- package/dist/delivery/files.js +144 -0
- package/dist/delivery/git-source-fingerprint.d.ts +2 -0
- package/dist/delivery/git-source-fingerprint.js +58 -0
- package/dist/delivery/isolated-source.d.ts +5 -0
- package/dist/delivery/isolated-source.js +126 -0
- package/dist/delivery/output-publication.d.ts +21 -0
- package/dist/delivery/output-publication.js +444 -0
- package/dist/delivery/project-delivery.d.ts +6 -0
- package/dist/delivery/project-delivery.js +287 -0
- package/dist/delivery/recipe-build-plan.d.ts +4 -0
- package/dist/delivery/recipe-build-plan.js +53 -0
- package/dist/delivery/recipe.d.ts +20 -0
- package/dist/delivery/recipe.js +211 -0
- package/dist/delivery/safe-path.d.ts +2 -0
- package/dist/delivery/safe-path.js +18 -0
- package/dist/delivery/types.d.ts +76 -0
- package/dist/delivery/types.js +1 -0
- package/dist/engines/engine-detector.js +4 -0
- package/dist/engines/generic-adapter.js +14 -19
- package/dist/index.d.ts +19 -4
- package/dist/index.js +11 -2
- package/dist/platforms/adikteev.js +1 -0
- package/dist/platforms/applovin.js +1 -0
- package/dist/platforms/base.js +2 -2
- package/dist/platforms/bigo.js +1 -0
- package/dist/platforms/facebook.js +1 -0
- package/dist/platforms/google.js +1 -0
- package/dist/platforms/inmobi.js +1 -0
- package/dist/platforms/ironsource.js +1 -0
- package/dist/platforms/liftoff.js +1 -0
- package/dist/platforms/mintegral.js +1 -0
- package/dist/platforms/moloco.js +1 -0
- package/dist/platforms/playcraft.js +1 -0
- package/dist/platforms/remerge.js +1 -0
- package/dist/platforms/snapchat.js +1 -0
- package/dist/platforms/tiktok.js +1 -0
- package/dist/platforms/unity.js +1 -0
- package/dist/production-animation-presence.d.ts +2 -0
- package/dist/production-animation-presence.js +146 -0
- package/dist/production-inputs.d.ts +30 -0
- package/dist/production-inputs.js +262 -0
- package/dist/production-source-paths.d.ts +5 -0
- package/dist/production-source-paths.js +27 -0
- package/dist/types.d.ts +5 -0
- package/dist/validation/artifact-qa.d.ts +44 -0
- package/dist/validation/artifact-qa.js +170 -0
- package/dist/validation/artifact-rules.d.ts +28 -0
- package/dist/validation/artifact-rules.js +440 -0
- package/dist/validation/artifact.d.ts +14 -0
- package/dist/validation/artifact.js +188 -0
- package/dist/validation/html-validator.d.ts +5 -0
- package/dist/validation/html-validator.js +19 -17
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.js +4 -0
- package/dist/validation/package-validator.d.ts +2 -0
- package/dist/validation/package-validator.js +25 -64
- package/dist/validation/profiles.d.ts +13 -1
- package/dist/validation/profiles.js +27 -0
- package/dist/validation/runtime-load.d.ts +89 -0
- package/dist/validation/runtime-load.js +654 -0
- package/dist/validation/source-scanner.d.ts +11 -0
- package/dist/validation/source-scanner.js +32 -2
- package/dist/validation/types.d.ts +155 -2
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +22 -2
- package/dist/validation/validation-runner.js +68 -3
- package/dist/validation/zip-reader.d.ts +7 -0
- package/dist/validation/zip-reader.js +159 -26
- package/dist/vite/config-builder-generic.d.ts +3 -1
- package/dist/vite/config-builder-generic.js +9 -7
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +30 -54
- package/dist/vite/plugin-source-builder.d.ts +2 -14
- package/dist/vite/plugin-source-builder.js +61 -997
- package/dist/vite/source-builder-asset-paths.d.ts +25 -0
- package/dist/vite/source-builder-asset-paths.js +154 -0
- package/dist/vite/source-builder-esm.d.ts +7 -0
- package/dist/vite/source-builder-esm.js +877 -0
- package/dist/vite/source-builder-types.d.ts +14 -0
- package/dist/vite/source-builder-types.js +1 -0
- package/dist/vite/workspace.d.ts +6 -0
- package/dist/vite/workspace.js +41 -0
- package/dist/vite-builder.d.ts +4 -5
- package/dist/vite-builder.js +33 -34
- package/dist/workspace-css-imports.d.ts +2 -0
- package/dist/workspace-css-imports.js +139 -0
- package/dist/workspace-model-source.d.ts +14 -0
- package/dist/workspace-model-source.js +184 -0
- package/dist/workspace-public-imports.d.ts +11 -0
- package/dist/workspace-public-imports.js +232 -0
- package/dist/workspace-public-source.d.ts +15 -0
- package/dist/workspace-public-source.js +564 -0
- package/package.json +15 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OutputFormat, Platform } from '../types.js';
|
|
2
|
+
import type { ValidationReport } from '../validation/types.js';
|
|
3
|
+
export type ArtifactFileDescriptor = {
|
|
4
|
+
path: string;
|
|
5
|
+
sizeBytes: number;
|
|
6
|
+
sha256: string;
|
|
7
|
+
};
|
|
8
|
+
export type ArtifactDescriptor = {
|
|
9
|
+
version: 1;
|
|
10
|
+
channel: Platform;
|
|
11
|
+
format: OutputFormat;
|
|
12
|
+
artifactDigest: string;
|
|
13
|
+
sizeBytes: number;
|
|
14
|
+
contentMd5Base64: string;
|
|
15
|
+
contentType: 'text/html; charset=utf-8' | 'application/zip';
|
|
16
|
+
files: ArtifactFileDescriptor[];
|
|
17
|
+
sourceFingerprint: string;
|
|
18
|
+
recipeDigest: string;
|
|
19
|
+
environmentDigest: string;
|
|
20
|
+
channelRulesVersion: string;
|
|
21
|
+
validation: ValidationReport;
|
|
22
|
+
};
|
|
23
|
+
export type ArtifactIdentity = Pick<ArtifactDescriptor, 'sourceFingerprint' | 'recipeDigest' | 'environmentDigest' | 'channelRulesVersion'>;
|
|
24
|
+
export declare function parseArtifactDescriptor(value: unknown): ArtifactDescriptor;
|
|
25
|
+
export declare function artifactBytesDigest(bytes: Uint8Array): {
|
|
26
|
+
artifactDigest: string;
|
|
27
|
+
sizeBytes: number;
|
|
28
|
+
contentMd5Base64: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function artifactFileDescriptor(path: string, bytes: Uint8Array): ArtifactFileDescriptor;
|
|
31
|
+
export declare function assertArtifactDescriptorDigest(value: unknown, bytes: Uint8Array): ArtifactDescriptor;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { CHANNEL_RULE_PROFILES } from '../validation/profiles.js';
|
|
3
|
+
import { ProjectDeliveryError } from './recipe.js';
|
|
4
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
5
|
+
const STATUSES = ['pass', 'failed', 'warning', 'manual-required'];
|
|
6
|
+
const RULE_STATUSES = ['pass', 'fail', 'warning', 'manual', 'external', 'not-applicable'];
|
|
7
|
+
const STAGES = ['prebuild-source', 'base-output', 'html-artifact', 'delivery-package', 'runtime-manual', 'external-validator'];
|
|
8
|
+
const SEVERITIES = ['error', 'warning', 'info'];
|
|
9
|
+
const OWNERS = ['playcraft-build', 'playcraft-delivery', 'devkit', 'manual', 'external'];
|
|
10
|
+
const CONFIDENCE = ['high', 'medium', 'low'];
|
|
11
|
+
const CHAINS = ['generic', 'devkit', 'playcanvas-native'];
|
|
12
|
+
function invalid(message, file) {
|
|
13
|
+
throw new ProjectDeliveryError('artifact_descriptor_invalid', message, file);
|
|
14
|
+
}
|
|
15
|
+
function record(value, field) {
|
|
16
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
17
|
+
invalid(`${field} must be an object`);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function exactKeys(value, expected, field) {
|
|
21
|
+
const actual = Object.keys(value).sort();
|
|
22
|
+
const sorted = [...expected].sort();
|
|
23
|
+
if (actual.length !== sorted.length || actual.some((key, index) => key !== sorted[index])) {
|
|
24
|
+
invalid(`${field} has missing or unsupported fields`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function allowedKeys(value, allowed, field) {
|
|
28
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
29
|
+
invalid(`${field} has unsupported fields`);
|
|
30
|
+
}
|
|
31
|
+
function text(value, field, maximum = 8192) {
|
|
32
|
+
if (typeof value !== 'string' || !value || value.length > maximum || value.includes('\0')) {
|
|
33
|
+
invalid(`Invalid ${field}`);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function integer(value, field, maximum = Number.MAX_SAFE_INTEGER) {
|
|
38
|
+
if (!Number.isSafeInteger(value) || Number(value) < 0 || Number(value) > maximum)
|
|
39
|
+
invalid(`Invalid ${field}`);
|
|
40
|
+
return Number(value);
|
|
41
|
+
}
|
|
42
|
+
function hash(value, field) {
|
|
43
|
+
const result = text(value, field, 64);
|
|
44
|
+
if (!HASH.test(result))
|
|
45
|
+
invalid(`${field} must be a lowercase SHA-256 digest`);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function choice(value, choices, field) {
|
|
49
|
+
if (typeof value !== 'string' || !choices.includes(value))
|
|
50
|
+
invalid(`Invalid ${field}`);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function channel(value, allowCommon = false) {
|
|
54
|
+
const result = text(value, 'channel', 64);
|
|
55
|
+
if ((allowCommon && result === 'common') || Object.prototype.hasOwnProperty.call(CHANNEL_RULE_PROFILES, result)) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
invalid('Invalid validation channel');
|
|
59
|
+
}
|
|
60
|
+
function artifactPath(value) {
|
|
61
|
+
const result = text(value, 'files.path', 1024);
|
|
62
|
+
if (result.includes('\\') ||
|
|
63
|
+
result.startsWith('/') ||
|
|
64
|
+
/^[A-Za-z]:/.test(result) ||
|
|
65
|
+
result.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
66
|
+
invalid('Artifact files must use normalized POSIX relative paths', result);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function parseFiles(value) {
|
|
71
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > 4096)
|
|
72
|
+
invalid('Invalid files');
|
|
73
|
+
const paths = new Set();
|
|
74
|
+
const folded = new Set();
|
|
75
|
+
let previous = '';
|
|
76
|
+
const files = value.map((item, index) => {
|
|
77
|
+
const input = record(item, `files[${index}]`);
|
|
78
|
+
exactKeys(input, ['path', 'sizeBytes', 'sha256'], `files[${index}]`);
|
|
79
|
+
const member = artifactPath(input.path);
|
|
80
|
+
const caseFolded = member.normalize('NFC').toLowerCase();
|
|
81
|
+
if (paths.has(member))
|
|
82
|
+
invalid('Duplicate artifact file', member);
|
|
83
|
+
if (folded.has(caseFolded))
|
|
84
|
+
invalid('Case-conflicting artifact file', member);
|
|
85
|
+
if (index > 0 && Buffer.compare(Buffer.from(previous), Buffer.from(member)) >= 0) {
|
|
86
|
+
invalid('Artifact files must be sorted by UTF-8 path bytes');
|
|
87
|
+
}
|
|
88
|
+
paths.add(member);
|
|
89
|
+
folded.add(caseFolded);
|
|
90
|
+
previous = member;
|
|
91
|
+
return {
|
|
92
|
+
path: member,
|
|
93
|
+
sizeBytes: integer(input.sizeBytes, `files[${index}].sizeBytes`, 64 * 1024 * 1024),
|
|
94
|
+
sha256: hash(input.sha256, `files[${index}].sha256`),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return files;
|
|
98
|
+
}
|
|
99
|
+
function parseResult(value, index) {
|
|
100
|
+
const input = record(value, `validation.results[${index}]`);
|
|
101
|
+
allowedKeys(input, ['ruleId', 'channel', 'stage', 'severity', 'status', 'message', 'recommendation', 'file', 'line', 'evidence', 'owner', 'confidence'], `validation.results[${index}]`);
|
|
102
|
+
for (const key of ['ruleId', 'channel', 'stage', 'severity', 'status', 'message', 'recommendation', 'owner', 'confidence']) {
|
|
103
|
+
if (input[key] === undefined)
|
|
104
|
+
invalid(`Missing validation result ${key}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
ruleId: text(input.ruleId, 'ruleId', 256),
|
|
108
|
+
channel: channel(input.channel, true),
|
|
109
|
+
stage: choice(input.stage, STAGES, 'stage'),
|
|
110
|
+
severity: choice(input.severity, SEVERITIES, 'severity'),
|
|
111
|
+
status: choice(input.status, RULE_STATUSES, 'status'),
|
|
112
|
+
message: text(input.message, 'message'),
|
|
113
|
+
recommendation: text(input.recommendation, 'recommendation'),
|
|
114
|
+
...(input.file !== undefined ? { file: text(input.file, 'file', 2048) } : {}),
|
|
115
|
+
...(input.line !== undefined ? { line: integer(input.line, 'line', 1000000000) } : {}),
|
|
116
|
+
...(input.evidence !== undefined ? { evidence: text(input.evidence, 'evidence') } : {}),
|
|
117
|
+
owner: choice(input.owner, OWNERS, 'owner'),
|
|
118
|
+
confidence: choice(input.confidence, CONFIDENCE, 'confidence'),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function parseChecklist(value, field) {
|
|
122
|
+
if (!Array.isArray(value) || value.length > 4096)
|
|
123
|
+
invalid(`Invalid ${field}`);
|
|
124
|
+
return value.map((item, index) => {
|
|
125
|
+
const input = record(item, `${field}[${index}]`);
|
|
126
|
+
exactKeys(input, ['ruleId', 'channel', 'stage', 'message', 'recommendation', 'owner'], `${field}[${index}]`);
|
|
127
|
+
return {
|
|
128
|
+
ruleId: text(input.ruleId, 'ruleId', 256),
|
|
129
|
+
channel: channel(input.channel, true),
|
|
130
|
+
stage: choice(input.stage, STAGES, 'stage'),
|
|
131
|
+
message: text(input.message, 'message'),
|
|
132
|
+
recommendation: text(input.recommendation, 'recommendation'),
|
|
133
|
+
owner: choice(input.owner, OWNERS, 'owner'),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function parseValidation(value, expectedChannel) {
|
|
138
|
+
const input = record(value, 'validation');
|
|
139
|
+
exactKeys(input, ['version', 'channel', 'buildChain', 'summary', 'results', 'manualChecklist', 'externalChecklist'], 'validation');
|
|
140
|
+
const actualChannel = channel(input.channel);
|
|
141
|
+
if (actualChannel !== expectedChannel)
|
|
142
|
+
invalid('Validation channel differs from artifact channel');
|
|
143
|
+
if (!Array.isArray(input.results) || input.results.length > 4096)
|
|
144
|
+
invalid('Invalid validation results');
|
|
145
|
+
const results = input.results.map(parseResult);
|
|
146
|
+
const manualChecklist = parseChecklist(input.manualChecklist, 'manualChecklist');
|
|
147
|
+
const externalChecklist = parseChecklist(input.externalChecklist, 'externalChecklist');
|
|
148
|
+
const summary = record(input.summary, 'validation.summary');
|
|
149
|
+
exactKeys(summary, ['status', 'errorCount', 'warningCount', 'manualCount', 'externalCount'], 'validation.summary');
|
|
150
|
+
const errorCount = results.filter((result) => result.status === 'fail').length;
|
|
151
|
+
const warningCount = results.filter((result) => result.status === 'warning').length;
|
|
152
|
+
const expectedStatus = errorCount > 0
|
|
153
|
+
? 'failed'
|
|
154
|
+
: warningCount > 0
|
|
155
|
+
? 'warning'
|
|
156
|
+
: manualChecklist.length > 0 || externalChecklist.length > 0
|
|
157
|
+
? 'manual-required'
|
|
158
|
+
: 'pass';
|
|
159
|
+
if (choice(summary.status, STATUSES, 'summary.status') !== expectedStatus ||
|
|
160
|
+
integer(summary.errorCount, 'summary.errorCount', 4096) !== errorCount ||
|
|
161
|
+
integer(summary.warningCount, 'summary.warningCount', 4096) !== warningCount ||
|
|
162
|
+
integer(summary.manualCount, 'summary.manualCount', 4096) !== manualChecklist.length ||
|
|
163
|
+
integer(summary.externalCount, 'summary.externalCount', 4096) !== externalChecklist.length) {
|
|
164
|
+
invalid('Validation summary does not match its findings');
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
version: text(input.version, 'validation.version', 64),
|
|
168
|
+
channel: actualChannel,
|
|
169
|
+
buildChain: choice(input.buildChain, CHAINS, 'validation.buildChain'),
|
|
170
|
+
summary: {
|
|
171
|
+
status: expectedStatus,
|
|
172
|
+
errorCount,
|
|
173
|
+
warningCount,
|
|
174
|
+
manualCount: manualChecklist.length,
|
|
175
|
+
externalCount: externalChecklist.length,
|
|
176
|
+
},
|
|
177
|
+
results,
|
|
178
|
+
manualChecklist,
|
|
179
|
+
externalChecklist,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function parseArtifactDescriptor(value) {
|
|
183
|
+
const input = record(value, 'artifactDescriptor');
|
|
184
|
+
exactKeys(input, ['version', 'channel', 'format', 'artifactDigest', 'sizeBytes', 'contentMd5Base64', 'contentType', 'files', 'sourceFingerprint', 'recipeDigest', 'environmentDigest', 'channelRulesVersion', 'validation'], 'artifactDescriptor');
|
|
185
|
+
if (input.version !== 1)
|
|
186
|
+
invalid('artifactDescriptor.version must be 1');
|
|
187
|
+
const actualChannel = channel(input.channel);
|
|
188
|
+
const format = choice(input.format, ['html', 'zip'], 'format');
|
|
189
|
+
const files = parseFiles(input.files);
|
|
190
|
+
if (format === 'html' && files.length !== 1)
|
|
191
|
+
invalid('HTML descriptor must contain exactly one file');
|
|
192
|
+
const md5 = text(input.contentMd5Base64, 'contentMd5Base64', 24);
|
|
193
|
+
if (!/^[A-Za-z0-9+/]{22}==$/.test(md5))
|
|
194
|
+
invalid('contentMd5Base64 must be a Base64 MD5');
|
|
195
|
+
const expectedContentType = format === 'html' ? 'text/html; charset=utf-8' : 'application/zip';
|
|
196
|
+
if (input.contentType !== expectedContentType)
|
|
197
|
+
invalid('Invalid contentType');
|
|
198
|
+
return {
|
|
199
|
+
version: 1,
|
|
200
|
+
channel: actualChannel,
|
|
201
|
+
format,
|
|
202
|
+
artifactDigest: hash(input.artifactDigest, 'artifactDigest'),
|
|
203
|
+
sizeBytes: integer(input.sizeBytes, 'sizeBytes', 64 * 1024 * 1024),
|
|
204
|
+
contentMd5Base64: md5,
|
|
205
|
+
contentType: expectedContentType,
|
|
206
|
+
files,
|
|
207
|
+
sourceFingerprint: hash(input.sourceFingerprint, 'sourceFingerprint'),
|
|
208
|
+
recipeDigest: hash(input.recipeDigest, 'recipeDigest'),
|
|
209
|
+
environmentDigest: hash(input.environmentDigest, 'environmentDigest'),
|
|
210
|
+
channelRulesVersion: text(input.channelRulesVersion, 'channelRulesVersion', 64),
|
|
211
|
+
validation: parseValidation(input.validation, actualChannel),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function artifactBytesDigest(bytes) {
|
|
215
|
+
return {
|
|
216
|
+
artifactDigest: createHash('sha256').update(bytes).digest('hex'),
|
|
217
|
+
sizeBytes: bytes.byteLength,
|
|
218
|
+
contentMd5Base64: createHash('md5').update(bytes).digest('base64'),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export function artifactFileDescriptor(path, bytes) {
|
|
222
|
+
return {
|
|
223
|
+
path,
|
|
224
|
+
sizeBytes: bytes.byteLength,
|
|
225
|
+
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export function assertArtifactDescriptorDigest(value, bytes) {
|
|
229
|
+
const descriptor = parseArtifactDescriptor(value);
|
|
230
|
+
const actual = artifactBytesDigest(bytes);
|
|
231
|
+
if (descriptor.artifactDigest !== actual.artifactDigest ||
|
|
232
|
+
descriptor.sizeBytes !== actual.sizeBytes ||
|
|
233
|
+
descriptor.contentMd5Base64 !== actual.contentMd5Base64) {
|
|
234
|
+
throw new ProjectDeliveryError('artifact_descriptor_mismatch', 'Artifact descriptor does not match the final bytes');
|
|
235
|
+
}
|
|
236
|
+
return descriptor;
|
|
237
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { OutputFormat, Platform } from '../types.js';
|
|
2
|
+
import { type ArtifactDescriptor, type ArtifactIdentity } from './artifact-descriptor.js';
|
|
3
|
+
export declare const ARTIFACT_LIMITS: {
|
|
4
|
+
readonly maxFiles: 4096;
|
|
5
|
+
readonly maxFileBytes: number;
|
|
6
|
+
readonly maxTotalBytes: number;
|
|
7
|
+
readonly maxCompressionRatio: 200;
|
|
8
|
+
};
|
|
9
|
+
export type ArtifactInputFile = {
|
|
10
|
+
path: string;
|
|
11
|
+
bytes: Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
export type PackageChannelArtifactOptions = ArtifactIdentity & {
|
|
14
|
+
channel: Platform;
|
|
15
|
+
format: OutputFormat;
|
|
16
|
+
files: ArtifactInputFile[];
|
|
17
|
+
projectRoot?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function normalizeArtifactPath(value: string): string;
|
|
20
|
+
export declare function validateArtifactFiles(values: readonly ArtifactInputFile[], channel: Platform): ArtifactInputFile[];
|
|
21
|
+
export declare function readArtifactDirectory(root: string, channel: Platform): Promise<ArtifactInputFile[]>;
|
|
22
|
+
/** Uses the streaming API so even numeric-looking filenames retain UTF-8 path ordering. */
|
|
23
|
+
export declare function createNormalizedZip(values: readonly ArtifactInputFile[], channel: Platform): Promise<Buffer>;
|
|
24
|
+
export declare function readZipArtifact(bytes: Uint8Array, channel: Platform): Promise<ArtifactInputFile[]>;
|
|
25
|
+
export declare function packageChannelArtifact(options: PackageChannelArtifactOptions): Promise<{
|
|
26
|
+
bytes: Buffer;
|
|
27
|
+
descriptor: ArtifactDescriptor;
|
|
28
|
+
}>;
|
|
29
|
+
export type DescribeChannelArtifactOptions = ArtifactIdentity & {
|
|
30
|
+
channel: Platform;
|
|
31
|
+
format: OutputFormat;
|
|
32
|
+
bytes: Uint8Array;
|
|
33
|
+
artifactName?: string;
|
|
34
|
+
projectRoot?: string;
|
|
35
|
+
};
|
|
36
|
+
/** Rebuilds the descriptor from actual bytes; used by Business instead of trusting Runner metadata. */
|
|
37
|
+
export declare function describeChannelArtifact(options: DescribeChannelArtifactOptions): Promise<ArtifactDescriptor>;
|
|
38
|
+
/** Checks digest, per-file hashes and a fresh channel report against the supplied manifest. */
|
|
39
|
+
export declare function verifyChannelArtifactDescriptor(value: unknown, options: {
|
|
40
|
+
bytes: Uint8Array;
|
|
41
|
+
artifactName?: string;
|
|
42
|
+
projectRoot?: string;
|
|
43
|
+
}): Promise<ArtifactDescriptor>;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, open, readdir, realpath } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { Zip, ZipDeflate } from 'fflate';
|
|
5
|
+
import { getChannelCapability } from '../validation/profiles.js';
|
|
6
|
+
import { runChannelArtifactValidation } from '../validation/validation-runner.js';
|
|
7
|
+
import { SimpleZipReader } from '../validation/zip-reader.js';
|
|
8
|
+
import { ProjectDeliveryError } from './recipe.js';
|
|
9
|
+
import { artifactBytesDigest, artifactFileDescriptor, assertArtifactDescriptorDigest, } from './artifact-descriptor.js';
|
|
10
|
+
export const ARTIFACT_LIMITS = {
|
|
11
|
+
maxFiles: 4096,
|
|
12
|
+
maxFileBytes: 64 * 1024 * 1024,
|
|
13
|
+
maxTotalBytes: 128 * 1024 * 1024,
|
|
14
|
+
maxCompressionRatio: 200,
|
|
15
|
+
};
|
|
16
|
+
function failure(code, message, file) {
|
|
17
|
+
throw new ProjectDeliveryError(code, message, file);
|
|
18
|
+
}
|
|
19
|
+
export function normalizeArtifactPath(value) {
|
|
20
|
+
if (!value ||
|
|
21
|
+
value.length > 1024 ||
|
|
22
|
+
value.includes('\0') ||
|
|
23
|
+
value.includes('\\') ||
|
|
24
|
+
path.posix.isAbsolute(value) ||
|
|
25
|
+
/^[A-Za-z]:/.test(value) ||
|
|
26
|
+
value.split('/').some((segment) => !segment || segment === '.' || segment === '..') ||
|
|
27
|
+
path.posix.normalize(value) !== value) {
|
|
28
|
+
failure('artifact_path_unsafe', 'Artifact paths must be normalized POSIX relative paths', value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function comparePaths(left, right) {
|
|
33
|
+
return Buffer.compare(Buffer.from(left, 'utf8'), Buffer.from(right, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
export function validateArtifactFiles(values, channel) {
|
|
36
|
+
const capability = getChannelCapability(channel);
|
|
37
|
+
const maximumFiles = Math.min(capability.maxFiles ?? ARTIFACT_LIMITS.maxFiles, ARTIFACT_LIMITS.maxFiles);
|
|
38
|
+
if (values.length === 0 || values.length > maximumFiles) {
|
|
39
|
+
failure('artifact_file_count_invalid', `Artifact must contain between 1 and ${maximumFiles} files`);
|
|
40
|
+
}
|
|
41
|
+
const paths = new Set();
|
|
42
|
+
const caseInsensitivePaths = new Set();
|
|
43
|
+
let totalBytes = 0;
|
|
44
|
+
const files = values.map((value) => {
|
|
45
|
+
const member = normalizeArtifactPath(value.path);
|
|
46
|
+
const folded = member.normalize('NFC').toLowerCase();
|
|
47
|
+
if (paths.has(member))
|
|
48
|
+
failure('artifact_duplicate_path', 'Duplicate artifact path', member);
|
|
49
|
+
if (caseInsensitivePaths.has(folded)) {
|
|
50
|
+
failure('artifact_case_conflict', 'Artifact paths differ only by case', member);
|
|
51
|
+
}
|
|
52
|
+
paths.add(member);
|
|
53
|
+
caseInsensitivePaths.add(folded);
|
|
54
|
+
if (!Number.isSafeInteger(value.bytes.byteLength) || value.bytes.byteLength > ARTIFACT_LIMITS.maxFileBytes) {
|
|
55
|
+
failure('artifact_file_too_large', 'Artifact file exceeds the size limit', member);
|
|
56
|
+
}
|
|
57
|
+
totalBytes += value.bytes.byteLength;
|
|
58
|
+
if (totalBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
59
|
+
failure('artifact_total_size_exceeded', 'Artifact uncompressed size exceeds the limit');
|
|
60
|
+
}
|
|
61
|
+
return { path: member, bytes: Buffer.from(value.bytes) };
|
|
62
|
+
});
|
|
63
|
+
if (capability.rootEntryRequired && !paths.has('index.html')) {
|
|
64
|
+
failure('artifact_root_entry_required', 'This channel requires a root index.html');
|
|
65
|
+
}
|
|
66
|
+
return files.sort((left, right) => comparePaths(left.path, right.path));
|
|
67
|
+
}
|
|
68
|
+
export async function readArtifactDirectory(root, channel) {
|
|
69
|
+
const requestedInfo = await lstat(root);
|
|
70
|
+
if (!requestedInfo.isDirectory() || requestedInfo.isSymbolicLink()) {
|
|
71
|
+
failure('artifact_source_invalid', 'Artifact source must be a real non-aliased directory');
|
|
72
|
+
}
|
|
73
|
+
const resolved = await realpath(root);
|
|
74
|
+
const rootInfo = await lstat(resolved);
|
|
75
|
+
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) {
|
|
76
|
+
failure('artifact_source_invalid', 'Artifact source must be a real directory');
|
|
77
|
+
}
|
|
78
|
+
const files = [];
|
|
79
|
+
let visited = 0;
|
|
80
|
+
let totalBytes = 0;
|
|
81
|
+
async function visit(directory, prefix) {
|
|
82
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
83
|
+
for (const entry of entries) {
|
|
84
|
+
if (++visited > ARTIFACT_LIMITS.maxFiles * 2) {
|
|
85
|
+
failure('artifact_file_count_invalid', 'Artifact source contains too many entries');
|
|
86
|
+
}
|
|
87
|
+
const member = normalizeArtifactPath(prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
88
|
+
const filename = path.join(directory, entry.name);
|
|
89
|
+
const info = await lstat(filename);
|
|
90
|
+
if (info.isSymbolicLink() || (!info.isDirectory() && !info.isFile())) {
|
|
91
|
+
failure('artifact_non_regular_file', 'Artifact source contains a non-regular file', member);
|
|
92
|
+
}
|
|
93
|
+
if (info.isDirectory()) {
|
|
94
|
+
await visit(filename, member);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (info.nlink !== 1 || info.size > ARTIFACT_LIMITS.maxFileBytes) {
|
|
98
|
+
failure('artifact_file_too_large', 'Artifact file is linked or exceeds the size limit', member);
|
|
99
|
+
}
|
|
100
|
+
totalBytes += info.size;
|
|
101
|
+
if (totalBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
102
|
+
failure('artifact_total_size_exceeded', 'Artifact uncompressed size exceeds the limit');
|
|
103
|
+
}
|
|
104
|
+
const handle = await open(filename, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
105
|
+
try {
|
|
106
|
+
const before = await handle.stat();
|
|
107
|
+
const bytes = await handle.readFile();
|
|
108
|
+
const after = await handle.stat();
|
|
109
|
+
if (!before.isFile() ||
|
|
110
|
+
!after.isFile() ||
|
|
111
|
+
before.dev !== after.dev ||
|
|
112
|
+
before.ino !== after.ino ||
|
|
113
|
+
before.size !== bytes.byteLength ||
|
|
114
|
+
after.size !== bytes.byteLength ||
|
|
115
|
+
before.mtimeMs !== after.mtimeMs ||
|
|
116
|
+
before.ctimeMs !== after.ctimeMs) {
|
|
117
|
+
failure('artifact_source_changed', 'Artifact source changed while being read', member);
|
|
118
|
+
}
|
|
119
|
+
files.push({ path: member, bytes });
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
await handle.close();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
await visit(resolved, '');
|
|
127
|
+
return validateArtifactFiles(files, channel);
|
|
128
|
+
}
|
|
129
|
+
/** Uses the streaming API so even numeric-looking filenames retain UTF-8 path ordering. */
|
|
130
|
+
export async function createNormalizedZip(values, channel) {
|
|
131
|
+
const files = validateArtifactFiles(values, channel);
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const chunks = [];
|
|
134
|
+
const archive = new Zip((error, data, final) => {
|
|
135
|
+
if (error) {
|
|
136
|
+
reject(error);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
chunks.push(Buffer.from(data));
|
|
140
|
+
if (final)
|
|
141
|
+
resolve(Buffer.concat(chunks));
|
|
142
|
+
});
|
|
143
|
+
for (const file of files) {
|
|
144
|
+
const entry = new ZipDeflate(file.path, { level: 6 });
|
|
145
|
+
entry.mtime = new Date(1980, 0, 1, 0, 0, 0);
|
|
146
|
+
entry.os = 3;
|
|
147
|
+
entry.attrs = 0o100644 << 16;
|
|
148
|
+
archive.add(entry);
|
|
149
|
+
entry.push(file.bytes, true);
|
|
150
|
+
}
|
|
151
|
+
archive.end();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
export async function readZipArtifact(bytes, channel) {
|
|
155
|
+
const reader = new SimpleZipReader(Buffer.from(bytes));
|
|
156
|
+
const entries = reader.listEntries();
|
|
157
|
+
const files = [];
|
|
158
|
+
let compressedBytes = 0;
|
|
159
|
+
let uncompressedBytes = 0;
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
if (entry.isDirectory) {
|
|
162
|
+
failure('artifact_non_regular_file', 'Directory entries are not allowed in a normalized artifact', entry.path);
|
|
163
|
+
}
|
|
164
|
+
normalizeArtifactPath(entry.path);
|
|
165
|
+
if (entry.encrypted || entry.uncompressedSize > ARTIFACT_LIMITS.maxFileBytes) {
|
|
166
|
+
failure('artifact_file_too_large', 'ZIP entry is encrypted or exceeds the size limit', entry.path);
|
|
167
|
+
}
|
|
168
|
+
if (entry.compressionMethod !== 0 && entry.compressionMethod !== 8) {
|
|
169
|
+
failure('artifact_compression_unsupported', 'ZIP entry uses an unsupported compression method', entry.path);
|
|
170
|
+
}
|
|
171
|
+
const fileType = (entry.externalAttributes ?? 0) >>> 16;
|
|
172
|
+
if (fileType !== 0 && (fileType & 0o170000) !== 0o100000) {
|
|
173
|
+
failure('artifact_non_regular_file', 'ZIP entry is not a regular file', entry.path);
|
|
174
|
+
}
|
|
175
|
+
compressedBytes += entry.compressedSize;
|
|
176
|
+
uncompressedBytes += entry.uncompressedSize;
|
|
177
|
+
if (uncompressedBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
178
|
+
failure('artifact_total_size_exceeded', 'ZIP uncompressed size exceeds the limit');
|
|
179
|
+
}
|
|
180
|
+
if (entry.uncompressedSize > 64 * 1024 &&
|
|
181
|
+
entry.uncompressedSize / Math.max(1, entry.compressedSize) > ARTIFACT_LIMITS.maxCompressionRatio) {
|
|
182
|
+
failure('artifact_compression_ratio_exceeded', 'ZIP entry compression ratio exceeds the limit', entry.path);
|
|
183
|
+
}
|
|
184
|
+
const content = reader.readEntry(entry.path);
|
|
185
|
+
if (!content || content.byteLength !== entry.uncompressedSize) {
|
|
186
|
+
failure('artifact_entry_size_mismatch', 'ZIP entry size differs from its central directory', entry.path);
|
|
187
|
+
}
|
|
188
|
+
files.push({ path: entry.path, bytes: content });
|
|
189
|
+
}
|
|
190
|
+
if (compressedBytes > bytes.byteLength) {
|
|
191
|
+
failure('artifact_zip_invalid', 'ZIP compressed sizes exceed the artifact size');
|
|
192
|
+
}
|
|
193
|
+
return validateArtifactFiles(files, channel);
|
|
194
|
+
}
|
|
195
|
+
function descriptor(options, bytes, files, validation) {
|
|
196
|
+
return {
|
|
197
|
+
version: 1,
|
|
198
|
+
channel: options.channel,
|
|
199
|
+
format: options.format,
|
|
200
|
+
...artifactBytesDigest(bytes),
|
|
201
|
+
contentType: options.format === 'html' ? 'text/html; charset=utf-8' : 'application/zip',
|
|
202
|
+
files,
|
|
203
|
+
sourceFingerprint: options.sourceFingerprint,
|
|
204
|
+
recipeDigest: options.recipeDigest,
|
|
205
|
+
environmentDigest: options.environmentDigest,
|
|
206
|
+
channelRulesVersion: options.channelRulesVersion,
|
|
207
|
+
validation,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export async function packageChannelArtifact(options) {
|
|
211
|
+
if (!getChannelCapability(options.channel).supportedFormats.includes(options.format)) {
|
|
212
|
+
failure('delivery_context_invalid', `${options.channel} does not support ${options.format} delivery`);
|
|
213
|
+
}
|
|
214
|
+
const files = validateArtifactFiles(options.files, options.channel);
|
|
215
|
+
if (options.format === 'html' && files.length !== 1) {
|
|
216
|
+
failure('artifact_single_html_required', 'HTML delivery must contain exactly one file');
|
|
217
|
+
}
|
|
218
|
+
const bytes = options.format === 'html'
|
|
219
|
+
? Buffer.from(files[0].bytes)
|
|
220
|
+
: await createNormalizedZip(files, options.channel);
|
|
221
|
+
const entryName = options.format === 'html' ? files[0].path : 'index.html';
|
|
222
|
+
const entry = options.format === 'html'
|
|
223
|
+
? files[0].bytes
|
|
224
|
+
: (await readZipArtifact(bytes, options.channel)).find((file) => file.path === entryName)?.bytes;
|
|
225
|
+
if (!entry)
|
|
226
|
+
failure('artifact_root_entry_required', 'The final artifact has no HTML entry', entryName);
|
|
227
|
+
const validation = await runChannelArtifactValidation({
|
|
228
|
+
channel: options.channel,
|
|
229
|
+
format: options.format,
|
|
230
|
+
bytes,
|
|
231
|
+
htmlBytes: entry,
|
|
232
|
+
artifactName: entryName,
|
|
233
|
+
projectRoot: options.projectRoot,
|
|
234
|
+
});
|
|
235
|
+
return {
|
|
236
|
+
bytes,
|
|
237
|
+
descriptor: descriptor(options, bytes, files.map((file) => artifactFileDescriptor(file.path, file.bytes)), validation),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/** Rebuilds the descriptor from actual bytes; used by Business instead of trusting Runner metadata. */
|
|
241
|
+
export async function describeChannelArtifact(options) {
|
|
242
|
+
const capability = getChannelCapability(options.channel);
|
|
243
|
+
if (!capability.supportedFormats.includes(options.format)) {
|
|
244
|
+
failure('delivery_context_invalid', `${options.channel} does not support ${options.format} delivery`);
|
|
245
|
+
}
|
|
246
|
+
const artifactName = options.artifactName ?? 'index.html';
|
|
247
|
+
const files = options.format === 'html'
|
|
248
|
+
? validateArtifactFiles([{ path: artifactName, bytes: options.bytes }], options.channel)
|
|
249
|
+
: await readZipArtifact(options.bytes, options.channel);
|
|
250
|
+
const entry = options.format === 'html'
|
|
251
|
+
? options.bytes
|
|
252
|
+
: files.find((file) => file.path === 'index.html')?.bytes;
|
|
253
|
+
if (!entry)
|
|
254
|
+
failure('artifact_root_entry_required', 'The final artifact has no root index.html');
|
|
255
|
+
const validation = await runChannelArtifactValidation({
|
|
256
|
+
channel: options.channel,
|
|
257
|
+
format: options.format,
|
|
258
|
+
bytes: options.bytes,
|
|
259
|
+
htmlBytes: entry,
|
|
260
|
+
artifactName: options.format === 'html' ? files[0].path : 'index.html',
|
|
261
|
+
projectRoot: options.projectRoot,
|
|
262
|
+
});
|
|
263
|
+
return descriptor({ ...options, files }, options.bytes, files.map((file) => artifactFileDescriptor(file.path, file.bytes)), validation);
|
|
264
|
+
}
|
|
265
|
+
/** Checks digest, per-file hashes and a fresh channel report against the supplied manifest. */
|
|
266
|
+
export async function verifyChannelArtifactDescriptor(value, options) {
|
|
267
|
+
const expected = assertArtifactDescriptorDigest(value, options.bytes);
|
|
268
|
+
const actual = await describeChannelArtifact({
|
|
269
|
+
channel: expected.channel,
|
|
270
|
+
format: expected.format,
|
|
271
|
+
bytes: options.bytes,
|
|
272
|
+
artifactName: options.artifactName ?? (expected.format === 'html' ? expected.files[0].path : 'index.html'),
|
|
273
|
+
projectRoot: options.projectRoot,
|
|
274
|
+
sourceFingerprint: expected.sourceFingerprint,
|
|
275
|
+
recipeDigest: expected.recipeDigest,
|
|
276
|
+
environmentDigest: expected.environmentDigest,
|
|
277
|
+
channelRulesVersion: expected.channelRulesVersion,
|
|
278
|
+
});
|
|
279
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
280
|
+
throw new ProjectDeliveryError('artifact_descriptor_mismatch', 'Artifact files or validation differ from the descriptor');
|
|
281
|
+
}
|
|
282
|
+
return actual;
|
|
283
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BuildPlan } from './build-plan.types.js';
|
|
2
|
+
/** Strictly parses the portable plan; absolute Runtime workspace paths are deliberately absent. */
|
|
3
|
+
export declare function parseBuildPlan(value: unknown): BuildPlan;
|
|
4
|
+
export declare function buildPlanDigest(value: BuildPlan): string;
|