@pie-qti/item-player 0.1.27 → 1.0.0-beta.0
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-D-kJi_w9.js} +3211 -2125
- package/dist/element-class-D-kJi_w9.js.map +1 -0
- package/dist/element-class.js +1 -1
- package/dist/element.js +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 +6 -6
- package/dist/element-class-BzATCyhV.js.map +0 -1
|
@@ -41,15 +41,15 @@ function parseAllowlistUrl(kind, value) {
|
|
|
41
41
|
* Non-http(s) URLs are always refused, which rules out `data:`, `blob:` and
|
|
42
42
|
* `javascript:` module paths regardless of configuration.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
/** Parse and normalize an allow-list, refusing an empty one as a configuration error. */
|
|
45
|
+
function buildAllowlist(options) {
|
|
45
46
|
const origins = (options.allowedOrigins ?? []).map((origin) => parseAllowlistUrl('origin', origin).origin);
|
|
46
47
|
const prefixes = (options.allowedPathPrefixes ?? []).map((prefix) => parseAllowlistUrl('path prefix', prefix).href);
|
|
47
48
|
if (origins.length === 0 && prefixes.length === 0) {
|
|
48
|
-
throw new Error('
|
|
49
|
+
throw new Error('PCI allow-list requires allowedOrigins or allowedPathPrefixes; ' +
|
|
49
50
|
'an empty allow-list would refuse every module');
|
|
50
51
|
}
|
|
51
|
-
const
|
|
52
|
-
return async (resolvedUrl, context) => {
|
|
52
|
+
const check = (resolvedUrl) => {
|
|
53
53
|
let url;
|
|
54
54
|
try {
|
|
55
55
|
url = new URL(resolvedUrl);
|
|
@@ -66,6 +66,45 @@ export function createAllowlistPciModuleResolver(options) {
|
|
|
66
66
|
if (prefixes.length > 0 && !prefixes.some((prefix) => url.href.startsWith(prefix))) {
|
|
67
67
|
throw new PciModuleNotAllowedError(resolvedUrl, 'no allow-listed path prefix matches');
|
|
68
68
|
}
|
|
69
|
+
return url;
|
|
70
|
+
};
|
|
71
|
+
return { check };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Build a `modulePolicy` — the sandboxed engine's variant of the allow-list
|
|
75
|
+
* resolver. It applies exactly the same origin/prefix/scheme checks but never
|
|
76
|
+
* imports anything: the module is not evaluated in the page, so the policy only
|
|
77
|
+
* decides whether its URL may be handed to the runner frame.
|
|
78
|
+
*/
|
|
79
|
+
export function createAllowlistPciModulePolicy(options) {
|
|
80
|
+
const { check } = buildAllowlist(options);
|
|
81
|
+
return (resolvedUrl) => {
|
|
82
|
+
check(resolvedUrl);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a `moduleResolver` that imports PCI modules only from an explicit
|
|
87
|
+
* allow-list.
|
|
88
|
+
*
|
|
89
|
+
* PCI code executes with the authority of the realm that imports it, so the
|
|
90
|
+
* player never resolves an authored path on its own. This factory does not
|
|
91
|
+
* remove that gate: a host still has to pass the returned resolver as
|
|
92
|
+
* `PciConfiguration.moduleResolver`, and doing so remains a trust decision. It
|
|
93
|
+
* exists so hosts opt into a reviewed check rather than writing the
|
|
94
|
+
* security-critical part themselves.
|
|
95
|
+
*
|
|
96
|
+
* At least one of `allowedOrigins` or `allowedPathPrefixes` must be non-empty;
|
|
97
|
+
* an empty allow-list would deny everything and is treated as a configuration
|
|
98
|
+
* error rather than silently disabling PCI. When both are given, both must match.
|
|
99
|
+
*
|
|
100
|
+
* Non-http(s) URLs are always refused, which rules out `data:`, `blob:` and
|
|
101
|
+
* `javascript:` module paths regardless of configuration.
|
|
102
|
+
*/
|
|
103
|
+
export function createAllowlistPciModuleResolver(options) {
|
|
104
|
+
const { check } = buildAllowlist(options);
|
|
105
|
+
const importModule = options.importModule ?? ((resolvedUrl) => import(/* @vite-ignore */ resolvedUrl));
|
|
106
|
+
return async (resolvedUrl, context) => {
|
|
107
|
+
const url = check(resolvedUrl);
|
|
69
108
|
return importModule(url.href, context);
|
|
70
109
|
};
|
|
71
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowlistResolver.js","sourceRoot":"","sources":["../../src/pci/allowlistResolver.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAClD,YACiB,WAAmB,EACnB,MAAc;QAE9B,KAAK,CAAC,eAAe,WAAW,qBAAqB,MAAM,EAAE,CAAC,CAAC;QAH/C,gBAAW,GAAX,WAAW,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAQ;QAG9B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;
|
|
1
|
+
{"version":3,"file":"allowlistResolver.js","sourceRoot":"","sources":["../../src/pci/allowlistResolver.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAClD,YACiB,WAAmB,EACnB,MAAc;QAE9B,KAAK,CAAC,eAAe,WAAW,qBAAqB,MAAM,EAAE,CAAC,CAAC;QAH/C,gBAAW,GAAX,WAAW,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAQ;QAG9B,IAAI,CAAC,IAAI,GA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G,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,YAAY,GACjB,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,WAAmB,EAAE,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;IAE3F,OAAO,KAAK,EAAE,WAAmB,EAAE,OAAmC,EAAE,EAAE;QACzE,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;QAC/B,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { PciModulePolicy, PciModuleResolutionContext, PciModuleResolver } from './types.js';\n\n/**\n * Raised when an authored PCI module path falls outside the configured allow-list.\n */\nexport class PciModuleNotAllowedError extends Error {\n\tconstructor(\n\t\tpublic readonly resolvedUrl: string,\n\t\tpublic readonly reason: string\n\t) {\n\t\tsuper(`PCI module '${resolvedUrl}' is not allowed: ${reason}`);\n\t\tthis.name = 'PciModuleNotAllowedError';\n\t}\n}\n\nexport interface AllowlistPciResolverOptions {\n\t/**\n\t * Origins permitted to serve PCI modules, compared against `URL.origin`\n\t * (for example `https://cdn.example.com`).\n\t */\n\tallowedOrigins?: readonly string[];\n\t/**\n\t * Absolute URL prefixes permitted. Checked against the normalized href, so a\n\t * traversal such as `/pci/../../evil.js` cannot escape its prefix.\n\t */\n\tallowedPathPrefixes?: readonly string[];\n\t/**\n\t * Module import hook. Defaults to a dynamic `import()`. Supply a different\n\t * loader to import through a package reader, a cache, or a test double.\n\t */\n\timportModule?: (resolvedUrl: string, context: PciModuleResolutionContext) => Promise<unknown>;\n}\n\n/** Options for {@link createAllowlistPciModulePolicy}; no import hook exists. */\nexport type AllowlistPciPolicyOptions = Omit<AllowlistPciResolverOptions, 'importModule'>;\n\n/** Parse one allow-list entry, rejecting anything not an absolute http(s) URL. */\nfunction parseAllowlistUrl(kind: 'origin' | 'path prefix', value: string): URL {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\tthrow new Error(`PCI allow-list ${kind} must be an absolute URL: '${value}'`);\n\t}\n\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\tthrow new Error(`PCI allow-list ${kind} must be http(s): '${value}'`);\n\t}\n\treturn url;\n}\n\n/**\n * Build a `moduleResolver` that imports PCI modules only from an explicit\n * allow-list.\n *\n * PCI code executes with the authority of the realm that imports it, so the\n * player never resolves an authored path on its own. This factory does not\n * remove that gate: a host still has to pass the returned resolver as\n * `PciConfiguration.moduleResolver`, and doing so remains a trust decision. It\n * exists so hosts opt into a reviewed check rather than writing the\n * security-critical part themselves.\n *\n * At least one of `allowedOrigins` or `allowedPathPrefixes` must be non-empty;\n * an empty allow-list would deny everything and is treated as a configuration\n * error rather than silently disabling PCI. When both are given, both must match.\n *\n * Non-http(s) URLs are always refused, which rules out `data:`, `blob:` and\n * `javascript:` module paths regardless of configuration.\n */\n/** Parse and normalize an allow-list, refusing an empty one as a configuration error. */\nfunction buildAllowlist(options: AllowlistPciPolicyOptions) {\n\tconst origins = (options.allowedOrigins ?? []).map(\n\t\t(origin) => parseAllowlistUrl('origin', origin).origin\n\t);\n\tconst prefixes = (options.allowedPathPrefixes ?? []).map(\n\t\t(prefix) => parseAllowlistUrl('path prefix', prefix).href\n\t);\n\tif (origins.length === 0 && prefixes.length === 0) {\n\t\tthrow new Error(\n\t\t\t'PCI allow-list requires allowedOrigins or allowedPathPrefixes; ' +\n\t\t\t\t'an empty allow-list would refuse every module'\n\t\t);\n\t}\n\tconst check = (resolvedUrl: string): URL => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(resolvedUrl);\n\t\t} catch {\n\t\t\tthrow new PciModuleNotAllowedError(\n\t\t\t\tresolvedUrl,\n\t\t\t\t'the authored path did not resolve to an absolute URL; set PciConfiguration.baseUrl'\n\t\t\t);\n\t\t}\n\t\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\t\tthrow new PciModuleNotAllowedError(resolvedUrl, `scheme '${url.protocol}' is not http(s)`);\n\t\t}\n\t\tif (origins.length > 0 && !origins.includes(url.origin)) {\n\t\t\tthrow new PciModuleNotAllowedError(resolvedUrl, `origin '${url.origin}' is not allow-listed`);\n\t\t}\n\t\tif (prefixes.length > 0 && !prefixes.some((prefix) => url.href.startsWith(prefix))) {\n\t\t\tthrow new PciModuleNotAllowedError(resolvedUrl, 'no allow-listed path prefix matches');\n\t\t}\n\t\treturn url;\n\t};\n\treturn { check };\n}\n\n/**\n * Build a `modulePolicy` — the sandboxed engine's variant of the allow-list\n * resolver. It applies exactly the same origin/prefix/scheme checks but never\n * imports anything: the module is not evaluated in the page, so the policy only\n * decides whether its URL may be handed to the runner frame.\n */\nexport function createAllowlistPciModulePolicy(\n\toptions: AllowlistPciPolicyOptions\n): PciModulePolicy {\n\tconst { check } = buildAllowlist(options);\n\treturn (resolvedUrl: string) => {\n\t\tcheck(resolvedUrl);\n\t};\n}\n\n/**\n * Build a `moduleResolver` that imports PCI modules only from an explicit\n * allow-list.\n *\n * PCI code executes with the authority of the realm that imports it, so the\n * player never resolves an authored path on its own. This factory does not\n * remove that gate: a host still has to pass the returned resolver as\n * `PciConfiguration.moduleResolver`, and doing so remains a trust decision. It\n * exists so hosts opt into a reviewed check rather than writing the\n * security-critical part themselves.\n *\n * At least one of `allowedOrigins` or `allowedPathPrefixes` must be non-empty;\n * an empty allow-list would deny everything and is treated as a configuration\n * error rather than silently disabling PCI. When both are given, both must match.\n *\n * Non-http(s) URLs are always refused, which rules out `data:`, `blob:` and\n * `javascript:` module paths regardless of configuration.\n */\nexport function createAllowlistPciModuleResolver(\n\toptions: AllowlistPciResolverOptions\n): PciModuleResolver {\n\tconst { check } = buildAllowlist(options);\n\tconst importModule =\n\t\toptions.importModule ?? ((resolvedUrl: string) => import(/* @vite-ignore */ resolvedUrl));\n\n\treturn async (resolvedUrl: string, context: PciModuleResolutionContext) => {\n\t\tconst url = check(resolvedUrl);\n\t\treturn importModule(url.href, context);\n\t};\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PciResolutionConfig } from './resolutionConfig.js';
|
|
2
|
+
export interface AmdLoaderOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
config: PciResolutionConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Evaluate one module URL through the host resolver. The module registers
|
|
7
|
+
* against `qtiCustomInteractionContext` (or defines itself) as a side effect.
|
|
8
|
+
*/
|
|
9
|
+
evaluate(resolvedUrl: string, authoredPath: string): Promise<unknown>;
|
|
10
|
+
/** Resolve a package-relative path to a loadable URL. */
|
|
11
|
+
resolveUrl(path: string): string;
|
|
12
|
+
}
|
|
13
|
+
export interface AmdLoader {
|
|
14
|
+
/** Swap the page's `define`/`require` for the loader's. */
|
|
15
|
+
install(): void;
|
|
16
|
+
/** Restore whatever `define`/`require` the page had. */
|
|
17
|
+
dispose(): void;
|
|
18
|
+
/** Evaluate the given module ids and their dependency trees. */
|
|
19
|
+
load(entryIds: string[]): Promise<void>;
|
|
20
|
+
/** Feed an already-known id → path binding, as authored `qti-interaction-module` entries do. */
|
|
21
|
+
addPaths(paths: Record<string, string>): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createAmdLoader(options: AmdLoaderOptions): AmdLoader;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const SPECIAL_DEPENDENCIES = new Set(['require', 'module', 'exports']);
|
|
2
|
+
export function createAmdLoader(options) {
|
|
3
|
+
const { config } = options;
|
|
4
|
+
const modules = new Map();
|
|
5
|
+
const inFlight = new Map();
|
|
6
|
+
const defineCompletions = new Map();
|
|
7
|
+
let defining;
|
|
8
|
+
/** Evaluations run one at a time, so an anonymous define lands on its own file. */
|
|
9
|
+
let evaluationQueue = Promise.resolve();
|
|
10
|
+
let installed = false;
|
|
11
|
+
let previousDefine;
|
|
12
|
+
let previousRequire;
|
|
13
|
+
let hadPreviousDefine = false;
|
|
14
|
+
let hadPreviousRequire = false;
|
|
15
|
+
// Paths from the resolution config, overlaid with authored module entries.
|
|
16
|
+
const paths = { ...config.paths };
|
|
17
|
+
function resolveIdPath(id) {
|
|
18
|
+
const mapped = paths[id];
|
|
19
|
+
const path = mapped ?? id;
|
|
20
|
+
const withArgs = config.urlArgs ? `${path}${path.includes('?') ? '&' : '?'}${config.urlArgs}` : path;
|
|
21
|
+
return options.resolveUrl(withArgs);
|
|
22
|
+
}
|
|
23
|
+
function normalizeDefine(args) {
|
|
24
|
+
let id;
|
|
25
|
+
let deps = [];
|
|
26
|
+
let rest = args;
|
|
27
|
+
if (typeof rest[0] === 'string') {
|
|
28
|
+
id = rest[0];
|
|
29
|
+
rest = rest.slice(1);
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(rest[0])) {
|
|
32
|
+
deps = rest[0].filter((dep) => typeof dep === 'string');
|
|
33
|
+
rest = rest.slice(1);
|
|
34
|
+
}
|
|
35
|
+
const factory = rest[0];
|
|
36
|
+
return { ...(id ? { id } : {}), deps, ...(factory !== undefined ? { factory } : {}) };
|
|
37
|
+
}
|
|
38
|
+
function define(...args) {
|
|
39
|
+
const normalized = normalizeDefine(args);
|
|
40
|
+
const id = normalized.id ?? defining;
|
|
41
|
+
if (!id) {
|
|
42
|
+
throw new Error('AMD define() without a module id and no module currently loading');
|
|
43
|
+
}
|
|
44
|
+
if (modules.has(id) || defineCompletions.has(id)) {
|
|
45
|
+
// RequireJS throws on a second definition of the same id.
|
|
46
|
+
throw new Error(`AMD module '${id}' is already defined`);
|
|
47
|
+
}
|
|
48
|
+
const completion = (async () => {
|
|
49
|
+
const exportsObject = {};
|
|
50
|
+
const usesExports = normalized.deps.includes('exports');
|
|
51
|
+
const values = await Promise.all(normalized.deps.map(async (dep) => {
|
|
52
|
+
if (dep === 'exports')
|
|
53
|
+
return exportsObject;
|
|
54
|
+
if (dep === 'module')
|
|
55
|
+
return { id, config: () => config };
|
|
56
|
+
if (dep === 'require')
|
|
57
|
+
return localRequire;
|
|
58
|
+
return loadModule(dep);
|
|
59
|
+
}));
|
|
60
|
+
if (typeof normalized.factory === 'function') {
|
|
61
|
+
const value = normalized.factory(...values);
|
|
62
|
+
if (!usesExports && value !== undefined)
|
|
63
|
+
modules.set(id, value);
|
|
64
|
+
}
|
|
65
|
+
else if (normalized.factory !== undefined) {
|
|
66
|
+
modules.set(id, normalized.factory);
|
|
67
|
+
}
|
|
68
|
+
if (usesExports)
|
|
69
|
+
modules.set(id, exportsObject);
|
|
70
|
+
})();
|
|
71
|
+
defineCompletions.set(id, completion);
|
|
72
|
+
completion.finally(() => defineCompletions.delete(id));
|
|
73
|
+
}
|
|
74
|
+
function applyShim(id) {
|
|
75
|
+
const shim = config.shim[id];
|
|
76
|
+
if (!shim)
|
|
77
|
+
return;
|
|
78
|
+
if (shim.exports && typeof globalThis === 'object') {
|
|
79
|
+
modules.set(id, globalThis[shim.exports]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function loadModule(id) {
|
|
83
|
+
if (modules.has(id))
|
|
84
|
+
return Promise.resolve(modules.get(id));
|
|
85
|
+
const pending = inFlight.get(id);
|
|
86
|
+
if (pending)
|
|
87
|
+
return pending.then(() => modules.get(id));
|
|
88
|
+
const load = (async () => {
|
|
89
|
+
if (!defineCompletions.has(id)) {
|
|
90
|
+
// Serialize against other evaluations, and claim the anonymous-define
|
|
91
|
+
// slot inside the queued task: sibling loads may have started already.
|
|
92
|
+
const run = evaluationQueue.then(() => {
|
|
93
|
+
defining = id;
|
|
94
|
+
return options.evaluate(resolveIdPath(id), paths[id] ?? id);
|
|
95
|
+
}, () => {
|
|
96
|
+
defining = id;
|
|
97
|
+
return options.evaluate(resolveIdPath(id), paths[id] ?? id);
|
|
98
|
+
});
|
|
99
|
+
evaluationQueue = run.then(() => {
|
|
100
|
+
if (defining === id)
|
|
101
|
+
defining = undefined;
|
|
102
|
+
}, () => {
|
|
103
|
+
if (defining === id)
|
|
104
|
+
defining = undefined;
|
|
105
|
+
});
|
|
106
|
+
await run;
|
|
107
|
+
// The define() call, if any, ran synchronously inside the evaluation.
|
|
108
|
+
if (!defineCompletions.has(id)) {
|
|
109
|
+
// Not an AMD module: a plain script, or a shimmed global.
|
|
110
|
+
await Promise.all((config.shim[id]?.deps ?? []).map((dep) => loadModule(dep)));
|
|
111
|
+
applyShim(id);
|
|
112
|
+
if (!modules.has(id))
|
|
113
|
+
modules.set(id, undefined);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await defineCompletions.get(id);
|
|
117
|
+
})();
|
|
118
|
+
// The dedupe entry is always handled, so a failed load is not an
|
|
119
|
+
// unhandled rejection, and it clears once it settles.
|
|
120
|
+
const settled = load.then(() => undefined, () => undefined);
|
|
121
|
+
inFlight.set(id, settled);
|
|
122
|
+
void settled.finally(() => {
|
|
123
|
+
if (inFlight.get(id) === settled)
|
|
124
|
+
inFlight.delete(id);
|
|
125
|
+
});
|
|
126
|
+
return load.then(() => modules.get(id));
|
|
127
|
+
}
|
|
128
|
+
function localRequire(...args) {
|
|
129
|
+
const first = args[0];
|
|
130
|
+
if (typeof first === 'string') {
|
|
131
|
+
// Synchronous require: only already-evaluated modules answer.
|
|
132
|
+
if (!modules.has(first)) {
|
|
133
|
+
throw new Error(`AMD sync require of '${first}' before the module was loaded`);
|
|
134
|
+
}
|
|
135
|
+
return modules.get(first);
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(first)) {
|
|
138
|
+
const ready = typeof args[1] === 'function' ? args[1] : undefined;
|
|
139
|
+
const deps = first.filter((dep) => typeof dep === 'string');
|
|
140
|
+
const result = Promise.all(deps.map((dep) => loadModule(dep)));
|
|
141
|
+
if (ready)
|
|
142
|
+
void result.then((values) => ready(...values));
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
// require.config({...}): merge runtime configuration.
|
|
146
|
+
if (typeof first === 'object' && first !== null) {
|
|
147
|
+
const merged = first;
|
|
148
|
+
Object.assign(paths, merged.paths ?? {});
|
|
149
|
+
Object.assign(config.shim, merged.shim ?? {});
|
|
150
|
+
}
|
|
151
|
+
return localRequire;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
install() {
|
|
155
|
+
if (installed)
|
|
156
|
+
return;
|
|
157
|
+
installed = true;
|
|
158
|
+
previousDefine = globalThis.define;
|
|
159
|
+
previousRequire = globalThis.require;
|
|
160
|
+
hadPreviousDefine = 'define' in globalThis;
|
|
161
|
+
hadPreviousRequire = 'require' in globalThis;
|
|
162
|
+
const amdFlag = { amd: {} };
|
|
163
|
+
const defineFn = define;
|
|
164
|
+
defineFn.amd = amdFlag;
|
|
165
|
+
globalThis.define = defineFn;
|
|
166
|
+
globalThis.require = localRequire;
|
|
167
|
+
},
|
|
168
|
+
dispose() {
|
|
169
|
+
if (!installed)
|
|
170
|
+
return;
|
|
171
|
+
installed = false;
|
|
172
|
+
const host = globalThis;
|
|
173
|
+
if (hadPreviousDefine)
|
|
174
|
+
host.define = previousDefine;
|
|
175
|
+
else
|
|
176
|
+
delete host.define;
|
|
177
|
+
if (hadPreviousRequire)
|
|
178
|
+
host.require = previousRequire;
|
|
179
|
+
else
|
|
180
|
+
delete host.require;
|
|
181
|
+
},
|
|
182
|
+
addPaths(authored) {
|
|
183
|
+
Object.assign(paths, authored);
|
|
184
|
+
},
|
|
185
|
+
async load(entryIds) {
|
|
186
|
+
await Promise.all(entryIds.map((id) => loadModule(id)));
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=amdLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amdLoader.js","sourceRoot":"","sources":["../../src/pci/amdLoader.ts"],"names":[],"mappings":"AAiDA,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAEvE,MAAM,UAAU,eAAe,CAAC,OAAyB;IACxD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;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/**\n * A minimal AMD loader for PCI modules.\n *\n * QTI 3.0 specifies AMD as PCI's default module resolution: modules call\n * `define([deps], factory)` and dependencies are wired by module id through a\n * resolution config's `paths` map. The loader installs `define`/`require`\n * globals so an evaluated module's `define` lands here, resolves each\n * dependency id to a URL, and hands the URL to the host resolver — the trust\n * gate stays the resolver's; the loader only decides how dependencies wire up.\n *\n * Evaluation goes through the resolver, whose dynamic `import()` executes the\n * file with the loader's `define` visible on the global scope. `define`-style\n * files register exactly as they do under RequireJS; plain scripts contribute\n * nothing unless the resolution config's `shim` names a global to read.\n */\n\ntype Factory = ((...args: unknown[]) => unknown) | Record<string, unknown>;\n\nexport interface AmdLoaderOptions {\n\tbaseUrl: string;\n\tconfig: PciResolutionConfig;\n\t/**\n\t * Evaluate one module URL through the host resolver. The module registers\n\t * against `qtiCustomInteractionContext` (or defines itself) as a side effect.\n\t */\n\tevaluate(resolvedUrl: string, authoredPath: string): Promise<unknown>;\n\t/** Resolve a package-relative path to a loadable URL. */\n\tresolveUrl(path: string): string;\n}\n\nexport interface AmdLoader {\n\t/** Swap the page's `define`/`require` for the loader's. */\n\tinstall(): void;\n\t/** Restore whatever `define`/`require` the page had. */\n\tdispose(): void;\n\t/** Evaluate the given module ids and their dependency trees. */\n\tload(entryIds: string[]): Promise<void>;\n\t/** Feed an already-known id → path binding, as authored `qti-interaction-module` entries do. */\n\taddPaths(paths: Record<string, string>): void;\n}\n\ninterface NormalizedDefine {\n\tid?: string;\n\tdeps: string[];\n\tfactory?: Factory;\n}\n\nconst SPECIAL_DEPENDENCIES = new Set(['require', 'module', 'exports']);\n\nexport function createAmdLoader(options: AmdLoaderOptions): AmdLoader {\n\tconst { config } = options;\n\tconst modules = new Map<string, unknown>();\n\tconst inFlight = new Map<string, Promise<void>>();\n\tconst defineCompletions = new Map<string, Promise<void>>();\n\tlet defining: string | undefined;\n\t/** Evaluations run one at a time, so an anonymous define lands on its own file. */\n\tlet evaluationQueue: Promise<unknown> = Promise.resolve();\n\tlet installed = false;\n\tlet previousDefine: unknown;\n\tlet previousRequire: unknown;\n\tlet hadPreviousDefine = false;\n\tlet hadPreviousRequire = false;\n\n\t// Paths from the resolution config, overlaid with authored module entries.\n\tconst paths: Record<string, string> = { ...config.paths };\n\n\tfunction resolveIdPath(id: string): string {\n\t\tconst mapped = paths[id];\n\t\tconst path = mapped ?? id;\n\t\tconst withArgs = config.urlArgs ? `${path}${path.includes('?') ? '&' : '?'}${config.urlArgs}` : path;\n\t\treturn options.resolveUrl(withArgs);\n\t}\n\n\tfunction normalizeDefine(args: unknown[]): NormalizedDefine {\n\t\tlet id: string | undefined;\n\t\tlet deps: string[] = [];\n\t\tlet rest = args;\n\t\tif (typeof rest[0] === 'string') {\n\t\t\tid = rest[0];\n\t\t\trest = rest.slice(1);\n\t\t}\n\t\tif (Array.isArray(rest[0])) {\n\t\t\tdeps = (rest[0] as unknown[]).filter((dep): dep is string => typeof dep === 'string');\n\t\t\trest = rest.slice(1);\n\t\t}\n\t\tconst factory = rest[0] as Factory | undefined;\n\t\treturn { ...(id ? { id } : {}), deps, ...(factory !== undefined ? { factory } : {}) };\n\t}\n\n\tfunction define(...args: unknown[]): void {\n\t\tconst normalized = normalizeDefine(args);\n\t\tconst id = normalized.id ?? defining;\n\t\tif (!id) {\n\t\t\tthrow new Error('AMD define() without a module id and no module currently loading');\n\t\t}\n\t\tif (modules.has(id) || defineCompletions.has(id)) {\n\t\t\t// RequireJS throws on a second definition of the same id.\n\t\t\tthrow new Error(`AMD module '${id}' is already defined`);\n\t\t}\n\t\tconst completion = (async () => {\n\t\t\tconst exportsObject: Record<string, unknown> = {};\n\t\t\tconst usesExports = normalized.deps.includes('exports');\n\t\t\tconst values = await Promise.all(\n\t\t\t\tnormalized.deps.map(async (dep) => {\n\t\t\t\t\tif (dep === 'exports') return exportsObject;\n\t\t\t\t\tif (dep === 'module') return { id, config: () => config };\n\t\t\t\t\tif (dep === 'require') return localRequire;\n\t\t\t\t\treturn loadModule(dep);\n\t\t\t\t})\n\t\t\t);\n\t\t\tif (typeof normalized.factory === 'function') {\n\t\t\t\tconst value = (normalized.factory as (...args: unknown[]) => unknown)(...values);\n\t\t\t\tif (!usesExports && value !== undefined) modules.set(id, value);\n\t\t\t} else if (normalized.factory !== undefined) {\n\t\t\t\tmodules.set(id, normalized.factory);\n\t\t\t}\n\t\t\tif (usesExports) modules.set(id, exportsObject);\n\t\t})();\n\t\tdefineCompletions.set(id, completion);\n\t\tcompletion.finally(() => defineCompletions.delete(id));\n\t}\n\n\tfunction applyShim(id: string): void {\n\t\tconst shim = config.shim[id];\n\t\tif (!shim) return;\n\t\tif (shim.exports && typeof globalThis === 'object') {\n\t\t\tmodules.set(id, (globalThis as Record<string, unknown>)[shim.exports]);\n\t\t}\n\t}\n\n\tfunction loadModule(id: string): Promise<unknown> {\n\t\tif (modules.has(id)) return Promise.resolve(modules.get(id));\n\t\tconst pending = inFlight.get(id);\n\t\tif (pending) return pending.then(() => modules.get(id));\n\t\tconst load = (async () => {\n\t\t\tif (!defineCompletions.has(id)) {\n\t\t\t\t// Serialize against other evaluations, and claim the anonymous-define\n\t\t\t\t// slot inside the queued task: sibling loads may have started already.\n\t\t\t\tconst run = evaluationQueue.then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdefining = id;\n\t\t\t\t\t\treturn options.evaluate(resolveIdPath(id), paths[id] ?? id);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdefining = id;\n\t\t\t\t\t\treturn options.evaluate(resolveIdPath(id), paths[id] ?? id);\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tevaluationQueue = run.then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (defining === id) defining = undefined;\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (defining === id) defining = undefined;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tawait run;\n\t\t\t\t// The define() call, if any, ran synchronously inside the evaluation.\n\t\t\t\tif (!defineCompletions.has(id)) {\n\t\t\t\t\t// Not an AMD module: a plain script, or a shimmed global.\n\t\t\t\t\tawait Promise.all((config.shim[id]?.deps ?? []).map((dep) => loadModule(dep)));\n\t\t\t\t\tapplyShim(id);\n\t\t\t\t\tif (!modules.has(id)) modules.set(id, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait defineCompletions.get(id);\n\t\t})();\n\t\t// The dedupe entry is always handled, so a failed load is not an\n\t\t// unhandled rejection, and it clears once it settles.\n\t\tconst settled = load.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined\n\t\t);\n\t\tinFlight.set(id, settled);\n\t\tvoid settled.finally(() => {\n\t\t\tif (inFlight.get(id) === settled) inFlight.delete(id);\n\t\t});\n\t\treturn load.then(() => modules.get(id));\n\t}\n\n\tfunction localRequire(...args: unknown[]): unknown {\n\t\tconst first = args[0];\n\t\tif (typeof first === 'string') {\n\t\t\t// Synchronous require: only already-evaluated modules answer.\n\t\t\tif (!modules.has(first)) {\n\t\t\t\tthrow new Error(`AMD sync require of '${first}' before the module was loaded`);\n\t\t\t}\n\t\t\treturn modules.get(first);\n\t\t}\n\t\tif (Array.isArray(first)) {\n\t\t\tconst ready = typeof args[1] === 'function' ? (args[1] as (...values: unknown[]) => void) : undefined;\n\t\t\tconst deps = (first as unknown[]).filter((dep): dep is string => typeof dep === 'string');\n\t\t\tconst result = Promise.all(deps.map((dep) => loadModule(dep)));\n\t\t\tif (ready) void result.then((values) => ready(...values));\n\t\t\treturn result;\n\t\t}\n\t\t// require.config({...}): merge runtime configuration.\n\t\tif (typeof first === 'object' && first !== null) {\n\t\t\tconst merged = first as Partial<PciResolutionConfig>;\n\t\t\tObject.assign(paths, merged.paths ?? {});\n\t\t\tObject.assign(config.shim, merged.shim ?? {});\n\t\t}\n\t\treturn localRequire;\n\t}\n\n\treturn {\n\t\tinstall() {\n\t\t\tif (installed) return;\n\t\t\tinstalled = true;\n\t\t\tpreviousDefine = (globalThis as Record<string, unknown>).define;\n\t\t\tpreviousRequire = (globalThis as Record<string, unknown>).require;\n\t\t\thadPreviousDefine = 'define' in globalThis;\n\t\t\thadPreviousRequire = 'require' in globalThis;\n\t\t\tconst amdFlag = { amd: {} };\n\t\t\tconst defineFn = define as ((...args: unknown[]) => void) & { amd?: unknown };\n\t\t\tdefineFn.amd = amdFlag;\n\t\t\t(globalThis as Record<string, unknown>).define = defineFn;\n\t\t\t(globalThis as Record<string, unknown>).require = localRequire;\n\t\t},\n\n\t\tdispose() {\n\t\t\tif (!installed) return;\n\t\t\tinstalled = false;\n\t\t\tconst host = globalThis as Record<string, unknown>;\n\t\t\tif (hadPreviousDefine) host.define = previousDefine;\n\t\t\telse delete host.define;\n\t\t\tif (hadPreviousRequire) host.require = previousRequire;\n\t\t\telse delete host.require;\n\t\t},\n\n\t\taddPaths(authored: Record<string, string>) {\n\t\t\tObject.assign(paths, authored);\n\t\t},\n\n\t\tasync load(entryIds: string[]) {\n\t\t\tawait Promise.all(entryIds.map((id) => loadModule(id)));\n\t\t},\n\t};\n}\n"]}
|
package/dist/pci/index.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
export { PciHost } from './PciHost.js';
|
|
2
|
-
export { createAllowlistPciModuleResolver, PciModuleNotAllowedError, } from './allowlistResolver.js';
|
|
3
|
-
export type { AllowlistPciResolverOptions } from './allowlistResolver.js';
|
|
4
|
-
export
|
|
2
|
+
export { createAllowlistPciModuleResolver, createAllowlistPciModulePolicy, PciModuleNotAllowedError, } from './allowlistResolver.js';
|
|
3
|
+
export type { AllowlistPciPolicyOptions, AllowlistPciResolverOptions, } from './allowlistResolver.js';
|
|
4
|
+
export { getSharedPciRegistry, installPciRegistry, PCI_REGISTRY_GLOBAL, } from './registry.js';
|
|
5
|
+
export { createAmdLoader } from './amdLoader.js';
|
|
6
|
+
export type { AmdLoader, AmdLoaderOptions } from './amdLoader.js';
|
|
7
|
+
export { DEFAULT_RESOLUTION_CONFIG_PATHS, emptyResolutionConfig, parseModuleResolutionConfig, } from './resolutionConfig.js';
|
|
8
|
+
export type { PciResolutionConfig, PciResolutionShim } from './resolutionConfig.js';
|
|
9
|
+
export { createIframeFrameConnector } from './sandbox/iframeConnector.js';
|
|
10
|
+
export { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';
|
|
11
|
+
export { PCI_SANDBOX_PROTOCOL, PCI_SANDBOX_PROTOCOL_VERSION, createSandboxEnvelope, isPciSandboxEnvelope, } from './sandbox/protocol.js';
|
|
12
|
+
export type { PciSandboxEnvelope, PciSandboxHostToRunnerType, PciSandboxInitPayload, PciSandboxInstantiatePayload, PciSandboxMessage, PciSandboxMessageType, PciSandboxModuleEntryPayload, PciSandboxProtocolVersion, PciSandboxRunnerToHostType, } from './sandbox/protocol.js';
|
|
13
|
+
export type { PciLoadContext, PciModuleSession } from './moduleSession.js';
|
|
14
|
+
export { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';
|
|
15
|
+
export type { ExtractedPci, PciConfiguration, PciCustomInteractionContext, PciFrameConnection, PciFrameConnector, PciHostController, PciHostOptions, PciInteractionStatus, PciModuleEntry, PciModulePathKind, PciModulePolicy, PciModuleResolutionContext, PciModuleResolver, PciRegistryObservation, PciResponseDeclarationInfo, PciSandboxConfiguration, QtiCustomInteractionRegistration, QtiPciConfiguration, QtiPciInstance, } from './types.js';
|
|
5
16
|
export { PciLoadError, PciModuleResolverRequiredError } from './types.js';
|
package/dist/pci/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { PciHost } from './PciHost.js';
|
|
2
|
-
export { createAllowlistPciModuleResolver, PciModuleNotAllowedError, } from './allowlistResolver.js';
|
|
2
|
+
export { createAllowlistPciModuleResolver, createAllowlistPciModulePolicy, PciModuleNotAllowedError, } from './allowlistResolver.js';
|
|
3
|
+
export { getSharedPciRegistry, installPciRegistry, PCI_REGISTRY_GLOBAL, } from './registry.js';
|
|
4
|
+
export { createAmdLoader } from './amdLoader.js';
|
|
5
|
+
export { DEFAULT_RESOLUTION_CONFIG_PATHS, emptyResolutionConfig, parseModuleResolutionConfig, } from './resolutionConfig.js';
|
|
6
|
+
export { createIframeFrameConnector } from './sandbox/iframeConnector.js';
|
|
7
|
+
export { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';
|
|
8
|
+
export { PCI_SANDBOX_PROTOCOL, PCI_SANDBOX_PROTOCOL_VERSION, createSandboxEnvelope, isPciSandboxEnvelope, } from './sandbox/protocol.js';
|
|
9
|
+
export { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';
|
|
3
10
|
export { PciLoadError, PciModuleResolverRequiredError } from './types.js';
|
|
4
11
|
//# sourceMappingURL=index.js.map
|
package/dist/pci/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pci/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,gCAAgC,EAChC,wBAAwB,GACxB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pci/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,gCAAgC,EAChC,8BAA8B,EAC9B,wBAAwB,GACxB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACN,+BAA+B,EAC/B,qBAAqB,EACrB,2BAA2B,GAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EACN,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,uBAAuB,CAAC;AAa/B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAsB9E,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { PciHost } from './PciHost.js';\nexport {\n\tcreateAllowlistPciModuleResolver,\n\tcreateAllowlistPciModulePolicy,\n\tPciModuleNotAllowedError,\n} from './allowlistResolver.js';\nexport type {\n\tAllowlistPciPolicyOptions,\n\tAllowlistPciResolverOptions,\n} from './allowlistResolver.js';\nexport {\n\tgetSharedPciRegistry,\n\tinstallPciRegistry,\n\tPCI_REGISTRY_GLOBAL,\n} from './registry.js';\nexport { createAmdLoader } from './amdLoader.js';\nexport type { AmdLoader, AmdLoaderOptions } from './amdLoader.js';\nexport {\n\tDEFAULT_RESOLUTION_CONFIG_PATHS,\n\temptyResolutionConfig,\n\tparseModuleResolutionConfig,\n} from './resolutionConfig.js';\nexport type { PciResolutionConfig, PciResolutionShim } from './resolutionConfig.js';\nexport { createIframeFrameConnector } from './sandbox/iframeConnector.js';\nexport { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';\nexport {\n\tPCI_SANDBOX_PROTOCOL,\n\tPCI_SANDBOX_PROTOCOL_VERSION,\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n} from './sandbox/protocol.js';\nexport type {\n\tPciSandboxEnvelope,\n\tPciSandboxHostToRunnerType,\n\tPciSandboxInitPayload,\n\tPciSandboxInstantiatePayload,\n\tPciSandboxMessage,\n\tPciSandboxMessageType,\n\tPciSandboxModuleEntryPayload,\n\tPciSandboxProtocolVersion,\n\tPciSandboxRunnerToHostType,\n} from './sandbox/protocol.js';\nexport type { PciLoadContext, PciModuleSession } from './moduleSession.js';\nexport { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';\nexport type {\n\tExtractedPci,\n\tPciConfiguration,\n\tPciCustomInteractionContext,\n\tPciFrameConnection,\n\tPciFrameConnector,\n\tPciHostController,\n\tPciHostOptions,\n\tPciInteractionStatus,\n\tPciModuleEntry,\n\tPciModulePathKind,\n\tPciModulePolicy,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tPciResponseDeclarationInfo,\n\tPciSandboxConfiguration,\n\tQtiCustomInteractionRegistration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './types.js';\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { QtiPciConfiguration, QtiPciInstance } from './types.js';
|
|
2
|
+
/** Identity of one `PciHost.load()` call, so a stale load can be detected. */
|
|
3
|
+
export interface PciLoadContext {
|
|
4
|
+
/** False once the host was destroyed or a newer load superseded this one. */
|
|
5
|
+
isCurrent(): boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* One module's execution backend beneath `PciHost`'s response-ownership state
|
|
9
|
+
* machine. Two implementations exist: the page realm, where the host resolver
|
|
10
|
+
* evaluates the module in-page, and the sandboxed engine, where the module runs
|
|
11
|
+
* in a cross-origin runner frame and every contract call crosses the bridge.
|
|
12
|
+
*
|
|
13
|
+
* The instantiation seam is the specified one — `getInstance`-shaped: state in,
|
|
14
|
+
* a `getResponse()`/`getState()` instance out, no setter. A sandboxed session
|
|
15
|
+
* returns a proxy whose reads answer from the bridge-maintained cache.
|
|
16
|
+
*/
|
|
17
|
+
export interface PciModuleSession {
|
|
18
|
+
/** Prepare/evaluate the module. Throws on failure, as `PciHost.load()` did. */
|
|
19
|
+
load(context: PciLoadContext): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Create the interaction instance inside `dom`, seeded with `state`.
|
|
22
|
+
* Synchronous from the host's side: a sandboxed session queues the bridge
|
|
23
|
+
* messages and the instance reports readiness asynchronously.
|
|
24
|
+
*/
|
|
25
|
+
instantiate(dom: HTMLElement, configuration: QtiPciConfiguration, state: unknown): QtiPciInstance | undefined;
|
|
26
|
+
/** Discard the instance; the session stays usable for a fresh `instantiate`. */
|
|
27
|
+
destroyInstance(instance: QtiPciInstance): void;
|
|
28
|
+
/** Final teardown of everything the session created. */
|
|
29
|
+
dispose(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Response/state pushes that arrive outside the `onready`/`ondone` lifecycle
|
|
32
|
+
* — the sandboxed engine's poll. The handler's `state` joins the host's
|
|
33
|
+
* instance-state; the response itself travels through the returned
|
|
34
|
+
* instance's cache, which the host reads with `getResponse()`.
|
|
35
|
+
*/
|
|
36
|
+
onRemoteReport?(handler: (report: {
|
|
37
|
+
state?: unknown;
|
|
38
|
+
}) => void): () => void;
|
|
39
|
+
/** Asynchronous failures that surface after `load()` resolved. */
|
|
40
|
+
onError?(handler: (error: Error) => void): () => void;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleSession.js","sourceRoot":"","sources":["../../src/pci/moduleSession.ts"],"names":[],"mappings":"","sourcesContent":["import type { QtiPciConfiguration, QtiPciInstance } from './types.js';\n\n/** Identity of one `PciHost.load()` call, so a stale load can be detected. */\nexport interface PciLoadContext {\n\t/** False once the host was destroyed or a newer load superseded this one. */\n\tisCurrent(): boolean;\n}\n\n/**\n * One module's execution backend beneath `PciHost`'s response-ownership state\n * machine. Two implementations exist: the page realm, where the host resolver\n * evaluates the module in-page, and the sandboxed engine, where the module runs\n * in a cross-origin runner frame and every contract call crosses the bridge.\n *\n * The instantiation seam is the specified one — `getInstance`-shaped: state in,\n * a `getResponse()`/`getState()` instance out, no setter. A sandboxed session\n * returns a proxy whose reads answer from the bridge-maintained cache.\n */\nexport interface PciModuleSession {\n\t/** Prepare/evaluate the module. Throws on failure, as `PciHost.load()` did. */\n\tload(context: PciLoadContext): Promise<void>;\n\t/**\n\t * Create the interaction instance inside `dom`, seeded with `state`.\n\t * Synchronous from the host's side: a sandboxed session queues the bridge\n\t * messages and the instance reports readiness asynchronously.\n\t */\n\tinstantiate(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate: unknown\n\t): QtiPciInstance | undefined;\n\t/** Discard the instance; the session stays usable for a fresh `instantiate`. */\n\tdestroyInstance(instance: QtiPciInstance): void;\n\t/** Final teardown of everything the session created. */\n\tdispose(): void;\n\t/**\n\t * Response/state pushes that arrive outside the `onready`/`ondone` lifecycle\n\t * — the sandboxed engine's poll. The handler's `state` joins the host's\n\t * instance-state; the response itself travels through the returned\n\t * instance's cache, which the host reads with `getResponse()`.\n\t */\n\tonRemoteReport?(handler: (report: { state?: unknown }) => void): () => void;\n\t/** Asynchronous failures that surface after `load()` resolved. */\n\tonError?(handler: (error: Error) => void): () => void;\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PciLoadContext, PciModuleSession } from './moduleSession.js';
|
|
2
|
+
import type { ExtractedPci, PciModuleResolver, PciRegistryObservation, QtiPciConfiguration, QtiPciInstance } from './types.js';
|
|
3
|
+
export interface PageRealmSessionOptions {
|
|
4
|
+
data: ExtractedPci;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Undefined is allowed at construction so an unconfigured host can be built
|
|
8
|
+
* and report the secure-default error at load time, as it always has.
|
|
9
|
+
*/
|
|
10
|
+
moduleResolver?: PciModuleResolver;
|
|
11
|
+
registry?: PciRegistryObservation;
|
|
12
|
+
registrationTimeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The page-realm engine: the host resolver evaluates the module in the page,
|
|
16
|
+
* the registry global observes its registration, and instantiation is a direct
|
|
17
|
+
* `getInstance` call. This is the behavior `PciHost` carried before the
|
|
18
|
+
* sandboxed engine existed, extracted behind the session seam unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export declare class PageRealmPciSession implements PciModuleSession {
|
|
21
|
+
private readonly data;
|
|
22
|
+
private readonly baseUrl;
|
|
23
|
+
private readonly moduleResolver;
|
|
24
|
+
private readonly registry;
|
|
25
|
+
private readonly registrationTimeoutMs;
|
|
26
|
+
private registration;
|
|
27
|
+
constructor(options: PageRealmSessionOptions);
|
|
28
|
+
/** {@inheritdoc PciModuleSession.load} */
|
|
29
|
+
load(context: PciLoadContext): Promise<void>;
|
|
30
|
+
/** {@inheritdoc PciModuleSession.instantiate} */
|
|
31
|
+
instantiate(dom: HTMLElement, configuration: QtiPciConfiguration, state: unknown): QtiPciInstance | undefined;
|
|
32
|
+
/** {@inheritdoc PciModuleSession.destroyInstance} */
|
|
33
|
+
destroyInstance(instance: QtiPciInstance): void;
|
|
34
|
+
/** {@inheritdoc PciModuleSession.dispose} */
|
|
35
|
+
dispose(): void;
|
|
36
|
+
private awaitRegistration;
|
|
37
|
+
private evaluateModule;
|
|
38
|
+
/**
|
|
39
|
+
* Multi-module loading: fetch the resolution config (authored reference first,
|
|
40
|
+
* then the defined default locations), then drive the entry module — its
|
|
41
|
+
* primary path, or its fallback — through the AMD loader so `define`
|
|
42
|
+
* dependencies wire up before the registration is read.
|
|
43
|
+
*/
|
|
44
|
+
private loadViaAmd;
|
|
45
|
+
/** The resolution config: the authored reference, then the defined default locations. */
|
|
46
|
+
private loadResolutionConfig;
|
|
47
|
+
private resolveUrl;
|
|
48
|
+
private adoptRegistration;
|
|
49
|
+
}
|