@playcraft/build 0.1.88 → 0.1.89
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/validation/html-validator.d.ts +0 -3
- package/dist/validation/html-validator.js +3 -3
- package/dist/validation/index.d.ts +0 -4
- package/dist/validation/index.js +0 -4
- package/dist/validation/package-validator.js +51 -3
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -150
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +1 -11
- package/dist/validation/validation-runner.js +1 -31
- package/dist/validation/zip-reader.d.ts +0 -1
- package/dist/validation/zip-reader.js +3 -11
- package/package.json +1 -1
- package/dist/validation/artifact-qa.d.ts +0 -44
- package/dist/validation/artifact-qa.js +0 -170
- package/dist/validation/artifact-rules.d.ts +0 -28
- package/dist/validation/artifact-rules.js +0 -440
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/runtime-load.d.ts +0 -89
- package/dist/validation/runtime-load.js +0 -654
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { SimpleZipReader } from './zip-reader.js';
|
|
5
|
-
export class ArtifactReadError extends Error {
|
|
6
|
-
constructor(code, message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.name = 'ArtifactReadError';
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
const HTML_FILE = /\.html?$/i;
|
|
13
|
-
/**
|
|
14
|
-
* Reads a built playable from a single HTML file, a ZIP file or a directory, and resolves its
|
|
15
|
-
* entry HTML. Only the artifact is inspected; how it was built does not matter.
|
|
16
|
-
*/
|
|
17
|
-
export async function readArtifact(inputPath, options = {}) {
|
|
18
|
-
const sourcePath = path.resolve(inputPath);
|
|
19
|
-
const stat = await fs.stat(sourcePath).catch(() => undefined);
|
|
20
|
-
if (!stat)
|
|
21
|
-
throw new ArtifactReadError('artifact_not_found', `Artifact not found: ${sourcePath}`);
|
|
22
|
-
if (stat.isDirectory()) {
|
|
23
|
-
const source = await directorySource(sourcePath);
|
|
24
|
-
return artifact(sourcePath, 'directory', source, resolveEntry(source.files, options.entry));
|
|
25
|
-
}
|
|
26
|
-
const buffer = await fs.readFile(sourcePath);
|
|
27
|
-
if (isZip(buffer)) {
|
|
28
|
-
const source = zipSource(buffer);
|
|
29
|
-
return artifact(sourcePath, 'zip', source, resolveEntry(source.files, options.entry));
|
|
30
|
-
}
|
|
31
|
-
if (HTML_FILE.test(sourcePath)) {
|
|
32
|
-
if (options.entry !== undefined)
|
|
33
|
-
throw new ArtifactReadError('artifact_entry_invalid', 'An entry can only be chosen inside a ZIP file or a directory');
|
|
34
|
-
const name = path.basename(sourcePath);
|
|
35
|
-
const source = {
|
|
36
|
-
files: [{ path: name, size: buffer.length }],
|
|
37
|
-
totalSize: buffer.length,
|
|
38
|
-
read: async (filePath) => (filePath === name ? buffer : null),
|
|
39
|
-
};
|
|
40
|
-
return artifact(sourcePath, 'html', source, name);
|
|
41
|
-
}
|
|
42
|
-
throw new ArtifactReadError('artifact_unsupported', `Unsupported artifact: ${sourcePath} (expected an HTML file, a ZIP file or a directory)`);
|
|
43
|
-
}
|
|
44
|
-
async function artifact(sourcePath, container, source, entry) {
|
|
45
|
-
const read = async (filePath) => {
|
|
46
|
-
const normalized = normalizeInnerPath(filePath);
|
|
47
|
-
return normalized === undefined ? null : source.read(normalized);
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
sourcePath,
|
|
51
|
-
container,
|
|
52
|
-
layout: source.files.length === 1 ? 'single-html' : 'multi-file',
|
|
53
|
-
entry,
|
|
54
|
-
files: source.files,
|
|
55
|
-
totalSize: source.totalSize,
|
|
56
|
-
digest: await contentDigest(source),
|
|
57
|
-
readBuffer: read,
|
|
58
|
-
readText: async (filePath) => (await read(filePath))?.toString('utf-8') ?? null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function resolveEntry(files, requested) {
|
|
62
|
-
const paths = new Set(files.map((file) => file.path));
|
|
63
|
-
if (requested !== undefined) {
|
|
64
|
-
const entry = normalizeInnerPath(requested);
|
|
65
|
-
if (entry === undefined || !HTML_FILE.test(entry))
|
|
66
|
-
throw new ArtifactReadError('artifact_entry_invalid', `Entry must be an HTML file inside the artifact: ${requested}`);
|
|
67
|
-
if (!paths.has(entry))
|
|
68
|
-
throw new ArtifactReadError('artifact_entry_missing', `Entry not found in artifact: ${entry}`);
|
|
69
|
-
return entry;
|
|
70
|
-
}
|
|
71
|
-
if (paths.has('index.html'))
|
|
72
|
-
return 'index.html';
|
|
73
|
-
const html = files.filter((file) => HTML_FILE.test(file.path)).map((file) => file.path);
|
|
74
|
-
if (html.length === 1)
|
|
75
|
-
return html[0];
|
|
76
|
-
if (html.length === 0)
|
|
77
|
-
throw new ArtifactReadError('artifact_entry_missing', 'The artifact contains no HTML entry');
|
|
78
|
-
throw new ArtifactReadError('artifact_entry_ambiguous', `The artifact has no index.html and several HTML files; choose one as the entry: ${html.slice(0, 10).join(', ')}`);
|
|
79
|
-
}
|
|
80
|
-
/** `/`-separated path inside the artifact, or undefined when it is absolute or leaves the artifact. */
|
|
81
|
-
function normalizeInnerPath(filePath) {
|
|
82
|
-
const value = filePath.replace(/\\/g, '/');
|
|
83
|
-
if (value.startsWith('/') || /^[a-zA-Z]:/.test(value))
|
|
84
|
-
return undefined;
|
|
85
|
-
const normalized = path.posix.normalize(value);
|
|
86
|
-
if (normalized === '..' || normalized.startsWith('../'))
|
|
87
|
-
return undefined;
|
|
88
|
-
return normalized.replace(/^\.\//, '');
|
|
89
|
-
}
|
|
90
|
-
function isZip(buffer) {
|
|
91
|
-
if (buffer.length < 4 || buffer[0] !== 0x50 || buffer[1] !== 0x4b)
|
|
92
|
-
return false;
|
|
93
|
-
const signature = buffer.readUInt32LE(0);
|
|
94
|
-
return signature === 0x04034b50 || signature === 0x06054b50;
|
|
95
|
-
}
|
|
96
|
-
function zipSource(buffer) {
|
|
97
|
-
const zip = new SimpleZipReader(buffer);
|
|
98
|
-
let entries;
|
|
99
|
-
try {
|
|
100
|
-
entries = zip.listEntries();
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
throw new ArtifactReadError('artifact_zip_invalid', error instanceof Error ? error.message : String(error));
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
files: entries
|
|
107
|
-
.filter((entry) => !entry.isDirectory)
|
|
108
|
-
.map((entry) => ({ path: entry.path, size: entry.uncompressedSize })),
|
|
109
|
-
totalSize: buffer.length,
|
|
110
|
-
read: async (filePath) => {
|
|
111
|
-
try {
|
|
112
|
-
return zip.readEntryBuffer(filePath);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
throw new ArtifactReadError('artifact_zip_invalid', error instanceof Error ? error.message : String(error));
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async function directorySource(dir) {
|
|
121
|
-
const files = (await listDirectoryEntries(dir))
|
|
122
|
-
.filter((entry) => !entry.isDirectory)
|
|
123
|
-
.map((entry) => ({ path: entry.path, size: entry.uncompressedSize }));
|
|
124
|
-
return {
|
|
125
|
-
files,
|
|
126
|
-
totalSize: files.reduce((sum, file) => sum + file.size, 0),
|
|
127
|
-
read: async (filePath) => fs.readFile(path.join(dir, filePath)).catch(() => null),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/** Hashes each file's path and content, so the same files give the same digest in any container. */
|
|
131
|
-
async function contentDigest(source) {
|
|
132
|
-
const digest = createHash('sha256');
|
|
133
|
-
for (const file of [...source.files].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))) {
|
|
134
|
-
const content = (await source.read(file.path)) ?? Buffer.alloc(0);
|
|
135
|
-
digest.update(file.path).update('\0').update(createHash('sha256').update(content).digest('hex')).update('\n');
|
|
136
|
-
}
|
|
137
|
-
return `sha256:${digest.digest('hex')}`;
|
|
138
|
-
}
|
|
139
|
-
/** Lists a directory like a ZIP central directory: files and `/`-terminated directories. */
|
|
140
|
-
export async function listDirectoryEntries(dir) {
|
|
141
|
-
const entries = [];
|
|
142
|
-
const walk = async (current) => {
|
|
143
|
-
const dirEntries = await fs.readdir(current, { withFileTypes: true });
|
|
144
|
-
for (const entry of dirEntries) {
|
|
145
|
-
const fullPath = path.join(current, entry.name);
|
|
146
|
-
const relative = path.relative(dir, fullPath).replace(/\\/g, '/');
|
|
147
|
-
if (entry.isDirectory()) {
|
|
148
|
-
entries.push({
|
|
149
|
-
path: `${relative}/`,
|
|
150
|
-
compressedSize: 0,
|
|
151
|
-
uncompressedSize: 0,
|
|
152
|
-
compressionMethod: 0,
|
|
153
|
-
isDirectory: true,
|
|
154
|
-
});
|
|
155
|
-
await walk(fullPath);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
const stat = await fs.stat(fullPath);
|
|
159
|
-
entries.push({
|
|
160
|
-
path: relative,
|
|
161
|
-
compressedSize: stat.size,
|
|
162
|
-
uncompressedSize: stat.size,
|
|
163
|
-
compressionMethod: 0,
|
|
164
|
-
isDirectory: false,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
await walk(dir);
|
|
170
|
-
return entries;
|
|
171
|
-
}
|
|
172
|
-
export async function directorySize(dir) {
|
|
173
|
-
let total = 0;
|
|
174
|
-
const walk = async (current) => {
|
|
175
|
-
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
176
|
-
for (const entry of entries) {
|
|
177
|
-
const fullPath = path.join(current, entry.name);
|
|
178
|
-
if (entry.isDirectory()) {
|
|
179
|
-
await walk(fullPath);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
total += (await fs.stat(fullPath)).size;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
await walk(dir);
|
|
187
|
-
return total;
|
|
188
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Platform } from '../types.js';
|
|
2
|
-
import type { BrowserDriver, PlayableArtifact, QaStageReport, RuntimeViewport, ValidationResult } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* `runtime-load` rules: open the artifact in a headless browser without playing it. All network
|
|
5
|
-
* access outside the artifact is blocked, store-opening calls are recorded instead of followed,
|
|
6
|
-
* and the CTA chain is exercised through whichever CTA entry the artifact has: adsdk's
|
|
7
|
-
* `window.PlayableSDK`, or the platform-injected CTA adapter's `window.PlayCraftCTA`. Either is
|
|
8
|
-
* accepted; what matters is that the CTA reaches the channel's store API.
|
|
9
|
-
*/
|
|
10
|
-
export declare const RUNTIME_LOAD_RULE_IDS: {
|
|
11
|
-
readonly pageLoads: "common.runtime.page.loads";
|
|
12
|
-
readonly requests: "common.runtime.requests.resolved";
|
|
13
|
-
readonly csp: "common.runtime.csp.clean";
|
|
14
|
-
readonly errors: "common.runtime.errors.none";
|
|
15
|
-
readonly firstFrame: "common.runtime.first-frame.content";
|
|
16
|
-
readonly ctaEntry: "common.runtime.cta.entry";
|
|
17
|
-
readonly startSignal: "common.runtime.start-signal.sent";
|
|
18
|
-
readonly noAutoRedirect: "common.runtime.redirect.none-on-load";
|
|
19
|
-
readonly ctaRouted: "common.runtime.cta.routed";
|
|
20
|
-
readonly ctaStoreUrl: "common.runtime.cta.store-url";
|
|
21
|
-
readonly viewportCanvasFit: "common.runtime.viewport.canvas-fit";
|
|
22
|
-
readonly viewportOverflow: "common.runtime.viewport.no-overflow";
|
|
23
|
-
readonly viewportErrors: "common.runtime.viewport.errors";
|
|
24
|
-
readonly viewportContent: "common.runtime.viewport.content";
|
|
25
|
-
};
|
|
26
|
-
export interface RuntimeViewportPreset {
|
|
27
|
-
/** Shown in evidence, e.g. `iphone16 portrait`. */
|
|
28
|
-
name: string;
|
|
29
|
-
viewport: RuntimeViewport;
|
|
30
|
-
}
|
|
31
|
-
export interface RuntimeLoadOptions {
|
|
32
|
-
driver: BrowserDriver;
|
|
33
|
-
profile: Platform;
|
|
34
|
-
/**
|
|
35
|
-
* Viewports to open the artifact in. The first one also runs the CTA checks. Callers pass
|
|
36
|
-
* presets from `@playcraft/common/preview/preview-devices`; default is one phone portrait.
|
|
37
|
-
*/
|
|
38
|
-
viewports?: RuntimeViewportPreset[];
|
|
39
|
-
/** Wait after the load event before inspecting the page. Default 1500 ms. */
|
|
40
|
-
settleMs?: number;
|
|
41
|
-
/** Navigation timeout. Default 15000 ms. */
|
|
42
|
-
timeoutMs?: number;
|
|
43
|
-
}
|
|
44
|
-
export declare const RUNTIME_ORIGIN = "http://artifact.playcraft-qa.test";
|
|
45
|
-
/** Same-origin artifact files and inline data only; no network, workers or frames. */
|
|
46
|
-
export declare const RUNTIME_CSP: string;
|
|
47
|
-
export declare function channelGlobalsFor(profile: Platform): string[];
|
|
48
|
-
/** `runtime-load` stage: opens the artifact in a headless browser. Needs the artifact and a driver. */
|
|
49
|
-
export declare function runRuntimeLoadStage(artifact: PlayableArtifact, options: RuntimeLoadOptions): Promise<QaStageReport>;
|
|
50
|
-
export declare function runRuntimeLoadChecks(artifact: PlayableArtifact, options: RuntimeLoadOptions): Promise<ValidationResult[]>;
|
|
51
|
-
/**
|
|
52
|
-
* Script injected before any page script during runtime QA. It records, without side effects:
|
|
53
|
-
* store-opening calls (channel SDK APIs, `window.open`, `postMessage('download')`), adsdk events
|
|
54
|
-
* (via `window.PlayableSDK.on`), and CSP violations. Results live on `window.__PLAYCRAFT_QA__`.
|
|
55
|
-
*
|
|
56
|
-
* adsdk picks the channel from build-time constants (`AD_NETWORK`, `AD_PROTOCOL`) and only checks
|
|
57
|
-
* that the channel's global exists. The platform CTA adapter instead picks the channel by which
|
|
58
|
-
* global exists, so only the profile's own channel globals are stubbed (`channelGlobalsFor`).
|
|
59
|
-
* Stubs are defined only when the page has none, matching the platform fallbacks in
|
|
60
|
-
* `packages/build/src/platforms/*.ts`.
|
|
61
|
-
*/
|
|
62
|
-
/** adsdk events the probe subscribes to. */
|
|
63
|
-
export declare const ADSDK_PROBE_EVENTS: readonly ["playcraftInit", "playcraftReady", "playcraftStart", "playcraftInteractive", "playcraftFinish", "playcraftInstall"];
|
|
64
|
-
export interface RuntimeProbeOptions {
|
|
65
|
-
/** Channel SDK globals to install recording stubs for; see `channelGlobalsFor`. */
|
|
66
|
-
channelGlobals: string[];
|
|
67
|
-
}
|
|
68
|
-
export interface RuntimeProbeCall {
|
|
69
|
-
api: string;
|
|
70
|
-
url?: string;
|
|
71
|
-
at: number;
|
|
72
|
-
}
|
|
73
|
-
export interface RuntimeProbeState {
|
|
74
|
-
calls: RuntimeProbeCall[];
|
|
75
|
-
events: Array<{
|
|
76
|
-
name: string;
|
|
77
|
-
at: number;
|
|
78
|
-
}>;
|
|
79
|
-
csp: Array<{
|
|
80
|
-
blockedURI: string;
|
|
81
|
-
violatedDirective: string;
|
|
82
|
-
}>;
|
|
83
|
-
sdk: boolean;
|
|
84
|
-
/** The platform CTA adapter (`window.PlayCraftCTA.jump`) is present. */
|
|
85
|
-
adapter: boolean;
|
|
86
|
-
/** The export wrote store links for the CTA adapter (`window.__PLAYCRAFT_STORE_URLS__`). */
|
|
87
|
-
storeUrls: boolean;
|
|
88
|
-
}
|
|
89
|
-
export declare function buildRuntimeProbeScript(options: RuntimeProbeOptions): string;
|