@playcraft/build 0.2.14 → 0.2.15-test-a

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.
Files changed (122) hide show
  1. package/dist/audio-source-files.d.ts +5 -0
  2. package/dist/audio-source-files.js +135 -0
  3. package/dist/base-builder.js +41 -2
  4. package/dist/delivery/agent-build-runner.d.ts +44 -0
  5. package/dist/delivery/agent-build-runner.js +365 -0
  6. package/dist/delivery/agent-build-source.d.ts +8 -0
  7. package/dist/delivery/agent-build-source.js +25 -0
  8. package/dist/delivery/artifact-descriptor.d.ts +31 -0
  9. package/dist/delivery/artifact-descriptor.js +237 -0
  10. package/dist/delivery/artifact-package.d.ts +43 -0
  11. package/dist/delivery/artifact-package.js +283 -0
  12. package/dist/delivery/build-plan.d.ts +4 -0
  13. package/dist/delivery/build-plan.js +189 -0
  14. package/dist/delivery/build-plan.types.d.ts +51 -0
  15. package/dist/delivery/build-plan.types.js +1 -0
  16. package/dist/delivery/command-isolation.d.ts +21 -0
  17. package/dist/delivery/command-isolation.js +327 -0
  18. package/dist/delivery/commands.d.ts +5 -0
  19. package/dist/delivery/commands.js +146 -0
  20. package/dist/delivery/files.d.ts +9 -0
  21. package/dist/delivery/files.js +144 -0
  22. package/dist/delivery/git-source-fingerprint.d.ts +2 -0
  23. package/dist/delivery/git-source-fingerprint.js +58 -0
  24. package/dist/delivery/isolated-source.d.ts +5 -0
  25. package/dist/delivery/isolated-source.js +131 -0
  26. package/dist/delivery/output-publication.d.ts +21 -0
  27. package/dist/delivery/output-publication.js +444 -0
  28. package/dist/delivery/project-delivery.d.ts +6 -0
  29. package/dist/delivery/project-delivery.js +287 -0
  30. package/dist/delivery/recipe-build-plan.d.ts +4 -0
  31. package/dist/delivery/recipe-build-plan.js +53 -0
  32. package/dist/delivery/recipe.d.ts +20 -0
  33. package/dist/delivery/recipe.js +211 -0
  34. package/dist/delivery/safe-path.d.ts +2 -0
  35. package/dist/delivery/safe-path.js +18 -0
  36. package/dist/delivery/types.d.ts +76 -0
  37. package/dist/delivery/types.js +1 -0
  38. package/dist/engines/engine-detector.js +4 -0
  39. package/dist/engines/generic-adapter.js +14 -19
  40. package/dist/engines/playable-scripts-adapter.js +2 -5
  41. package/dist/index.d.ts +21 -4
  42. package/dist/index.js +12 -2
  43. package/dist/platforms/adikteev.js +1 -0
  44. package/dist/platforms/applovin.js +1 -0
  45. package/dist/platforms/base.d.ts +4 -0
  46. package/dist/platforms/base.js +25 -6
  47. package/dist/platforms/bigo.js +1 -0
  48. package/dist/platforms/facebook.js +1 -0
  49. package/dist/platforms/google.js +1 -0
  50. package/dist/platforms/inmobi.js +1 -0
  51. package/dist/platforms/ironsource.js +1 -0
  52. package/dist/platforms/liftoff.js +1 -0
  53. package/dist/platforms/mintegral.js +1 -0
  54. package/dist/platforms/moloco.js +1 -0
  55. package/dist/platforms/playcraft.js +1 -0
  56. package/dist/platforms/remerge.js +1 -0
  57. package/dist/platforms/snapchat.js +1 -0
  58. package/dist/platforms/tiktok.js +1 -0
  59. package/dist/platforms/unity.js +1 -0
  60. package/dist/production-animation-presence.d.ts +2 -0
  61. package/dist/production-animation-presence.js +146 -0
  62. package/dist/production-inputs.d.ts +30 -0
  63. package/dist/production-inputs.js +262 -0
  64. package/dist/production-source-paths.d.ts +5 -0
  65. package/dist/production-source-paths.js +27 -0
  66. package/dist/redirect-policy.d.ts +23 -0
  67. package/dist/redirect-policy.js +25 -0
  68. package/dist/types.d.ts +10 -2
  69. package/dist/validation/artifact-qa.d.ts +36 -0
  70. package/dist/validation/artifact-qa.js +263 -0
  71. package/dist/validation/artifact-rules.d.ts +39 -0
  72. package/dist/validation/artifact-rules.js +451 -0
  73. package/dist/validation/artifact.d.ts +14 -0
  74. package/dist/validation/artifact.js +188 -0
  75. package/dist/validation/html-validator.d.ts +5 -0
  76. package/dist/validation/html-validator.js +19 -17
  77. package/dist/validation/index.d.ts +5 -0
  78. package/dist/validation/index.js +5 -0
  79. package/dist/validation/package-validator.d.ts +2 -0
  80. package/dist/validation/package-validator.js +25 -64
  81. package/dist/validation/playwright-driver.d.ts +37 -0
  82. package/dist/validation/playwright-driver.js +302 -0
  83. package/dist/validation/profiles.d.ts +13 -1
  84. package/dist/validation/profiles.js +27 -0
  85. package/dist/validation/runtime-cover.d.ts +32 -0
  86. package/dist/validation/runtime-cover.js +120 -0
  87. package/dist/validation/runtime-load.d.ts +141 -0
  88. package/dist/validation/runtime-load.js +812 -0
  89. package/dist/validation/source-scanner.d.ts +11 -0
  90. package/dist/validation/source-scanner.js +32 -2
  91. package/dist/validation/types.d.ts +201 -2
  92. package/dist/validation/types.js +1 -1
  93. package/dist/validation/validation-runner.d.ts +22 -2
  94. package/dist/validation/validation-runner.js +64 -3
  95. package/dist/validation/zip-reader.d.ts +7 -0
  96. package/dist/validation/zip-reader.js +159 -26
  97. package/dist/vite/config-builder-generic.d.ts +3 -1
  98. package/dist/vite/config-builder-generic.js +9 -7
  99. package/dist/vite/config-builder.js +1 -1
  100. package/dist/vite/plugin-platform.js +16 -30
  101. package/dist/vite/plugin-source-builder.d.ts +2 -14
  102. package/dist/vite/plugin-source-builder.js +61 -997
  103. package/dist/vite/source-builder-asset-paths.d.ts +25 -0
  104. package/dist/vite/source-builder-asset-paths.js +154 -0
  105. package/dist/vite/source-builder-esm.d.ts +7 -0
  106. package/dist/vite/source-builder-esm.js +877 -0
  107. package/dist/vite/source-builder-types.d.ts +14 -0
  108. package/dist/vite/source-builder-types.js +1 -0
  109. package/dist/vite/workspace.d.ts +6 -0
  110. package/dist/vite/workspace.js +41 -0
  111. package/dist/vite-builder.d.ts +4 -5
  112. package/dist/vite-builder.js +33 -34
  113. package/dist/workspace-css-imports.d.ts +2 -0
  114. package/dist/workspace-css-imports.js +139 -0
  115. package/dist/workspace-model-source.d.ts +14 -0
  116. package/dist/workspace-model-source.js +184 -0
  117. package/dist/workspace-public-imports.d.ts +11 -0
  118. package/dist/workspace-public-imports.js +232 -0
  119. package/dist/workspace-public-source.d.ts +15 -0
  120. package/dist/workspace-public-source.js +564 -0
  121. package/package.json +30 -4
  122. package/templates/patches/playcraft-redirect-policy.js +115 -0
