@playcraft/build 0.1.87 → 0.1.88

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.
@@ -1,4 +1,8 @@
1
1
  export * from './types.js';
2
+ export * from './artifact.js';
3
+ export * from './artifact-rules.js';
4
+ export * from './artifact-qa.js';
5
+ export * from './runtime-load.js';
2
6
  export * from './profiles.js';
3
7
  export * from './html-validator.js';
4
8
  export * from './package-validator.js';
@@ -2,6 +2,7 @@ import fs from 'fs/promises';
2
2
  import fsSync from 'fs';
3
3
  import path from 'path';
4
4
  import { getChannelRuleProfile } from './profiles.js';
5
+ import { directorySize, listDirectoryEntries } from './artifact.js';
5
6
  import { SimpleZipReader } from './zip-reader.js';
6
7
  const FIVE_MB = 5 * 1024 * 1024;
7
8
  export async function validateDeliveryPackage(context, profile = getChannelRuleProfile(context.channel)) {
@@ -65,12 +66,12 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
65
66
  async function readPackageInventory(packagePath) {
66
67
  const stat = await fs.stat(packagePath);
67
68
  if (stat.isDirectory()) {
68
- const entries = await readDirectoryEntries(packagePath);
69
+ const entries = await listDirectoryEntries(packagePath);
69
70
  return {
70
71
  packagePath,
71
72
  entries,
72
73
  readText: (entryPath) => readTextFromDirectorySyncUnsupported(packagePath, entryPath),
73
- size: await calculateDirectorySize(packagePath),
74
+ size: await directorySize(packagePath),
74
75
  };
75
76
  }
76
77
  const buffer = await fs.readFile(packagePath);
@@ -82,38 +83,6 @@ async function readPackageInventory(packagePath) {
82
83
  size: buffer.length,
83
84
  };
84
85
  }
85
- async function readDirectoryEntries(dir) {
86
- const entries = [];
87
- const walk = async (current) => {
88
- const dirEntries = await fs.readdir(current, { withFileTypes: true });
89
- for (const entry of dirEntries) {
90
- const fullPath = path.join(current, entry.name);
91
- const relative = path.relative(dir, fullPath).replace(/\\/g, '/');
92
- if (entry.isDirectory()) {
93
- entries.push({
94
- path: `${relative}/`,
95
- compressedSize: 0,
96
- uncompressedSize: 0,
97
- compressionMethod: 0,
98
- isDirectory: true,
99
- });
100
- await walk(fullPath);
101
- }
102
- else {
103
- const stat = await fs.stat(fullPath);
104
- entries.push({
105
- path: relative,
106
- compressedSize: stat.size,
107
- uncompressedSize: stat.size,
108
- compressionMethod: 0,
109
- isDirectory: false,
110
- });
111
- }
112
- }
113
- };
114
- await walk(dir);
115
- return entries;
116
- }
117
86
  function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
118
87
  const filePath = path.join(_packagePath, _entryPath);
119
88
  try {
@@ -123,23 +92,6 @@ function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
123
92
  return null;
124
93
  }
125
94
  }
126
- async function calculateDirectorySize(dir) {
127
- let total = 0;
128
- const walk = async (current) => {
129
- const entries = await fs.readdir(current, { withFileTypes: true });
130
- for (const entry of entries) {
131
- const fullPath = path.join(current, entry.name);
132
- if (entry.isDirectory()) {
133
- await walk(fullPath);
134
- }
135
- else {
136
- total += (await fs.stat(fullPath)).size;
137
- }
138
- }
139
- };
140
- await walk(dir);
141
- return total;
142
- }
143
95
  function validateZipLikePackage(channel, inventory) {
144
96
  const paths = new Set(inventory.entries.map((entry) => entry.path));
145
97
  return [
@@ -0,0 +1,89 @@
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;