@pie-qti/item-player 0.1.28 → 1.0.0-beta.1
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/README.md +35 -6
- package/dist/catalog/applyGlossaryTriggers.js +8 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +44 -7
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/catalogLookup.d.ts +8 -0
- package/dist/catalog/catalogLookup.js +17 -0
- package/dist/catalog/catalogLookup.js.map +1 -1
- package/dist/catalog/types.d.ts +3 -3
- package/dist/catalog/types.js.map +1 -1
- package/dist/components/utils/feedbackUtils.d.ts +9 -4
- package/dist/components/utils/feedbackUtils.js +67 -34
- package/dist/components/utils/feedbackUtils.js.map +1 -1
- package/dist/core/AssessmentItemDefinition.js +35 -0
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ItemSession.d.ts +19 -1
- package/dist/core/ItemSession.js +12 -2
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +41 -1
- package/dist/core/Player.js +216 -48
- package/dist/core/Player.js.map +1 -1
- package/dist/core/sanitizer.js +16 -3
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/document/AssessmentItemDocument.d.ts +12 -5
- package/dist/document/AssessmentItemDocument.js +28 -19
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/document/contentPass.d.ts +17 -0
- package/dist/document/contentPass.js +40 -0
- package/dist/document/contentPass.js.map +1 -0
- package/dist/document/printedVariable.d.ts +35 -0
- package/dist/document/printedVariable.js +215 -0
- package/dist/document/printedVariable.js.map +1 -0
- package/dist/{element-class-BzATCyhV.js → element-class-IVUE-E9w.js} +3288 -2311
- package/dist/element-class-IVUE-E9w.js.map +1 -0
- package/dist/element-class.js +1 -2
- package/dist/element.js +1 -1
- package/dist/element.js.map +1 -1
- package/dist/extraction/interactionAccessibility.d.ts +14 -0
- package/dist/extraction/interactionAccessibility.js +58 -0
- package/dist/extraction/interactionAccessibility.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.d.ts +4 -1
- package/dist/extraction/interactionExtractionPipeline.js +7 -2
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/utils.js +20 -1
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interactions/order/extractor.js +2 -0
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.js +47 -11
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +16 -0
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/pci/PciHost.d.ts +85 -43
- package/dist/pci/PciHost.js +229 -148
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/allowlistResolver.d.ts +10 -1
- package/dist/pci/allowlistResolver.js +43 -4
- package/dist/pci/allowlistResolver.js.map +1 -1
- package/dist/pci/amdLoader.d.ts +23 -0
- package/dist/pci/amdLoader.js +190 -0
- package/dist/pci/amdLoader.js.map +1 -0
- package/dist/pci/index.d.ts +14 -3
- package/dist/pci/index.js +8 -1
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/moduleSession.d.ts +41 -0
- package/dist/pci/moduleSession.js +2 -0
- package/dist/pci/moduleSession.js.map +1 -0
- package/dist/pci/pageRealmSession.d.ts +49 -0
- package/dist/pci/pageRealmSession.js +193 -0
- package/dist/pci/pageRealmSession.js.map +1 -0
- package/dist/pci/qtiVariableJson.d.ts +7 -0
- package/dist/pci/qtiVariableJson.js +93 -0
- package/dist/pci/qtiVariableJson.js.map +1 -0
- package/dist/pci/registry.d.ts +15 -0
- package/dist/pci/registry.js +77 -0
- package/dist/pci/registry.js.map +1 -0
- package/dist/pci/resolutionConfig.d.ts +23 -0
- package/dist/pci/resolutionConfig.js +63 -0
- package/dist/pci/resolutionConfig.js.map +1 -0
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +78 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +332 -0
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -0
- package/dist/pci/sandbox/iframeConnector.d.ts +13 -0
- package/dist/pci/sandbox/iframeConnector.js +94 -0
- package/dist/pci/sandbox/iframeConnector.js.map +1 -0
- package/dist/pci/sandbox/protocol.d.ts +117 -0
- package/dist/pci/sandbox/protocol.js +49 -0
- package/dist/pci/sandbox/protocol.js.map +1 -0
- package/dist/pci/types.d.ts +213 -30
- package/dist/pci/types.js +8 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +3 -4
- package/dist/pnp/applyPnp.js +54 -8
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.d.ts +2 -2
- package/dist/pnp/parsePnpXml.js +146 -4
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +57 -0
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +12 -1
- package/dist/presentation/itemPresentationPlan.js +11 -3
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/element-class-BzATCyhV.js.map +0 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { PciLoadError } from '../types.js';
|
|
2
|
+
import { htmlToString, sanitizeSharedHtml } from '../../security/index.js';
|
|
3
|
+
import { createIframeFrameConnector } from './iframeConnector.js';
|
|
4
|
+
import { createSandboxEnvelope, isPciSandboxEnvelope, } from './protocol.js';
|
|
5
|
+
const DEFAULT_HANDSHAKE_TIMEOUT_MS = 15000;
|
|
6
|
+
const DEFAULT_POLL_INTERVAL_MS = 250;
|
|
7
|
+
const DEFAULT_REGISTRATION_TIMEOUT_MS = 5000;
|
|
8
|
+
/**
|
|
9
|
+
* The sandboxed engine: the module runs in a cross-origin runner frame
|
|
10
|
+
* (`@pie-qti/pci-runner` deployed on a cookieless origin) and every contract
|
|
11
|
+
* call crosses the postMessage bridge.
|
|
12
|
+
*
|
|
13
|
+
* Nothing here evaluates module code. Module URLs are resolved against the
|
|
14
|
+
* package base, checked against the optional policy, and handed to the runner,
|
|
15
|
+
* which loads them in its own opaque-origin document. `getResponse()` stays
|
|
16
|
+
* synchronous for `PciHost` by answering from a cache the runner maintains:
|
|
17
|
+
* pushes on every observed change, plus a bounded poll as the freshness floor.
|
|
18
|
+
*/
|
|
19
|
+
export class SandboxedPciSession {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.connection = null;
|
|
22
|
+
this.pendingInit = null;
|
|
23
|
+
this.handshook = false;
|
|
24
|
+
this.moduleReady = false;
|
|
25
|
+
this.queuedInstantiate = null;
|
|
26
|
+
this.currentConfiguration = null;
|
|
27
|
+
/** The proxy `PciHost`'s state machine talks to; reads answer from the cache. */
|
|
28
|
+
this.proxy = null;
|
|
29
|
+
this.cache = { response: null, state: undefined };
|
|
30
|
+
this.reportHandlers = new Set();
|
|
31
|
+
this.errorHandlers = new Set();
|
|
32
|
+
this.stopMessages = null;
|
|
33
|
+
this.disposed = false;
|
|
34
|
+
this.runnerUrl = options.sandbox.runnerUrl;
|
|
35
|
+
this.handshakeTimeoutMs = options.sandbox.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;
|
|
36
|
+
this.pollIntervalMs = options.sandbox.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
37
|
+
this.registrationTimeoutMs =
|
|
38
|
+
options.sandbox.registrationTimeoutMs ?? DEFAULT_REGISTRATION_TIMEOUT_MS;
|
|
39
|
+
this.data = options.data;
|
|
40
|
+
this.baseUrl = options.baseUrl;
|
|
41
|
+
this.modulePolicy = options.modulePolicy;
|
|
42
|
+
this.parentOrigin = options.parentOrigin ?? defaultParentOrigin;
|
|
43
|
+
this.connector = options.frameConnector ?? createIframeFrameConnector();
|
|
44
|
+
// Config errors surface at construction, before any frame exists.
|
|
45
|
+
let runnerOrigin;
|
|
46
|
+
try {
|
|
47
|
+
runnerOrigin = new URL(this.runnerUrl);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new Error(`PCI sandbox runnerUrl must be an absolute URL: '${this.runnerUrl}'`);
|
|
51
|
+
}
|
|
52
|
+
if (runnerOrigin.protocol !== 'https:' && runnerOrigin.protocol !== 'http:') {
|
|
53
|
+
throw new Error(`PCI sandbox runnerUrl must be http(s): '${this.runnerUrl}'`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** {@inheritdoc PciModuleSession.load} */
|
|
57
|
+
async load(_context) {
|
|
58
|
+
if (this.disposed)
|
|
59
|
+
throw new Error('Cannot load a destroyed PciHost');
|
|
60
|
+
// Preparing the init payload resolves every authored path and runs the
|
|
61
|
+
// policy gate before a frame exists; the module itself loads in the frame,
|
|
62
|
+
// and its failures surface through onError.
|
|
63
|
+
this.pendingInit = this.buildInitPayload();
|
|
64
|
+
}
|
|
65
|
+
/** {@inheritdoc PciModuleSession.instantiate} */
|
|
66
|
+
instantiate(dom, configuration, state) {
|
|
67
|
+
if (this.disposed || !this.pendingInit)
|
|
68
|
+
return undefined;
|
|
69
|
+
this.currentConfiguration = configuration;
|
|
70
|
+
if (!this.connection || !this.connection.isAttached()) {
|
|
71
|
+
// First mount, or the renderer's scaffold reset removed the frame.
|
|
72
|
+
this.resetConnection();
|
|
73
|
+
this.connection = this.connector(this.runnerUrl, frameTitle(this.data));
|
|
74
|
+
this.stopMessages = this.connection.onMessage((data) => this.handleMessage(data));
|
|
75
|
+
dom.replaceChildren();
|
|
76
|
+
this.connection.appendTo(dom);
|
|
77
|
+
this.armHandshakeTimeout();
|
|
78
|
+
}
|
|
79
|
+
// A fresh read of the seeded state keeps the proxy honest before the
|
|
80
|
+
// instance's first report arrives.
|
|
81
|
+
this.cache.response = null;
|
|
82
|
+
this.cache.state = undefined;
|
|
83
|
+
this.proxy = {
|
|
84
|
+
getResponse: () => this.cache.response,
|
|
85
|
+
getState: () => this.cache.state,
|
|
86
|
+
disable: () => this.post('set-enabled', { enabled: false }),
|
|
87
|
+
enable: () => this.post('set-enabled', { enabled: true }),
|
|
88
|
+
};
|
|
89
|
+
const payload = {
|
|
90
|
+
responseIdentifier: configuration.responseIdentifier,
|
|
91
|
+
status: configuration.status,
|
|
92
|
+
properties: configuration.properties,
|
|
93
|
+
...(configuration.templateVariables !== undefined
|
|
94
|
+
? { templateVariables: configuration.templateVariables }
|
|
95
|
+
: {}),
|
|
96
|
+
...(configuration.contextVariables !== undefined
|
|
97
|
+
? { contextVariables: configuration.contextVariables }
|
|
98
|
+
: {}),
|
|
99
|
+
...(state !== undefined ? { state } : {}),
|
|
100
|
+
};
|
|
101
|
+
if (this.moduleReady) {
|
|
102
|
+
// Runner messages are handled in arrival order, so an in-frame instance
|
|
103
|
+
// from a previous instantiation is torn down before this one is created.
|
|
104
|
+
this.post('teardown-instance', {});
|
|
105
|
+
this.post('instantiate', payload);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.queuedInstantiate = payload;
|
|
109
|
+
}
|
|
110
|
+
return this.proxy;
|
|
111
|
+
}
|
|
112
|
+
/** {@inheritdoc PciModuleSession.destroyInstance} */
|
|
113
|
+
destroyInstance(_instance) {
|
|
114
|
+
if (this.connection && this.moduleReady) {
|
|
115
|
+
this.post('teardown-instance', {});
|
|
116
|
+
}
|
|
117
|
+
this.cache.response = null;
|
|
118
|
+
this.cache.state = undefined;
|
|
119
|
+
this.proxy = null;
|
|
120
|
+
}
|
|
121
|
+
/** {@inheritdoc PciModuleSession.dispose} */
|
|
122
|
+
dispose() {
|
|
123
|
+
if (this.connection) {
|
|
124
|
+
this.post('dispose', {});
|
|
125
|
+
}
|
|
126
|
+
this.resetConnection();
|
|
127
|
+
this.disposed = true;
|
|
128
|
+
this.pendingInit = null;
|
|
129
|
+
this.currentConfiguration = null;
|
|
130
|
+
this.queuedInstantiate = null;
|
|
131
|
+
}
|
|
132
|
+
/** {@inheritdoc PciModuleSession.onRemoteReport} */
|
|
133
|
+
onRemoteReport(handler) {
|
|
134
|
+
this.reportHandlers.add(handler);
|
|
135
|
+
return () => this.reportHandlers.delete(handler);
|
|
136
|
+
}
|
|
137
|
+
/** {@inheritdoc PciModuleSession.onError} */
|
|
138
|
+
onError(handler) {
|
|
139
|
+
this.errorHandlers.add(handler);
|
|
140
|
+
return () => this.errorHandlers.delete(handler);
|
|
141
|
+
}
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// Private helpers
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
buildInitPayload() {
|
|
146
|
+
const entries = this.data.modules
|
|
147
|
+
.filter((module) => module.primaryPath)
|
|
148
|
+
.map((module) => {
|
|
149
|
+
const primaryUrl = this.resolveChecked(module.primaryPath, 'primary');
|
|
150
|
+
return {
|
|
151
|
+
id: module.id || module.primaryPath,
|
|
152
|
+
primaryUrl,
|
|
153
|
+
...(module.fallbackPath
|
|
154
|
+
? { fallbackUrl: this.resolveChecked(module.fallbackPath, 'fallback') }
|
|
155
|
+
: {}),
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const entry = this.data.modules.find((module) => module.primaryPath === this.data.primaryPath) ??
|
|
159
|
+
this.data.modules[this.data.modules.length - 1];
|
|
160
|
+
const markup = this.data.markup;
|
|
161
|
+
return {
|
|
162
|
+
typeIdentifier: this.data.customInteractionTypeIdentifier,
|
|
163
|
+
modules: entries,
|
|
164
|
+
entryId: entry?.id || this.data.primaryPath,
|
|
165
|
+
...(this.data.resolutionConfigPath
|
|
166
|
+
? { resolutionConfigUrl: this.resolveUrl(this.data.resolutionConfigPath) }
|
|
167
|
+
: {}),
|
|
168
|
+
baseUrl: this.baseUrl,
|
|
169
|
+
// The frame renders this as its interaction markup; the same sanitizer
|
|
170
|
+
// the page-realm scaffold uses runs before it crosses the bridge.
|
|
171
|
+
markup: htmlToString(sanitizeSharedHtml(htmlToString(markup))),
|
|
172
|
+
registrationTimeoutMs: this.registrationTimeoutMs,
|
|
173
|
+
pollIntervalMs: this.pollIntervalMs,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/** Resolve one authored path and run the policy gate on the absolute URL. */
|
|
177
|
+
resolveChecked(path, kind) {
|
|
178
|
+
const resolved = this.resolveUrl(path);
|
|
179
|
+
if (this.modulePolicy) {
|
|
180
|
+
this.modulePolicy(resolved, {
|
|
181
|
+
authoredPath: path,
|
|
182
|
+
kind,
|
|
183
|
+
responseIdentifier: this.data.responseIdentifier,
|
|
184
|
+
customInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return resolved;
|
|
188
|
+
}
|
|
189
|
+
resolveUrl(path) {
|
|
190
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {
|
|
191
|
+
return path;
|
|
192
|
+
}
|
|
193
|
+
if (!this.baseUrl)
|
|
194
|
+
return path;
|
|
195
|
+
const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';
|
|
196
|
+
try {
|
|
197
|
+
return new URL(path, base).href;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return base + path;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
post(type, payload) {
|
|
204
|
+
if (!this.connection)
|
|
205
|
+
return;
|
|
206
|
+
this.connection.post(createSandboxEnvelope(type, payload));
|
|
207
|
+
}
|
|
208
|
+
resetConnection() {
|
|
209
|
+
if (this.handshakeTimer !== undefined) {
|
|
210
|
+
clearTimeout(this.handshakeTimer);
|
|
211
|
+
this.handshakeTimer = undefined;
|
|
212
|
+
}
|
|
213
|
+
this.stopMessages?.();
|
|
214
|
+
this.stopMessages = null;
|
|
215
|
+
this.connection?.dispose();
|
|
216
|
+
this.connection = null;
|
|
217
|
+
this.handshook = false;
|
|
218
|
+
this.moduleReady = false;
|
|
219
|
+
}
|
|
220
|
+
armHandshakeTimeout() {
|
|
221
|
+
if (this.handshakeTimer !== undefined)
|
|
222
|
+
clearTimeout(this.handshakeTimer);
|
|
223
|
+
this.handshakeTimer = setTimeout(() => {
|
|
224
|
+
this.handshakeTimer = undefined;
|
|
225
|
+
if (this.disposed || this.moduleReady)
|
|
226
|
+
return;
|
|
227
|
+
// A frame that never became ready (or a module that never loaded) is
|
|
228
|
+
// reported but not torn down: a late load still recovers the interaction.
|
|
229
|
+
// Not a PciLoadError — no authored path was attempted yet.
|
|
230
|
+
this.emitError(new Error(`PCI runner frame did not become ready within ${this.handshakeTimeoutMs}ms`));
|
|
231
|
+
}, this.handshakeTimeoutMs);
|
|
232
|
+
}
|
|
233
|
+
emitError(error) {
|
|
234
|
+
for (const handler of this.errorHandlers)
|
|
235
|
+
handler(error);
|
|
236
|
+
}
|
|
237
|
+
handleMessage(data) {
|
|
238
|
+
if (!isPciSandboxEnvelope(data))
|
|
239
|
+
return;
|
|
240
|
+
switch (data.type) {
|
|
241
|
+
case 'runner-ready': {
|
|
242
|
+
if (this.handshook)
|
|
243
|
+
return;
|
|
244
|
+
this.handshook = true;
|
|
245
|
+
// Sent in order: the runner locks on `hello` before `init` arrives.
|
|
246
|
+
this.post('hello', { parentOrigin: this.parentOrigin() });
|
|
247
|
+
if (this.pendingInit)
|
|
248
|
+
this.post('init', this.pendingInit);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
case 'module-loaded': {
|
|
252
|
+
this.moduleReady = true;
|
|
253
|
+
if (this.handshakeTimer !== undefined) {
|
|
254
|
+
clearTimeout(this.handshakeTimer);
|
|
255
|
+
this.handshakeTimer = undefined;
|
|
256
|
+
}
|
|
257
|
+
if (this.queuedInstantiate) {
|
|
258
|
+
this.post('instantiate', this.queuedInstantiate);
|
|
259
|
+
this.queuedInstantiate = null;
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
case 'module-error': {
|
|
264
|
+
const message = typeof data.payload?.message === 'string'
|
|
265
|
+
? data.payload.message
|
|
266
|
+
: 'unknown error';
|
|
267
|
+
this.emitError(new PciLoadError(this.data.primaryPath, this.data.fallbackPath, new Error(message)));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
case 'instance-ready': {
|
|
271
|
+
this.applySnapshot(data.payload);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
case 'ready': {
|
|
275
|
+
this.applySnapshot(data.payload);
|
|
276
|
+
if (this.proxy) {
|
|
277
|
+
this.currentConfiguration?.onready(this.proxy, data.payload.state);
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
case 'done': {
|
|
282
|
+
this.applySnapshot(data.payload);
|
|
283
|
+
if (this.proxy) {
|
|
284
|
+
this.currentConfiguration?.ondone(this.proxy, data.payload.state);
|
|
285
|
+
}
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
case 'response-change': {
|
|
289
|
+
this.applySnapshot(data.payload);
|
|
290
|
+
const state = data.payload.state;
|
|
291
|
+
for (const handler of this.reportHandlers)
|
|
292
|
+
handler({ state });
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
case 'instance-error': {
|
|
296
|
+
const message = typeof data.payload?.message === 'string'
|
|
297
|
+
? data.payload.message
|
|
298
|
+
: 'unknown error';
|
|
299
|
+
this.emitError(new Error(`PCI runner failed to instantiate: ${message}`));
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
case 'resize': {
|
|
303
|
+
const height = data.payload?.height;
|
|
304
|
+
if (typeof height === 'number')
|
|
305
|
+
this.connection?.setHeight(height);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
default:
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/** Take a bridge snapshot into the cache the proxy reads from. */
|
|
313
|
+
applySnapshot(payload) {
|
|
314
|
+
if (typeof payload !== 'object' || payload === null)
|
|
315
|
+
return;
|
|
316
|
+
const snapshot = payload;
|
|
317
|
+
if ('response' in snapshot)
|
|
318
|
+
this.cache.response = snapshot.response ?? null;
|
|
319
|
+
if ('state' in snapshot && snapshot.state !== undefined)
|
|
320
|
+
this.cache.state = snapshot.state;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function defaultParentOrigin() {
|
|
324
|
+
return globalThis.location?.origin ?? '';
|
|
325
|
+
}
|
|
326
|
+
/** The frame's accessible name: the PCI type's tail, locale-neutral by nature. */
|
|
327
|
+
function frameTitle(data) {
|
|
328
|
+
const typeIdentifier = data.customInteractionTypeIdentifier;
|
|
329
|
+
const tail = typeIdentifier.split(/[/:#]/).pop();
|
|
330
|
+
return tail && tail.length > 0 ? `Interactive content: ${tail}` : 'Interactive content';
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=SandboxedPciSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SandboxedPciSession.js","sourceRoot":"","sources":["../../../src/pci/sandbox/SandboxedPciSession.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EACN,qBAAqB,EACrB,oBAAoB,GAIpB,MAAM,eAAe,CAAC;AAEvB,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAiB7C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,mBAAmB;IA0B/B,YAAY,OAAgC;QAfpC,eAAU,GAAyC,IAAI,CAAC;QACxD,gBAAW,GAAiC,IAAI,CAAC;QACjD,cAAS,GAAG,KAAK,CAAC;Q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AAC,GAAG,EAAE,CAAC;IACjD,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC;AACzF,CAAC","sourcesContent":["import type { PciLoadContext, PciModuleSession } from '../moduleSession.js';\nimport type {\n\tExtractedPci,\n\tPciFrameConnector,\n\tPciModulePolicy,\n\tPciSandboxConfiguration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from '../types.js';\nimport { PciLoadError } from '../types.js';\nimport { htmlToString, sanitizeSharedHtml } from '../../security/index.js';\nimport { createIframeFrameConnector } from './iframeConnector.js';\nimport {\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n\ttype PciSandboxInitPayload,\n\ttype PciSandboxInstantiatePayload,\n\ttype PciSandboxModuleEntryPayload,\n} from './protocol.js';\n\nconst DEFAULT_HANDSHAKE_TIMEOUT_MS = 15000;\nconst DEFAULT_POLL_INTERVAL_MS = 250;\nconst DEFAULT_REGISTRATION_TIMEOUT_MS = 5000;\n\nexport interface SandboxedSessionOptions {\n\tsandbox: PciSandboxConfiguration;\n\tdata: ExtractedPci;\n\tbaseUrl: string;\n\t/** Policy gate applied to module URLs before anything is handed to the frame. */\n\tmodulePolicy?: PciModulePolicy;\n\t/** The page origin the runner locks to; injectable for tests. */\n\tparentOrigin?: () => string;\n\t/** Frame connection factory; defaults to a real sandboxed iframe. */\n\tframeConnector?: PciFrameConnector;\n}\n\ntype RemoteReportHandler = (report: { state?: unknown }) => void;\ntype ErrorHandler = (error: Error) => void;\n\n/**\n * The sandboxed engine: the module runs in a cross-origin runner frame\n * (`@pie-qti/pci-runner` deployed on a cookieless origin) and every contract\n * call crosses the postMessage bridge.\n *\n * Nothing here evaluates module code. Module URLs are resolved against the\n * package base, checked against the optional policy, and handed to the runner,\n * which loads them in its own opaque-origin document. `getResponse()` stays\n * synchronous for `PciHost` by answering from a cache the runner maintains:\n * pushes on every observed change, plus a bounded poll as the freshness floor.\n */\nexport class SandboxedPciSession implements PciModuleSession {\n\tprivate readonly runnerUrl: string;\n\tprivate readonly handshakeTimeoutMs: number;\n\tprivate readonly pollIntervalMs: number;\n\tprivate readonly registrationTimeoutMs: number;\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly modulePolicy: PciModulePolicy | undefined;\n\tprivate readonly parentOrigin: () => string;\n\tprivate readonly connector: PciFrameConnector;\n\n\tprivate connection: ReturnType<PciFrameConnector> | null = null;\n\tprivate pendingInit: PciSandboxInitPayload | null = null;\n\tprivate handshook = false;\n\tprivate moduleReady = false;\n\tprivate handshakeTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate queuedInstantiate: PciSandboxInstantiatePayload | null = null;\n\tprivate currentConfiguration: QtiPciConfiguration | null = null;\n\t/** The proxy `PciHost`'s state machine talks to; reads answer from the cache. */\n\tprivate proxy: (QtiPciInstance & { disable?(): void; enable?(): void }) | null = null;\n\tprivate readonly cache: { response: unknown; state: unknown } = { response: null, state: undefined };\n\tprivate readonly reportHandlers = new Set<RemoteReportHandler>();\n\tprivate readonly errorHandlers = new Set<ErrorHandler>();\n\tprivate stopMessages: (() => void) | null = null;\n\tprivate disposed = false;\n\n\tconstructor(options: SandboxedSessionOptions) {\n\t\tthis.runnerUrl = options.sandbox.runnerUrl;\n\t\tthis.handshakeTimeoutMs = options.sandbox.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;\n\t\tthis.pollIntervalMs = options.sandbox.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n\t\tthis.registrationTimeoutMs =\n\t\t\toptions.sandbox.registrationTimeoutMs ?? DEFAULT_REGISTRATION_TIMEOUT_MS;\n\t\tthis.data = options.data;\n\t\tthis.baseUrl = options.baseUrl;\n\t\tthis.modulePolicy = options.modulePolicy;\n\t\tthis.parentOrigin = options.parentOrigin ?? defaultParentOrigin;\n\t\tthis.connector = options.frameConnector ?? createIframeFrameConnector();\n\n\t\t// Config errors surface at construction, before any frame exists.\n\t\tlet runnerOrigin: URL;\n\t\ttry {\n\t\t\trunnerOrigin = new URL(this.runnerUrl);\n\t\t} catch {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be an absolute URL: '${this.runnerUrl}'`);\n\t\t}\n\t\tif (runnerOrigin.protocol !== 'https:' && runnerOrigin.protocol !== 'http:') {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be http(s): '${this.runnerUrl}'`);\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciModuleSession.load} */\n\tpublic async load(_context: PciLoadContext): Promise<void> {\n\t\tif (this.disposed) throw new Error('Cannot load a destroyed PciHost');\n\t\t// Preparing the init payload resolves every authored path and runs the\n\t\t// policy gate before a frame exists; the module itself loads in the frame,\n\t\t// and its failures surface through onError.\n\t\tthis.pendingInit = this.buildInitPayload();\n\t}\n\n\t/** {@inheritdoc PciModuleSession.instantiate} */\n\tpublic instantiate(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate: unknown\n\t): QtiPciInstance | undefined {\n\t\tif (this.disposed || !this.pendingInit) return undefined;\n\t\tthis.currentConfiguration = configuration;\n\n\t\tif (!this.connection || !this.connection.isAttached()) {\n\t\t\t// First mount, or the renderer's scaffold reset removed the frame.\n\t\t\tthis.resetConnection();\n\t\t\tthis.connection = this.connector(this.runnerUrl, frameTitle(this.data));\n\t\t\tthis.stopMessages = this.connection.onMessage((data) => this.handleMessage(data));\n\t\t\tdom.replaceChildren();\n\t\t\tthis.connection.appendTo(dom);\n\t\t\tthis.armHandshakeTimeout();\n\t\t}\n\n\t\t// A fresh read of the seeded state keeps the proxy honest before the\n\t\t// instance's first report arrives.\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = {\n\t\t\tgetResponse: () => this.cache.response,\n\t\t\tgetState: () => this.cache.state,\n\t\t\tdisable: () => this.post('set-enabled', { enabled: false }),\n\t\t\tenable: () => this.post('set-enabled', { enabled: true }),\n\t\t};\n\n\t\tconst payload: PciSandboxInstantiatePayload = {\n\t\t\tresponseIdentifier: configuration.responseIdentifier,\n\t\t\tstatus: configuration.status,\n\t\t\tproperties: configuration.properties,\n\t\t\t...(configuration.templateVariables !== undefined\n\t\t\t\t? { templateVariables: configuration.templateVariables }\n\t\t\t\t: {}),\n\t\t\t...(configuration.contextVariables !== undefined\n\t\t\t\t? { contextVariables: configuration.contextVariables }\n\t\t\t\t: {}),\n\t\t\t...(state !== undefined ? { state } : {}),\n\t\t};\n\t\tif (this.moduleReady) {\n\t\t\t// Runner messages are handled in arrival order, so an in-frame instance\n\t\t\t// from a previous instantiation is torn down before this one is created.\n\t\t\tthis.post('teardown-instance', {});\n\t\t\tthis.post('instantiate', payload);\n\t\t} else {\n\t\t\tthis.queuedInstantiate = payload;\n\t\t}\n\t\treturn this.proxy;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.destroyInstance} */\n\tpublic destroyInstance(_instance: QtiPciInstance): void {\n\t\tif (this.connection && this.moduleReady) {\n\t\t\tthis.post('teardown-instance', {});\n\t\t}\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.dispose} */\n\tpublic dispose(): void {\n\t\tif (this.connection) {\n\t\t\tthis.post('dispose', {});\n\t\t}\n\t\tthis.resetConnection();\n\t\tthis.disposed = true;\n\t\tthis.pendingInit = null;\n\t\tthis.currentConfiguration = null;\n\t\tthis.queuedInstantiate = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onRemoteReport} */\n\tpublic onRemoteReport(handler: RemoteReportHandler): () => void {\n\t\tthis.reportHandlers.add(handler);\n\t\treturn () => this.reportHandlers.delete(handler);\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onError} */\n\tpublic onError(handler: ErrorHandler): () => void {\n\t\tthis.errorHandlers.add(handler);\n\t\treturn () => this.errorHandlers.delete(handler);\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate buildInitPayload(): PciSandboxInitPayload {\n\t\tconst entries: PciSandboxModuleEntryPayload[] = this.data.modules\n\t\t\t.filter((module) => module.primaryPath)\n\t\t\t.map((module) => {\n\t\t\t\tconst primaryUrl = this.resolveChecked(module.primaryPath, 'primary');\n\t\t\t\treturn {\n\t\t\t\t\tid: module.id || module.primaryPath,\n\t\t\t\t\tprimaryUrl,\n\t\t\t\t\t...(module.fallbackPath\n\t\t\t\t\t\t? { fallbackUrl: this.resolveChecked(module.fallbackPath, 'fallback') }\n\t\t\t\t\t\t: {}),\n\t\t\t\t};\n\t\t\t});\n\t\tconst entry =\n\t\t\tthis.data.modules.find((module) => module.primaryPath === this.data.primaryPath) ??\n\t\t\tthis.data.modules[this.data.modules.length - 1];\n\t\tconst markup = this.data.markup;\n\t\treturn {\n\t\t\ttypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\tmodules: entries,\n\t\t\tentryId: entry?.id || this.data.primaryPath,\n\t\t\t...(this.data.resolutionConfigPath\n\t\t\t\t? { resolutionConfigUrl: this.resolveUrl(this.data.resolutionConfigPath) }\n\t\t\t\t: {}),\n\t\t\tbaseUrl: this.baseUrl,\n\t\t\t// The frame renders this as its interaction markup; the same sanitizer\n\t\t\t// the page-realm scaffold uses runs before it crosses the bridge.\n\t\t\tmarkup: htmlToString(sanitizeSharedHtml(htmlToString(markup))),\n\t\t\tregistrationTimeoutMs: this.registrationTimeoutMs,\n\t\t\tpollIntervalMs: this.pollIntervalMs,\n\t\t};\n\t}\n\n\t/** Resolve one authored path and run the policy gate on the absolute URL. */\n\tprivate resolveChecked(path: string, kind: 'primary' | 'fallback'): string {\n\t\tconst resolved = this.resolveUrl(path);\n\t\tif (this.modulePolicy) {\n\t\t\tthis.modulePolicy(resolved, {\n\t\t\t\tauthoredPath: path,\n\t\t\t\tkind,\n\t\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\t\tcustomInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\t});\n\t\t}\n\t\treturn resolved;\n\t}\n\n\tprivate resolveUrl(path: string): string {\n\t\tif (/^[a-z][a-z\\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {\n\t\t\treturn path;\n\t\t}\n\t\tif (!this.baseUrl) return path;\n\t\tconst base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';\n\t\ttry {\n\t\t\treturn new URL(path, base).href;\n\t\t} catch {\n\t\t\treturn base + path;\n\t\t}\n\t}\n\n\tprivate post(type: Parameters<typeof createSandboxEnvelope>[0], payload: unknown): void {\n\t\tif (!this.connection) return;\n\t\tthis.connection.post(createSandboxEnvelope(type, payload));\n\t}\n\n\tprivate resetConnection(): void {\n\t\tif (this.handshakeTimer !== undefined) {\n\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\tthis.handshakeTimer = undefined;\n\t\t}\n\t\tthis.stopMessages?.();\n\t\tthis.stopMessages = null;\n\t\tthis.connection?.dispose();\n\t\tthis.connection = null;\n\t\tthis.handshook = false;\n\t\tthis.moduleReady = false;\n\t}\n\n\tprivate armHandshakeTimeout(): void {\n\t\tif (this.handshakeTimer !== undefined) clearTimeout(this.handshakeTimer);\n\t\tthis.handshakeTimer = setTimeout(() => {\n\t\t\tthis.handshakeTimer = undefined;\n\t\t\tif (this.disposed || this.moduleReady) return;\n\t\t\t// A frame that never became ready (or a module that never loaded) is\n\t\t\t// reported but not torn down: a late load still recovers the interaction.\n\t\t\t// Not a PciLoadError — no authored path was attempted yet.\n\t\t\tthis.emitError(\n\t\t\t\tnew Error(`PCI runner frame did not become ready within ${this.handshakeTimeoutMs}ms`)\n\t\t\t);\n\t\t}, this.handshakeTimeoutMs);\n\t}\n\n\tprivate emitError(error: Error): void {\n\t\tfor (const handler of this.errorHandlers) handler(error);\n\t}\n\n\tprivate handleMessage(data: unknown): void {\n\t\tif (!isPciSandboxEnvelope(data)) return;\n\t\tswitch (data.type) {\n\t\t\tcase 'runner-ready': {\n\t\t\t\tif (this.handshook) return;\n\t\t\t\tthis.handshook = true;\n\t\t\t\t// Sent in order: the runner locks on `hello` before `init` arrives.\n\t\t\t\tthis.post('hello', { parentOrigin: this.parentOrigin() });\n\t\t\t\tif (this.pendingInit) this.post('init', this.pendingInit);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-loaded': {\n\t\t\t\tthis.moduleReady = true;\n\t\t\t\tif (this.handshakeTimer !== undefined) {\n\t\t\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\t\t\tthis.handshakeTimer = undefined;\n\t\t\t\t}\n\t\t\t\tif (this.queuedInstantiate) {\n\t\t\t\t\tthis.post('instantiate', this.queuedInstantiate);\n\t\t\t\t\tthis.queuedInstantiate = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(\n\t\t\t\t\tnew PciLoadError(\n\t\t\t\t\t\tthis.data.primaryPath,\n\t\t\t\t\t\tthis.data.fallbackPath,\n\t\t\t\t\t\tnew Error(message)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.onready(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'done': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.ondone(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'response-change': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tconst state = (data.payload as { state?: unknown }).state;\n\t\t\t\tfor (const handler of this.reportHandlers) handler({ state });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(new Error(`PCI runner failed to instantiate: ${message}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'resize': {\n\t\t\t\tconst height = (data.payload as { height?: unknown })?.height;\n\t\t\t\tif (typeof height === 'number') this.connection?.setHeight(height);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Take a bridge snapshot into the cache the proxy reads from. */\n\tprivate applySnapshot(payload: unknown): void {\n\t\tif (typeof payload !== 'object' || payload === null) return;\n\t\tconst snapshot = payload as { response?: unknown; state?: unknown };\n\t\tif ('response' in snapshot) this.cache.response = snapshot.response ?? null;\n\t\tif ('state' in snapshot && snapshot.state !== undefined) this.cache.state = snapshot.state;\n\t}\n}\n\nfunction defaultParentOrigin(): string {\n\treturn globalThis.location?.origin ?? '';\n}\n\n/** The frame's accessible name: the PCI type's tail, locale-neutral by nature. */\nfunction frameTitle(data: ExtractedPci): string {\n\tconst typeIdentifier = data.customInteractionTypeIdentifier;\n\tconst tail = typeIdentifier.split(/[/:#]/).pop();\n\treturn tail && tail.length > 0 ? `Interactive content: ${tail}` : 'Interactive content';\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PciFrameConnector } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The production `PciFrameConnector`: one `<iframe sandbox="allow-scripts">`
|
|
4
|
+
* per PCI, loaded from the runner origin. Without `allow-same-origin` the
|
|
5
|
+
* frame's document has an opaque origin — it shares no storage, cookies, or
|
|
6
|
+
* DOM with the player — while its base URL stays the runner URL, so authored
|
|
7
|
+
* relative asset paths still resolve inside it.
|
|
8
|
+
*
|
|
9
|
+
* Incoming messages are accepted only when `event.origin` is the runner origin
|
|
10
|
+
* and `event.source` is this frame's `contentWindow`; outgoing messages are
|
|
11
|
+
* posted locked to the runner origin.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createIframeFrameConnector(): PciFrameConnector;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The production `PciFrameConnector`: one `<iframe sandbox="allow-scripts">`
|
|
3
|
+
* per PCI, loaded from the runner origin. Without `allow-same-origin` the
|
|
4
|
+
* frame's document has an opaque origin — it shares no storage, cookies, or
|
|
5
|
+
* DOM with the player — while its base URL stays the runner URL, so authored
|
|
6
|
+
* relative asset paths still resolve inside it.
|
|
7
|
+
*
|
|
8
|
+
* Incoming messages are accepted only when `event.origin` is the runner origin
|
|
9
|
+
* and `event.source` is this frame's `contentWindow`; outgoing messages are
|
|
10
|
+
* posted locked to the runner origin.
|
|
11
|
+
*/
|
|
12
|
+
export function createIframeFrameConnector() {
|
|
13
|
+
return (frameUrl, title) => new IframeFrameConnection(frameUrl, title);
|
|
14
|
+
}
|
|
15
|
+
class IframeFrameConnection {
|
|
16
|
+
/** The identity incoming events are filtered against: this frame's window. */
|
|
17
|
+
get source() {
|
|
18
|
+
return this.frame.contentWindow;
|
|
19
|
+
}
|
|
20
|
+
constructor(frameUrl, title) {
|
|
21
|
+
this.handlers = new Set();
|
|
22
|
+
this.disposed = false;
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(frameUrl);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error(`PCI sandbox runnerUrl must be an absolute URL: '${frameUrl}'`);
|
|
29
|
+
}
|
|
30
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
31
|
+
throw new Error(`PCI sandbox runnerUrl must be http(s): '${frameUrl}'`);
|
|
32
|
+
}
|
|
33
|
+
this.frameOrigin = url.origin;
|
|
34
|
+
const frame = document.createElement('iframe');
|
|
35
|
+
// `allow-scripts` alone: a frame carrying it together with `allow-same-origin`
|
|
36
|
+
// could strip its own sandbox attribute.
|
|
37
|
+
frame.setAttribute('sandbox', 'allow-scripts');
|
|
38
|
+
frame.src = frameUrl;
|
|
39
|
+
frame.title = title;
|
|
40
|
+
frame.style.width = '100%';
|
|
41
|
+
frame.style.border = '0';
|
|
42
|
+
frame.style.display = 'block';
|
|
43
|
+
// The runner reports the interaction's height; until then the frame stays
|
|
44
|
+
// out of the layout's way.
|
|
45
|
+
frame.style.height = '0px';
|
|
46
|
+
this.frame = frame;
|
|
47
|
+
this.windowListener = (event) => {
|
|
48
|
+
if (this.disposed)
|
|
49
|
+
return;
|
|
50
|
+
if (event.source !== this.frame.contentWindow)
|
|
51
|
+
return;
|
|
52
|
+
if (event.origin !== this.frameOrigin)
|
|
53
|
+
return;
|
|
54
|
+
for (const handler of this.handlers)
|
|
55
|
+
handler(event.data);
|
|
56
|
+
};
|
|
57
|
+
if (typeof window !== 'undefined') {
|
|
58
|
+
window.addEventListener('message', this.windowListener);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** {@inheritdoc PciFrameConnection.post} */
|
|
62
|
+
post(message) {
|
|
63
|
+
this.frame.contentWindow?.postMessage(message, this.frameOrigin);
|
|
64
|
+
}
|
|
65
|
+
/** {@inheritdoc PciFrameConnection.appendTo} */
|
|
66
|
+
appendTo(target) {
|
|
67
|
+
target.appendChild(this.frame);
|
|
68
|
+
}
|
|
69
|
+
/** {@inheritdoc PciFrameConnection.isAttached} */
|
|
70
|
+
isAttached() {
|
|
71
|
+
return this.frame.isConnected;
|
|
72
|
+
}
|
|
73
|
+
/** {@inheritdoc PciFrameConnection.setHeight} */
|
|
74
|
+
setHeight(height) {
|
|
75
|
+
if (Number.isFinite(height) && height >= 0) {
|
|
76
|
+
this.frame.style.height = `${Math.ceil(height)}px`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** {@inheritdoc PciFrameConnection.onMessage} */
|
|
80
|
+
onMessage(handler) {
|
|
81
|
+
this.handlers.add(handler);
|
|
82
|
+
return () => this.handlers.delete(handler);
|
|
83
|
+
}
|
|
84
|
+
/** {@inheritdoc PciFrameConnection.dispose} */
|
|
85
|
+
dispose() {
|
|
86
|
+
this.disposed = true;
|
|
87
|
+
this.handlers.clear();
|
|
88
|
+
if (typeof window !== 'undefined') {
|
|
89
|
+
window.removeEventListener('message', this.windowListener);
|
|
90
|
+
}
|
|
91
|
+
this.frame.remove();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=iframeConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframeConnector.js","sourceRoot":"","sources":["../../../src/pci/sandbox/iframeConnector.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B;IACzC,OAAO,CAAC,QAAgB,EAAE,KAAa,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACxF,CAAC;AAED,MAAM,qBAAqB;IAG1B,8EAA8E;IAC9E,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;IACjC,CAAC;IAOD,YAAY,QAAgB,EAAE,KAAa;QAJ1B,aAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;QAEvD,aAAQ,GAAG,KAAK,CAAC;QAGxB,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACJ,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,mDAAmD,QAAQ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nector } from '../types.js';\n\n/**\n * The production `PciFrameConnector`: one `<iframe sandbox=\"allow-scripts\">`\n * per PCI, loaded from the runner origin. Without `allow-same-origin` the\n * frame's document has an opaque origin — it shares no storage, cookies, or\n * DOM with the player — while its base URL stays the runner URL, so authored\n * relative asset paths still resolve inside it.\n *\n * Incoming messages are accepted only when `event.origin` is the runner origin\n * and `event.source` is this frame's `contentWindow`; outgoing messages are\n * posted locked to the runner origin.\n */\nexport function createIframeFrameConnector(): PciFrameConnector {\n\treturn (frameUrl: string, title: string) => new IframeFrameConnection(frameUrl, title);\n}\n\nclass IframeFrameConnection implements PciFrameConnection {\n\tpublic readonly frameOrigin: string;\n\n\t/** The identity incoming events are filtered against: this frame's window. */\n\tpublic get source(): unknown {\n\t\treturn this.frame.contentWindow;\n\t}\n\n\tprivate readonly frame: HTMLIFrameElement;\n\tprivate readonly handlers = new Set<(data: unknown) => void>();\n\tprivate readonly windowListener: (event: MessageEvent) => void;\n\tprivate disposed = false;\n\n\tconstructor(frameUrl: string, title: string) {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(frameUrl);\n\t\t} catch {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be an absolute URL: '${frameUrl}'`);\n\t\t}\n\t\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be http(s): '${frameUrl}'`);\n\t\t}\n\t\tthis.frameOrigin = url.origin;\n\n\t\tconst frame = document.createElement('iframe');\n\t\t// `allow-scripts` alone: a frame carrying it together with `allow-same-origin`\n\t\t// could strip its own sandbox attribute.\n\t\tframe.setAttribute('sandbox', 'allow-scripts');\n\t\tframe.src = frameUrl;\n\t\tframe.title = title;\n\t\tframe.style.width = '100%';\n\t\tframe.style.border = '0';\n\t\tframe.style.display = 'block';\n\t\t// The runner reports the interaction's height; until then the frame stays\n\t\t// out of the layout's way.\n\t\tframe.style.height = '0px';\n\t\tthis.frame = frame;\n\n\t\tthis.windowListener = (event: MessageEvent) => {\n\t\t\tif (this.disposed) return;\n\t\t\tif (event.source !== this.frame.contentWindow) return;\n\t\t\tif (event.origin !== this.frameOrigin) return;\n\t\t\tfor (const handler of this.handlers) handler(event.data);\n\t\t};\n\t\tif (typeof window !== 'undefined') {\n\t\t\twindow.addEventListener('message', this.windowListener);\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.post} */\n\tpublic post(message: unknown): void {\n\t\tthis.frame.contentWindow?.postMessage(message, this.frameOrigin);\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.appendTo} */\n\tpublic appendTo(target: HTMLElement): void {\n\t\ttarget.appendChild(this.frame);\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.isAttached} */\n\tpublic isAttached(): boolean {\n\t\treturn this.frame.isConnected;\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.setHeight} */\n\tpublic setHeight(height: number): void {\n\t\tif (Number.isFinite(height) && height >= 0) {\n\t\t\tthis.frame.style.height = `${Math.ceil(height)}px`;\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.onMessage} */\n\tpublic onMessage(handler: (data: unknown) => void): () => void {\n\t\tthis.handlers.add(handler);\n\t\treturn () => this.handlers.delete(handler);\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.dispose} */\n\tpublic dispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.handlers.clear();\n\t\tif (typeof window !== 'undefined') {\n\t\t\twindow.removeEventListener('message', this.windowListener);\n\t\t}\n\t\tthis.frame.remove();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PCI sandbox bridge protocol (host page ⇄ runner frame).
|
|
3
|
+
*
|
|
4
|
+
* The sandboxed engine runs a PCI module inside `<iframe sandbox="allow-scripts">`
|
|
5
|
+
* loaded from a dedicated runner origin (`@pie-qti/pci-runner`). The frame's
|
|
6
|
+
* document has an opaque origin, so every contract call crosses `postMessage`:
|
|
7
|
+
* this module defines the versioned envelope and payload shapes both sides
|
|
8
|
+
* speak. Like `src/iframe/protocol.ts`, it contains no DOM globals and can be
|
|
9
|
+
* imported anywhere.
|
|
10
|
+
*
|
|
11
|
+
* Origin locking is mutual and rooted at each side's structural facts:
|
|
12
|
+
*
|
|
13
|
+
* - The host accepts a message only when `event.origin` equals the runner
|
|
14
|
+
* URL's origin **and** `event.source` is the frame's `contentWindow`.
|
|
15
|
+
* - The runner accepts its first message only from its `window.parent`, locks
|
|
16
|
+
* to that message's `event.origin`, and sends everything to that origin.
|
|
17
|
+
*
|
|
18
|
+
* `runner-ready` is the one message posted without a locked origin (the runner
|
|
19
|
+
* cannot know its parent before the first exchange). It carries no secrets —
|
|
20
|
+
* it only announces the protocol version.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PCI_SANDBOX_PROTOCOL: "pie-qti-pci-sandbox";
|
|
23
|
+
export declare const PCI_SANDBOX_PROTOCOL_VERSION: "0.1.0";
|
|
24
|
+
export type PciSandboxProtocolVersion = typeof PCI_SANDBOX_PROTOCOL_VERSION;
|
|
25
|
+
export type PciSandboxHostToRunnerType = 'hello' | 'init' | 'instantiate' | 'set-enabled' | 'teardown-instance' | 'dispose';
|
|
26
|
+
export type PciSandboxRunnerToHostType = 'runner-ready' | 'module-loaded' | 'module-error' | 'instance-ready' | 'instance-error' | 'ready' | 'done' | 'response-change' | 'resize';
|
|
27
|
+
export type PciSandboxMessageType = PciSandboxHostToRunnerType | PciSandboxRunnerToHostType;
|
|
28
|
+
export interface PciSandboxEnvelope<TType extends PciSandboxMessageType = PciSandboxMessageType, TPayload = unknown> {
|
|
29
|
+
protocol: typeof PCI_SANDBOX_PROTOCOL;
|
|
30
|
+
version: PciSandboxProtocolVersion;
|
|
31
|
+
type: TType;
|
|
32
|
+
payload: TPayload;
|
|
33
|
+
}
|
|
34
|
+
/** runner → host, immediately when the runner page loads. */
|
|
35
|
+
export interface PciSandboxRunnerReadyPayload {
|
|
36
|
+
runtime?: string;
|
|
37
|
+
}
|
|
38
|
+
/** host → runner, locking the runner to the page's origin. */
|
|
39
|
+
export interface PciSandboxHelloPayload {
|
|
40
|
+
/** The origin the runner must send every subsequent message to. */
|
|
41
|
+
parentOrigin: string;
|
|
42
|
+
}
|
|
43
|
+
/** One authored `qti-interaction-module` entry, resolved to absolute URLs. */
|
|
44
|
+
export interface PciSandboxModuleEntryPayload {
|
|
45
|
+
id: string;
|
|
46
|
+
primaryUrl: string;
|
|
47
|
+
fallbackUrl?: string;
|
|
48
|
+
}
|
|
49
|
+
/** host → runner: load the resolution config and the entry module. */
|
|
50
|
+
export interface PciSandboxInitPayload {
|
|
51
|
+
/** The `customInteractionTypeIdentifier` whose registration instantiates. */
|
|
52
|
+
typeIdentifier: string;
|
|
53
|
+
/** Authored module entries, paths resolved to absolute URLs. */
|
|
54
|
+
modules: PciSandboxModuleEntryPayload[];
|
|
55
|
+
/** The id of the entry module whose registration instantiates. */
|
|
56
|
+
entryId: string;
|
|
57
|
+
/** Absolute resolution-config URL, when the item authored one. */
|
|
58
|
+
resolutionConfigUrl?: string;
|
|
59
|
+
/** Package base URL; relative config paths and module assets resolve against it. */
|
|
60
|
+
baseUrl: string;
|
|
61
|
+
/** The interaction markup, already sanitized by the host. */
|
|
62
|
+
markup: string;
|
|
63
|
+
/** Milliseconds the runner waits for the module to register. */
|
|
64
|
+
registrationTimeoutMs: number;
|
|
65
|
+
/** How often the runner pushes response/state reads. */
|
|
66
|
+
pollIntervalMs: number;
|
|
67
|
+
}
|
|
68
|
+
/** host → runner: instantiate the interaction. */
|
|
69
|
+
export interface PciSandboxInstantiatePayload {
|
|
70
|
+
responseIdentifier: string;
|
|
71
|
+
status: string;
|
|
72
|
+
properties: Record<string, string>;
|
|
73
|
+
templateVariables?: Record<string, unknown>;
|
|
74
|
+
contextVariables?: Record<string, unknown>;
|
|
75
|
+
/** The QTI variable JSON (or module state) this instantiation is seeded with. */
|
|
76
|
+
state?: unknown;
|
|
77
|
+
}
|
|
78
|
+
/** host → runner. */
|
|
79
|
+
export interface PciSandboxSetEnabledPayload {
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Response and state exactly as the module reports them (QTI variable JSON). */
|
|
83
|
+
export interface PciSandboxSnapshotPayload {
|
|
84
|
+
response: unknown;
|
|
85
|
+
state?: unknown;
|
|
86
|
+
}
|
|
87
|
+
/** runner → host: the module registered. */
|
|
88
|
+
export interface PciSandboxModuleLoadedPayload {
|
|
89
|
+
typeIdentifier: string;
|
|
90
|
+
}
|
|
91
|
+
/** runner → host: module load or registration failed. */
|
|
92
|
+
export interface PciSandboxModuleErrorPayload {
|
|
93
|
+
message: string;
|
|
94
|
+
}
|
|
95
|
+
/** runner → host: `getInstance` returned. */
|
|
96
|
+
export interface PciSandboxInstanceReadyPayload extends PciSandboxSnapshotPayload {
|
|
97
|
+
}
|
|
98
|
+
/** runner → host: `getInstance` threw. */
|
|
99
|
+
export interface PciSandboxInstanceErrorPayload {
|
|
100
|
+
message: string;
|
|
101
|
+
}
|
|
102
|
+
/** runner → host: the module called `onready`/`ondone`. */
|
|
103
|
+
export interface PciSandboxLifecyclePayload extends PciSandboxSnapshotPayload {
|
|
104
|
+
/** The state argument the module passed, if any. */
|
|
105
|
+
state?: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** runner → host: poll or lifecycle observed a changed read. */
|
|
108
|
+
export interface PciSandboxResponseChangePayload extends PciSandboxSnapshotPayload {
|
|
109
|
+
}
|
|
110
|
+
/** runner → host: the interaction's content resized. */
|
|
111
|
+
export interface PciSandboxResizePayload {
|
|
112
|
+
height: number;
|
|
113
|
+
}
|
|
114
|
+
export type PciSandboxMessage = PciSandboxEnvelope<'runner-ready', PciSandboxRunnerReadyPayload> | PciSandboxEnvelope<'hello', PciSandboxHelloPayload> | PciSandboxEnvelope<'init', PciSandboxInitPayload> | PciSandboxEnvelope<'instantiate', PciSandboxInstantiatePayload> | PciSandboxEnvelope<'set-enabled', PciSandboxSetEnabledPayload> | PciSandboxEnvelope<'teardown-instance', Record<string, never>> | PciSandboxEnvelope<'dispose', Record<string, never>> | PciSandboxEnvelope<'module-loaded', PciSandboxModuleLoadedPayload> | PciSandboxEnvelope<'module-error', PciSandboxModuleErrorPayload> | PciSandboxEnvelope<'instance-ready', PciSandboxInstanceReadyPayload> | PciSandboxEnvelope<'instance-error', PciSandboxInstanceErrorPayload> | PciSandboxEnvelope<'ready', PciSandboxLifecyclePayload> | PciSandboxEnvelope<'done', PciSandboxLifecyclePayload> | PciSandboxEnvelope<'response-change', PciSandboxResponseChangePayload> | PciSandboxEnvelope<'resize', PciSandboxResizePayload>;
|
|
115
|
+
export declare function createSandboxEnvelope<TType extends PciSandboxMessageType, TPayload>(type: TType, payload: TPayload): PciSandboxEnvelope<TType, TPayload>;
|
|
116
|
+
/** Shallow envelope check; payload fields are validated where they are used. */
|
|
117
|
+
export declare function isPciSandboxEnvelope(value: unknown): value is PciSandboxEnvelope;
|