@innovatorved/code-lab 0.1.5 → 0.1.7
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/ARCHITECTURE.md +1 -1
- package/README.md +1 -1
- package/dist/code-lab.d.ts +3 -1
- package/dist/code-lab.esm.js +811 -74
- package/dist/code-lab.js +801 -73
- package/dist/extensions/guided-lab.esm.js +3 -0
- package/dist/extensions/guided-lab.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +56 -8
- package/dist/runtime.d.ts +7 -27
- package/dist/runtime.esm.js +458 -16
- package/dist/runtime.js +415 -5
- package/dist/schemas.d.ts +10 -1
- package/dist/schemas.esm.js +4194 -0
- package/dist/schemas.js +4210 -0
- package/dist/shell.d.ts +18 -47
- package/dist/shell.esm.js +139 -29
- package/dist/shell.js +139 -29
- package/dist/terminal.d.ts +11 -87
- package/dist/terminal.esm.js +10 -2
- package/dist/terminal.js +3 -1
- package/package.json +12 -5
- package/src/index.ts +1 -1
- package/src/preview-sw.js +56 -8
- package/src/runtime.ts +478 -79
- package/src/schemas.ts +4 -1
- package/src/shell.ts +412 -359
- package/src/terminal.ts +885 -919
- package/src/workbench.ts +244 -40
- package/src/runtime.js +0 -7821
- package/src/shell.js +0 -7166
- package/src/terminal.js +0 -1046
- package/src/workbench.js +0 -7353
|
@@ -4157,6 +4157,9 @@ var WorkbenchOptionsSchema = external_exports.object({
|
|
|
4157
4157
|
testFile: external_exports.string().optional(),
|
|
4158
4158
|
backLabel: external_exports.string().default("Back"),
|
|
4159
4159
|
monacoUrl: external_exports.string().optional(),
|
|
4160
|
+
previewOrigin: external_exports.string().optional(),
|
|
4161
|
+
logger: external_exports.any().optional(),
|
|
4162
|
+
debug: external_exports.boolean().optional(),
|
|
4160
4163
|
onClose: external_exports.function().returns(external_exports.void()).optional(),
|
|
4161
4164
|
onRun: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional(),
|
|
4162
4165
|
onTestResult: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional(),
|
|
@@ -4177,6 +4177,9 @@ var CodeLabGuidedLab = (() => {
|
|
|
4177
4177
|
testFile: external_exports.string().optional(),
|
|
4178
4178
|
backLabel: external_exports.string().default("Back"),
|
|
4179
4179
|
monacoUrl: external_exports.string().optional(),
|
|
4180
|
+
previewOrigin: external_exports.string().optional(),
|
|
4181
|
+
logger: external_exports.any().optional(),
|
|
4182
|
+
debug: external_exports.boolean().optional(),
|
|
4180
4183
|
onClose: external_exports.function().returns(external_exports.void()).optional(),
|
|
4181
4184
|
onRun: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional(),
|
|
4182
4185
|
onTestResult: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional(),
|
package/dist/index.d.ts
CHANGED
package/dist/preview-sw.js
CHANGED
|
@@ -17,6 +17,49 @@
|
|
|
17
17
|
const PREVIEW_PREFIX = '/__preview/';
|
|
18
18
|
const DISPATCH_TIMEOUT_MS = 15000;
|
|
19
19
|
|
|
20
|
+
// Content-Security-Policy applied to every HTML preview response.
|
|
21
|
+
//
|
|
22
|
+
// The preview is untrusted user code. Inline/eval are allowed because previews
|
|
23
|
+
// are built from arbitrary user source, but network access is restricted to
|
|
24
|
+
// the preview origin plus data:/blob: so a preview cannot exfiltrate host data
|
|
25
|
+
// to a third party. Keep this string in sync with PREVIEW_CSP in workbench.js.
|
|
26
|
+
const PREVIEW_CSP = [
|
|
27
|
+
"default-src 'self' data: blob:",
|
|
28
|
+
"base-uri 'self'",
|
|
29
|
+
"object-src 'none'",
|
|
30
|
+
"script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:",
|
|
31
|
+
"style-src 'self' 'unsafe-inline'",
|
|
32
|
+
"img-src 'self' data: blob:",
|
|
33
|
+
"font-src 'self' data:",
|
|
34
|
+
"connect-src 'self' data: blob:",
|
|
35
|
+
"media-src 'self' data: blob:",
|
|
36
|
+
"worker-src 'self' blob:",
|
|
37
|
+
"frame-src 'self' data: blob:",
|
|
38
|
+
"form-action 'self'",
|
|
39
|
+
"frame-ancestors 'self'"
|
|
40
|
+
].join('; ');
|
|
41
|
+
|
|
42
|
+
function injectPreviewHead(html, port) {
|
|
43
|
+
const tags = [];
|
|
44
|
+
if (!/<meta[^>]+http-equiv=["']?content-security-policy/i.test(html)) {
|
|
45
|
+
tags.push(`<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">`);
|
|
46
|
+
}
|
|
47
|
+
if (!/<base\b/i.test(html)) {
|
|
48
|
+
tags.push(`<base href="${PREVIEW_PREFIX}${port}/">`);
|
|
49
|
+
}
|
|
50
|
+
if (tags.length === 0) return html;
|
|
51
|
+
|
|
52
|
+
const injection = tags.join('');
|
|
53
|
+
if (/<head\b[^>]*>/i.test(html)) {
|
|
54
|
+
return html.replace(/<head\b[^>]*>/i, (match) => match + injection);
|
|
55
|
+
}
|
|
56
|
+
if (/<html\b[^>]*>/i.test(html)) {
|
|
57
|
+
return html.replace(/<html\b[^>]*>/i, (match) => `${match}<head>${injection}</head>`);
|
|
58
|
+
}
|
|
59
|
+
return `<head>${injection}</head>${html}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
20
63
|
self.addEventListener('install', () => {
|
|
21
64
|
self.skipWaiting();
|
|
22
65
|
});
|
|
@@ -32,12 +75,18 @@ function parsePreviewPath(pathname) {
|
|
|
32
75
|
}
|
|
33
76
|
|
|
34
77
|
function previewErrorResponse(status, title, message) {
|
|
35
|
-
const body = `<!doctype html><meta charset="utf-8"
|
|
78
|
+
const body = `<!doctype html><meta charset="utf-8">` +
|
|
79
|
+
`<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">` +
|
|
80
|
+
`<title>${title}</title>` +
|
|
36
81
|
`<body style="font-family:system-ui,-apple-system,sans-serif;padding:32px;color:#666;background:#0a0a0a">` +
|
|
37
82
|
`<h1 style="color:#e5e5e5;font-size:18px">${title}</h1><p>${message}</p></body>`;
|
|
38
83
|
return new Response(body, {
|
|
39
84
|
status,
|
|
40
|
-
headers: {
|
|
85
|
+
headers: {
|
|
86
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
87
|
+
'Content-Security-Policy': PREVIEW_CSP,
|
|
88
|
+
'X-Content-Type-Options': 'nosniff'
|
|
89
|
+
}
|
|
41
90
|
});
|
|
42
91
|
}
|
|
43
92
|
|
|
@@ -102,13 +151,12 @@ async function proxyVirtualRequest(event, port, targetPath) {
|
|
|
102
151
|
const responseHeaders = new Headers((response && response.headers) || {});
|
|
103
152
|
const contentType = responseHeaders.get('content-type') || '';
|
|
104
153
|
|
|
105
|
-
// Inject a <base> so relative asset URLs in HTML responses resolve
|
|
106
|
-
// `/__preview/:port/` namespace rather than the host document root.
|
|
154
|
+
// Inject a CSP and a <base> so relative asset URLs in HTML responses resolve
|
|
155
|
+
// under the `/__preview/:port/` namespace rather than the host document root.
|
|
107
156
|
if (/text\/html/i.test(contentType) && typeof responseBody === 'string') {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
157
|
+
responseBody = injectPreviewHead(responseBody, port);
|
|
158
|
+
responseHeaders.set('Content-Security-Policy', PREVIEW_CSP);
|
|
159
|
+
responseHeaders.set('X-Content-Type-Options', 'nosniff');
|
|
112
160
|
}
|
|
113
161
|
|
|
114
162
|
return new Response(responseBody, {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export interface RuntimeExecutionResult {
|
|
3
|
-
ok: boolean;
|
|
4
|
-
exitCode: number;
|
|
5
|
-
durationMs: number;
|
|
6
|
-
stdout: string;
|
|
7
|
-
stderr: string;
|
|
8
|
-
testResults: any[];
|
|
9
|
-
fsSnapshot: any[];
|
|
10
|
-
httpTrace: any[];
|
|
11
|
-
error?: {
|
|
12
|
-
message: string;
|
|
13
|
-
stack?: string;
|
|
14
|
-
};
|
|
15
|
-
outputTruncated?: boolean;
|
|
16
|
-
replValue?: any;
|
|
17
|
-
cancelled?: boolean;
|
|
18
|
-
testSummary?: {
|
|
19
|
-
total: number;
|
|
20
|
-
passed: number;
|
|
21
|
-
failed: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
1
|
+
declare const _runtimeApi: any;
|
|
24
2
|
export declare const VirtualBuffer: any;
|
|
25
3
|
export declare const VirtualCrypto: any;
|
|
26
4
|
export declare const VirtualZlib: any;
|
|
@@ -39,10 +17,12 @@ export declare const createVirtualFs: (options?: any) => any;
|
|
|
39
17
|
export declare const createVirtualHttp: (portTable?: any, vfs?: any) => any;
|
|
40
18
|
export declare const createVirtualNet: (portTable?: any) => any;
|
|
41
19
|
export declare const transpileTS: (code: string, filename?: string) => string;
|
|
20
|
+
export declare const transpileForBrowser: (source: string, filename?: string) => string;
|
|
42
21
|
export declare const preloadNpmPackages: (files?: Record<string, any>, onProgressOrCache?: ((pkg: string) => void) | Map<string, string>, onProgress?: (pkg: string) => void) => Promise<Record<string, string>>;
|
|
43
22
|
export declare const createVirtualPortTable: () => any;
|
|
44
|
-
export declare const executeInVirtualRuntime: (options?: any) => Promise<
|
|
45
|
-
|
|
23
|
+
export declare const executeInVirtualRuntime: (options?: any) => Promise<any>;
|
|
24
|
+
declare const createWorkerRuntimeSourceExport: () => string;
|
|
25
|
+
export { createWorkerRuntimeSourceExport as createWorkerRuntimeSource };
|
|
46
26
|
export declare const cancelWorkerExecution: (reason?: string, instanceId?: string) => boolean;
|
|
47
|
-
export declare const executeInWorker: (options?: any) => Promise<
|
|
48
|
-
export default
|
|
27
|
+
export declare const executeInWorker: (options?: any) => Promise<any>;
|
|
28
|
+
export default _runtimeApi;
|