@@ -0,0 +1,120 @@
1
+ import sharp from 'sharp';
2
+ import { RUNTIME_ORIGIN } from './runtime-load.js';
3
+ const IPHONE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
4
+ const POLL_INTERVAL_MS = 500;
5
+ const READY_STREAK = 3;
6
+ const SETTLE_MS = 500;
7
+ /** Cover content thresholds, the same as the workspace cover capture. */
8
+ const MIN_STDDEV = 15;
9
+ const MAX_FLAT_RATIO = 0.88;
10
+ const CONTENT_TYPES = {
11
+ html: 'text/html; charset=utf-8',
12
+ htm: 'text/html; charset=utf-8',
13
+ js: 'text/javascript; charset=utf-8',
14
+ mjs: 'text/javascript; charset=utf-8',
15
+ css: 'text/css; charset=utf-8',
16
+ json: 'application/json',
17
+ svg: 'image/svg+xml',
18
+ png: 'image/png',
19
+ jpg: 'image/jpeg',
20
+ jpeg: 'image/jpeg',
21
+ webp: 'image/webp',
22
+ gif: 'image/gif',
23
+ mp3: 'audio/mpeg',
24
+ ogg: 'audio/ogg',
25
+ wav: 'audio/wav',
26
+ woff: 'font/woff',
27
+ woff2: 'font/woff2',
28
+ ttf: 'font/ttf',
29
+ wasm: 'application/wasm',
30
+ };
31
+ /** Returns the cover frame, or `undefined` when the page does not open. */
32
+ export async function captureCoverFrame(artifact, options) {
33
+ const startedAt = Date.now();
34
+ const page = await options.driver.open({
35
+ origin: RUNTIME_ORIGIN,
36
+ entryPath: artifact.entry,
37
+ viewport: {
38
+ width: options.width,
39
+ height: options.height,
40
+ deviceScaleFactor: 1,
41
+ isMobile: true,
42
+ hasTouch: true,
43
+ },
44
+ userAgent: IPHONE_USER_AGENT,
45
+ locale: 'en-US',
46
+ // The cover shows the game as players see it: no probe and no extra policy on the page.
47
+ initScript: '',
48
+ contentSecurityPolicy: '',
49
+ timeoutMs: options.timeoutMs ?? 20000,
50
+ resolve: async (pathname) => {
51
+ const relativePath = pathname.replace(/^\/+/, '');
52
+ const body = await artifact.readBuffer(relativePath);
53
+ if (!body)
54
+ return null;
55
+ const extension = relativePath.split('.').pop()?.toLowerCase() ?? '';
56
+ return { body, contentType: CONTENT_TYPES[extension] ?? 'application/octet-stream' };
57
+ },
58
+ });
59
+ try {
60
+ if (!page.loaded)
61
+ return undefined;
62
+ await page.wait(options.minRenderMs ?? 3000);
63
+ let contentReady = false;
64
+ let streak = 0;
65
+ const deadline = Date.now() + (options.contentWaitMs ?? 20000);
66
+ while (Date.now() < deadline) {
67
+ const frame = await page.screenshot().catch(() => undefined);
68
+ streak = frame && (await hasVisibleContent(frame)) ? streak + 1 : 0;
69
+ if (streak >= READY_STREAK) {
70
+ contentReady = true;
71
+ break;
72
+ }
73
+ await page.wait(POLL_INTERVAL_MS);
74
+ }
75
+ await page.wait(SETTLE_MS);
76
+ const png = await page.screenshot();
77
+ return {
78
+ png,
79
+ width: options.width,
80
+ height: options.height,
81
+ contentReady,
82
+ waitedMs: Date.now() - startedAt,
83
+ };
84
+ }
85
+ finally {
86
+ await page.close();
87
+ }
88
+ }
89
+ /** Not a flat, mostly white or mostly black frame, judged on a 48 px wide grey thumbnail. */
90
+ export async function hasVisibleContent(frame) {
91
+ try {
92
+ const { data, info } = await sharp(frame)
93
+ .resize({ width: 48 })
94
+ .greyscale()
95
+ .raw()
96
+ .toBuffer({ resolveWithObject: true });
97
+ const count = info.width * info.height;
98
+ if (count === 0)
99
+ return false;
100
+ let sum = 0;
101
+ let squares = 0;
102
+ let white = 0;
103
+ let black = 0;
104
+ for (let index = 0; index < count; index++) {
105
+ const lum = data[index * info.channels];
106
+ sum += lum;
107
+ squares += lum * lum;
108
+ if (lum >= 245)
109
+ white++;
110
+ if (lum <= 10)
111
+ black++;
112
+ }
113
+ const mean = sum / count;
114
+ const stddev = Math.sqrt(Math.max(0, squares / count - mean * mean));
115
+ return stddev >= MIN_STDDEV && white / count < MAX_FLAT_RATIO && black / count < MAX_FLAT_RATIO;
116
+ }
117
+ catch {
118
+ return false;
119
+ }
120
+ }
@@ -0,0 +1,141 @@
1
+ import type { Platform } from '../types.js';
2
+ import type { BrowserDriver, PlayableArtifact, 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
+ readonly firstTap: "common.runtime.interaction.first-tap";
26
+ readonly webgl: "common.runtime.environment.webgl";
27
+ };
28
+ export type RuntimeLoadRuleId = (typeof RUNTIME_LOAD_RULE_IDS)[keyof typeof RUNTIME_LOAD_RULE_IDS];
29
+ export interface RuntimeViewportPreset {
30
+ /** Shown in evidence, e.g. `iphone16 portrait`. */
31
+ name: string;
32
+ viewport: RuntimeViewport;
33
+ }
34
+ export interface RuntimeLoadOptions {
35
+ driver: BrowserDriver;
36
+ profile: Platform;
37
+ /**
38
+ * Viewports to open the artifact in. The first one also runs the CTA checks. Callers pass
39
+ * presets from `@playcraft/common/preview/preview-devices`; default is one phone portrait.
40
+ */
41
+ viewports?: RuntimeViewportPreset[];
42
+ /** Wait after the load event before inspecting the page. Default 1500 ms. */
43
+ settleMs?: number;
44
+ /** Navigation timeout. Default 15000 ms. */
45
+ timeoutMs?: number;
46
+ /**
47
+ * Receives what the main viewport recorded, with page exceptions kept apart from other errors,
48
+ * so a caller such as export validation can apply its own policy and keep the evidence.
49
+ */
50
+ onDiagnostics?: (diagnostics: RuntimeLoadDiagnostics) => void;
51
+ }
52
+ /** Raw observations of the main viewport, for callers that keep their own report. */
53
+ export interface RuntimeLoadDiagnostics {
54
+ viewport: RuntimeViewport;
55
+ loaded: boolean;
56
+ loadError?: string;
57
+ pageErrors: Array<{
58
+ message: string;
59
+ stack?: string;
60
+ }>;
61
+ rejections: Array<{
62
+ message: string;
63
+ stack?: string;
64
+ }>;
65
+ consoleErrors: string[];
66
+ failedRequests: Array<{
67
+ url: string;
68
+ reason: string;
69
+ }>;
70
+ blockedRequests: string[];
71
+ containerRequests: string[];
72
+ crashed: boolean;
73
+ /** `false` when the browser offered no WebGL context. */
74
+ webgl?: boolean;
75
+ /** Whether the first-tap check ran. */
76
+ tapped: boolean;
77
+ /** Errors raised after the first tap. */
78
+ afterTapErrors: string[];
79
+ screenshot?: Buffer;
80
+ }
81
+ export declare const RUNTIME_ORIGIN = "http://artifact.playcraft-qa.test";
82
+ /** Same-origin artifact files and inline data only; no network, workers or frames. */
83
+ export declare const RUNTIME_CSP: string;
84
+ /**
85
+ * A channel container lets the ad SDK report to its servers, so writes may connect out; the driver
86
+ * answers them locally (`containerTelemetry`), and remote reads are still blocked and reported.
87
+ */
88
+ export declare const RUNTIME_CONTAINER_CSP: string;
89
+ export declare function channelGlobalsFor(profile: Platform): string[];
90
+ /** Names of the viewports `runRuntimeLoadChecks` opens, for reports. */
91
+ export declare function runtimeViewportNames(viewports?: RuntimeViewportPreset[]): string[];
92
+ /**
93
+ * Opens the artifact in a headless browser and returns every `runtime-load` result. When the page
94
+ * does not load, only the page-load result is returned.
95
+ */
96
+ export declare function runRuntimeLoadChecks(artifact: PlayableArtifact, options: RuntimeLoadOptions): Promise<ValidationResult[]>;
97
+ /**
98
+ * Script injected before any page script during runtime QA. It records, without side effects:
99
+ * store-opening calls (channel SDK APIs, `window.open`, `postMessage('download')`), adsdk events
100
+ * (via `window.PlayableSDK.on`), and CSP violations. Results live on `window.__PLAYCRAFT_QA__`.
101
+ *
102
+ * adsdk picks the channel from build-time constants (`AD_NETWORK`, `AD_PROTOCOL`) and only checks
103
+ * that the channel's global exists. The platform CTA adapter instead picks the channel by which
104
+ * global exists, so only the profile's own channel globals are stubbed (`channelGlobalsFor`).
105
+ * Stubs are defined only when the page has none, matching the platform fallbacks in
106
+ * `packages/build/src/platforms/*.ts`.
107
+ */
108
+ /** adsdk events the probe subscribes to. */
109
+ export declare const ADSDK_PROBE_EVENTS: readonly ["playcraftInit", "playcraftReady", "playcraftStart", "playcraftInteractive", "playcraftFinish", "playcraftInstall"];
110
+ export interface RuntimeProbeOptions {
111
+ /** Channel SDK globals to install recording stubs for; see `channelGlobalsFor`. */
112
+ channelGlobals: string[];
113
+ }
114
+ export interface RuntimeProbeCall {
115
+ api: string;
116
+ url?: string;
117
+ at: number;
118
+ }
119
+ export interface RuntimeProbeState {
120
+ calls: RuntimeProbeCall[];
121
+ events: Array<{
122
+ name: string;
123
+ at: number;
124
+ }>;
125
+ csp: Array<{
126
+ blockedURI: string;
127
+ violatedDirective: string;
128
+ }>;
129
+ sdk: boolean;
130
+ /** The platform CTA adapter (`window.PlayCraftCTA.jump`) is present. */
131
+ adapter: boolean;
132
+ /** The export wrote store links for the CTA adapter (`window.__PLAYCRAFT_STORE_URLS__`). */
133
+ storeUrls: boolean;
134
+ /** Messages of unhandled Promise rejections. */
135
+ rejections?: string[];
136
+ /** Stacks of those rejections, in the same order; empty when the reason was not an Error. */
137
+ rejectionStacks?: string[];
138
+ /** Host-app bridge addresses (`bytedance://`, `nativeapp://`) a frame tried to open; stopped. */
139
+ bridge?: string[];
140
+ }
141
+ export declare function buildRuntimeProbeScript(options: RuntimeProbeOptions): string;