@pie-qti/ims-cp-core 0.1.11 → 0.1.13

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/dist/index.d.ts CHANGED
@@ -4,7 +4,9 @@
4
4
  */
5
5
  export * from './manifest-parser.js';
6
6
  export * from './package-path.js';
7
+ export * from './package-file-resolver.js';
7
8
  export * from './package-graph.js';
9
+ export * from './security-parsing.js';
8
10
  export * from './localized-resources.js';
9
11
  export * from './passage-reusability.js';
10
12
  export * from './qti3-shared-content.js';
package/dist/index.js CHANGED
@@ -4,7 +4,9 @@
4
4
  */
5
5
  export * from './manifest-parser.js';
6
6
  export * from './package-path.js';
7
+ export * from './package-file-resolver.js';
7
8
  export * from './package-graph.js';
9
+ export * from './security-parsing.js';
8
10
  export * from './localized-resources.js';
9
11
  export * from './passage-reusability.js';
10
12
  export * from './qti3-shared-content.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC","sourcesContent":["/**\n * @pie-qti/ims-cp-core\n * Core IMS Content Package utilities (browser + Node.js compatible)\n */\n\nexport * from './manifest-parser.js';\nexport * from './package-path.js';\nexport * from './package-graph.js';\nexport * from './localized-resources.js';\nexport * from './passage-reusability.js';\nexport * from './qti3-shared-content.js';\nexport * from './qti-heuristics.js';\nexport * from './utils/qti-xml.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC","sourcesContent":["/**\n * @pie-qti/ims-cp-core\n * Core IMS Content Package utilities (browser + Node.js compatible)\n */\n\nexport * from './manifest-parser.js';\nexport * from './package-path.js';\nexport * from './package-file-resolver.js';\nexport * from './package-graph.js';\nexport * from './security-parsing.js';\nexport * from './localized-resources.js';\nexport * from './passage-reusability.js';\nexport * from './qti3-shared-content.js';\nexport * from './qti-heuristics.js';\nexport * from './utils/qti-xml.js';\n"]}
@@ -0,0 +1,48 @@
1
+ import { type QtiHeuristicsConfig } from './qti-heuristics.js';
2
+ export type PackageReferenceKind = 'media-asset' | 'stylesheet' | 'catalog-file' | 'source-xml' | 'assessment-item-ref' | 'other-asset';
3
+ export type PackageReferenceResolutionStrategy = 'source-relative' | 'package-root' | 'unique-suffix' | 'unique-basename';
4
+ export type PackageReferenceUnresolvedStatus = 'skipped' | 'unsafe' | 'ambiguous' | 'missing';
5
+ export interface PackageReferenceDiagnostic {
6
+ severity: 'info' | 'warning' | 'error';
7
+ code: string;
8
+ message: string;
9
+ sourcePath?: string;
10
+ reference?: string;
11
+ candidatePaths?: string[];
12
+ }
13
+ export interface PackageFileIndex {
14
+ readonly exactPaths: ReadonlySet<string>;
15
+ readonly pathsBySuffix: ReadonlyMap<string, readonly string[]>;
16
+ readonly pathsByBasename: ReadonlyMap<string, readonly string[]>;
17
+ readonly diagnostics: readonly PackageReferenceDiagnostic[];
18
+ }
19
+ export interface ResolvePackageReferenceInput {
20
+ readonly fileIndex: PackageFileIndex;
21
+ readonly rawHref: string;
22
+ readonly sourcePath?: string;
23
+ readonly referenceKind: PackageReferenceKind;
24
+ readonly heuristicsConfig?: QtiHeuristicsConfig;
25
+ readonly manifestEvidencePaths?: ReadonlySet<string>;
26
+ }
27
+ export interface ResolvedPackageReference {
28
+ readonly status: 'resolved';
29
+ readonly rawHref: string;
30
+ readonly lookupHref: string;
31
+ readonly renderHref: string;
32
+ readonly resolvedPath: string;
33
+ readonly strategy: PackageReferenceResolutionStrategy;
34
+ readonly heuristic: boolean;
35
+ readonly queryAndFragment: string;
36
+ readonly diagnostics: readonly PackageReferenceDiagnostic[];
37
+ }
38
+ export interface UnresolvedPackageReference {
39
+ readonly status: PackageReferenceUnresolvedStatus;
40
+ readonly rawHref: string;
41
+ readonly lookupHref: string;
42
+ readonly queryAndFragment: string;
43
+ readonly diagnostics: readonly PackageReferenceDiagnostic[];
44
+ readonly candidatePaths?: readonly string[];
45
+ }
46
+ export type PackageReferenceResolution = ResolvedPackageReference | UnresolvedPackageReference;
47
+ export declare function buildPackageFileIndex(paths: readonly string[]): PackageFileIndex;
48
+ export declare function resolvePackageReference(input: ResolvePackageReferenceInput): PackageReferenceResolution;
@@ -0,0 +1,312 @@
1
+ import { DEFAULT_HEURISTICS_CONFIG, normalizeHeuristicsConfig, } from './qti-heuristics.js';
2
+ export function buildPackageFileIndex(paths) {
3
+ const exactPaths = new Set();
4
+ const pathsBySuffix = new Map();
5
+ const pathsByBasename = new Map();
6
+ const diagnostics = [];
7
+ for (const rawPath of paths) {
8
+ const normalized = normalizePackagePath('', rawPath);
9
+ if (hasUnsafeEncodedPathToken(rawPath) || normalized.unsafe || !normalized.path) {
10
+ diagnostics.push({
11
+ severity: 'warning',
12
+ code: 'IMS_CP_FILE_INDEX_UNSAFE_PATH',
13
+ message: `Package file index skipped unsafe path: ${rawPath}.`,
14
+ reference: rawPath,
15
+ });
16
+ continue;
17
+ }
18
+ if (exactPaths.has(normalized.path)) {
19
+ diagnostics.push({
20
+ severity: 'warning',
21
+ code: 'IMS_CP_FILE_INDEX_COLLISION',
22
+ message: `Package file index saw duplicate canonical path: ${normalized.path}.`,
23
+ reference: rawPath,
24
+ candidatePaths: [normalized.path],
25
+ });
26
+ continue;
27
+ }
28
+ exactPaths.add(normalized.path);
29
+ addSuffixes(pathsBySuffix, normalized.path);
30
+ const basename = basenameOf(normalized.path);
31
+ if (basename) {
32
+ mapArrayFor(pathsByBasename, lookupKey(basename)).push(normalized.path);
33
+ }
34
+ }
35
+ return { exactPaths, pathsBySuffix, pathsByBasename, diagnostics };
36
+ }
37
+ export function resolvePackageReference(input) {
38
+ const rawHref = input.rawHref;
39
+ const trimmed = String(rawHref ?? '').trim();
40
+ const split = splitLookupHref(trimmed);
41
+ const lookupHref = split.lookupHref.replaceAll('\\', '/').trim();
42
+ const diagnostics = [];
43
+ if (!lookupHref || lookupHref.startsWith('#') || isExternalHref(lookupHref)) {
44
+ return {
45
+ status: 'skipped',
46
+ rawHref,
47
+ lookupHref,
48
+ queryAndFragment: split.queryAndFragment,
49
+ diagnostics,
50
+ };
51
+ }
52
+ if (lookupHref.startsWith('/') || hasUnsafeEncodedPathToken(lookupHref)) {
53
+ return unsafeResolution(rawHref, lookupHref, split.queryAndFragment, input.sourcePath);
54
+ }
55
+ const sourceBase = input.sourcePath ? dirname(input.sourcePath) : '';
56
+ const sourceCandidate = normalizePackagePath(sourceBase, lookupHref);
57
+ if (sourceCandidate.unsafe) {
58
+ return unsafeResolution(rawHref, lookupHref, split.queryAndFragment, input.sourcePath);
59
+ }
60
+ const sourceMatch = exactMatch(input.fileIndex, sourceCandidate.path);
61
+ if (sourceMatch) {
62
+ return resolved(rawHref, lookupHref, split.queryAndFragment, sourceMatch, 'source-relative', false, diagnostics);
63
+ }
64
+ const rootCandidate = normalizePackagePath('', lookupHref);
65
+ if (!rootCandidate.unsafe) {
66
+ const rootMatch = exactMatch(input.fileIndex, rootCandidate.path);
67
+ if (rootMatch) {
68
+ return resolved(rawHref, lookupHref, split.queryAndFragment, rootMatch, 'package-root', false, diagnostics);
69
+ }
70
+ }
71
+ const heuristics = normalizeHeuristicsConfig(input.heuristicsConfig ?? DEFAULT_HEURISTICS_CONFIG);
72
+ if (!heuristics.enabled || !heuristics.lenientPackageResourcePaths) {
73
+ return missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, [
74
+ {
75
+ severity: 'info',
76
+ code: 'IMS_CP_REFERENCE_HEURISTIC_DISABLED',
77
+ message: `Heuristic package path resolution is disabled for ${lookupHref}.`,
78
+ sourcePath: input.sourcePath,
79
+ reference: rawHref,
80
+ },
81
+ ]);
82
+ }
83
+ const suffixKeys = suffixLookupKeys(sourceCandidate.path, rootCandidate.path, lookupHref);
84
+ let ambiguousSuffixMatches = [];
85
+ let suffixKey = suffixKeys[0] ?? '';
86
+ let eligibleSuffixMatches = [];
87
+ for (const key of suffixKeys) {
88
+ if (!canUseSingleSegmentSuffix(input.referenceKind) && !key.includes('/')) {
89
+ continue;
90
+ }
91
+ const suffixMatches = uniqueSorted(input.fileIndex.pathsBySuffix.get(lookupKey(key)) ?? []);
92
+ const eligibleMatches = filterManifestEvidence(suffixMatches, input);
93
+ if (eligibleMatches.length === 1) {
94
+ suffixKey = key;
95
+ eligibleSuffixMatches = eligibleMatches;
96
+ break;
97
+ }
98
+ if (eligibleMatches.length > 1 && ambiguousSuffixMatches.length === 0) {
99
+ suffixKey = key;
100
+ ambiguousSuffixMatches = eligibleMatches;
101
+ }
102
+ }
103
+ if (eligibleSuffixMatches.length === 1) {
104
+ return resolved(rawHref, lookupHref, split.queryAndFragment, eligibleSuffixMatches[0], 'unique-suffix', true, diagnostics);
105
+ }
106
+ if (ambiguousSuffixMatches.length > 1) {
107
+ return ambiguous(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, ambiguousSuffixMatches);
108
+ }
109
+ if (!canUseBasenameHeuristic(input.referenceKind, heuristics)) {
110
+ return missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, diagnostics);
111
+ }
112
+ const basename = basenameOf(suffixKey);
113
+ const basenameMatches = uniqueSorted(input.fileIndex.pathsByBasename.get(lookupKey(basename)) ?? []);
114
+ if (basenameMatches.length === 1) {
115
+ return resolved(rawHref, lookupHref, split.queryAndFragment, basenameMatches[0], 'unique-basename', true, diagnostics);
116
+ }
117
+ if (basenameMatches.length > 1) {
118
+ return ambiguous(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, basenameMatches);
119
+ }
120
+ return missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, diagnostics);
121
+ }
122
+ function exactMatch(fileIndex, path) {
123
+ return path && fileIndex.exactPaths.has(path) ? path : null;
124
+ }
125
+ function resolved(rawHref, lookupHref, queryAndFragment, resolvedPath, strategy, heuristic, diagnostics) {
126
+ return {
127
+ status: 'resolved',
128
+ rawHref,
129
+ lookupHref,
130
+ renderHref: `${resolvedPath}${queryAndFragment}`,
131
+ resolvedPath,
132
+ strategy,
133
+ heuristic,
134
+ queryAndFragment,
135
+ diagnostics,
136
+ };
137
+ }
138
+ function missing(rawHref, lookupHref, queryAndFragment, sourcePath, diagnostics) {
139
+ return {
140
+ status: 'missing',
141
+ rawHref,
142
+ lookupHref,
143
+ queryAndFragment,
144
+ diagnostics: diagnostics.length > 0
145
+ ? diagnostics
146
+ : [
147
+ {
148
+ severity: 'warning',
149
+ code: 'IMS_CP_REFERENCE_MISSING',
150
+ message: `Package reference could not be resolved: ${lookupHref}.`,
151
+ sourcePath,
152
+ reference: rawHref,
153
+ },
154
+ ],
155
+ };
156
+ }
157
+ function ambiguous(rawHref, lookupHref, queryAndFragment, sourcePath, candidatePaths) {
158
+ return {
159
+ status: 'ambiguous',
160
+ rawHref,
161
+ lookupHref,
162
+ queryAndFragment,
163
+ candidatePaths,
164
+ diagnostics: [
165
+ {
166
+ severity: 'warning',
167
+ code: 'IMS_CP_REFERENCE_AMBIGUOUS',
168
+ message: `Package reference is ambiguous: ${lookupHref} matched ${candidatePaths.length} files.`,
169
+ sourcePath,
170
+ reference: rawHref,
171
+ candidatePaths: [...candidatePaths],
172
+ },
173
+ ],
174
+ };
175
+ }
176
+ function unsafeResolution(rawHref, lookupHref, queryAndFragment, sourcePath) {
177
+ return {
178
+ status: 'unsafe',
179
+ rawHref,
180
+ lookupHref,
181
+ queryAndFragment,
182
+ diagnostics: [
183
+ {
184
+ severity: 'error',
185
+ code: 'IMS_CP_REFERENCE_UNSAFE',
186
+ message: `Package reference escapes the package root or uses an absolute package path: ${lookupHref}.`,
187
+ sourcePath,
188
+ reference: rawHref,
189
+ },
190
+ ],
191
+ };
192
+ }
193
+ function splitLookupHref(rawHref) {
194
+ const queryIndex = rawHref.indexOf('?');
195
+ const fragmentIndex = rawHref.indexOf('#');
196
+ const indexes = [queryIndex, fragmentIndex].filter((index) => index >= 0);
197
+ if (indexes.length === 0) {
198
+ return { lookupHref: rawHref, queryAndFragment: '' };
199
+ }
200
+ const splitIndex = Math.min(...indexes);
201
+ return {
202
+ lookupHref: rawHref.slice(0, splitIndex),
203
+ queryAndFragment: rawHref.slice(splitIndex),
204
+ };
205
+ }
206
+ function isExternalHref(href) {
207
+ return /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(href);
208
+ }
209
+ function hasUnsafeEncodedPathToken(href) {
210
+ let current = href;
211
+ for (let i = 0; i < 3; i += 1) {
212
+ if (/%(?:2e|2f|5c)/i.test(current)) {
213
+ return true;
214
+ }
215
+ const decoded = safeDecodeURIComponent(current);
216
+ if (decoded === current) {
217
+ return false;
218
+ }
219
+ current = decoded;
220
+ }
221
+ return /%(?:2e|2f|5c)/i.test(current);
222
+ }
223
+ function safeDecodeURIComponent(value) {
224
+ try {
225
+ return decodeURIComponent(value);
226
+ }
227
+ catch {
228
+ return value;
229
+ }
230
+ }
231
+ function normalizePackagePath(basePath, href) {
232
+ const raw = href.replaceAll('\\', '/').trim();
233
+ if (!raw || raw.startsWith('/')) {
234
+ return { path: '', unsafe: raw.startsWith('/') };
235
+ }
236
+ const parts = [...(basePath ? basePath.replaceAll('\\', '/').split('/') : []), ...raw.split('/')];
237
+ const normalized = [];
238
+ for (const part of parts) {
239
+ if (!part || part === '.')
240
+ continue;
241
+ if (part === '..') {
242
+ if (normalized.length === 0) {
243
+ return { path: '', unsafe: true };
244
+ }
245
+ normalized.pop();
246
+ continue;
247
+ }
248
+ normalized.push(part);
249
+ }
250
+ return { path: normalized.join('/'), unsafe: false };
251
+ }
252
+ function suffixLookupKeys(sourceCandidate, rootCandidate, lookupHref) {
253
+ return uniqueStrings([
254
+ rootCandidate,
255
+ normalizePackagePath('', lookupHref).path,
256
+ sourceCandidate,
257
+ lookupHref.replaceAll('\\', '/').replace(/^\/+/, ''),
258
+ ].filter(Boolean));
259
+ }
260
+ function canUseBasenameHeuristic(referenceKind, heuristics) {
261
+ if (!heuristics.lenientAssetBasenames)
262
+ return false;
263
+ return referenceKind === 'media-asset';
264
+ }
265
+ function canUseSingleSegmentSuffix(referenceKind) {
266
+ return referenceKind === 'media-asset';
267
+ }
268
+ function filterManifestEvidence(matches, input) {
269
+ if (input.referenceKind !== 'source-xml' && input.referenceKind !== 'assessment-item-ref') {
270
+ return matches;
271
+ }
272
+ const evidence = input.manifestEvidencePaths;
273
+ if (!evidence)
274
+ return [];
275
+ return matches.filter((match) => evidence.has(match));
276
+ }
277
+ function addSuffixes(index, path) {
278
+ const parts = path.split('/');
279
+ for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
280
+ const suffix = parts.slice(partIndex).join('/');
281
+ if (suffix) {
282
+ mapArrayFor(index, lookupKey(suffix)).push(path);
283
+ }
284
+ }
285
+ }
286
+ function lookupKey(value) {
287
+ return value.toLowerCase();
288
+ }
289
+ function mapArrayFor(map, key) {
290
+ const existing = map.get(key);
291
+ if (existing)
292
+ return existing;
293
+ const next = [];
294
+ map.set(key, next);
295
+ return next;
296
+ }
297
+ function basenameOf(path) {
298
+ const index = path.lastIndexOf('/');
299
+ return index === -1 ? path : path.slice(index + 1);
300
+ }
301
+ function dirname(path) {
302
+ const normalized = path.replaceAll('\\', '/');
303
+ const index = normalized.lastIndexOf('/');
304
+ return index === -1 ? '' : normalized.slice(0, index);
305
+ }
306
+ function uniqueSorted(values) {
307
+ return [...new Set(values)].sort((left, right) => left.localeCompare(right));
308
+ }
309
+ function uniqueStrings(values) {
310
+ return [...new Set(values)];
311
+ }
312
+ //# sourceMappingURL=package-file-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-file-resolver.js","sourceRoot":"","sources":["../src/package-file-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,yBAAyB,EACzB,yBAAyB,GAEzB,MAAM,qBAAqB,CAAC;AAuE7B,MAAM,UAAU,qBAAqB,CAAC,KAAwB;IAC7D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAoB,CAAC;IAClD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAoB,CAAC;IACpD,MAAM,WAAW,GAAiC,EAAE,CAAC;IAErD,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,oBAAoB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,yBAAyB,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACjF,WAAW,CAAC,IAAI,CAAC;gBAChB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,+BAA+B;gBACrC,OAAO,EAAE,2CAA2C,OAAO,GAAG;gBAC9D,SAAS,EAAE,OAAO;aAClB,CAAC,CAAC;YACH,SAAS;QACV,CAAC;QACD,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrC,WAAW,CAAC,IAAI,CAAC;gBAChB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,6BAA6B;gBACnC,OAAO,EAAE,oDAAoD,UAAU,CAAC,IAAI,GAAG;gBAC/E,SAAS,EAAE,OAAO;gBAClB,cAAc,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;aACjC,CAAC,CAAC;YACH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AC,IAAY;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,YAAY,CAAC,MAAyB;IAC9C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,aAAa,CAAC,MAAyB;IAC/C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import {\n\tDEFAULT_HEURISTICS_CONFIG,\n\tnormalizeHeuristicsConfig,\n\ttype QtiHeuristicsConfig,\n} from './qti-heuristics.js';\n\nexport type PackageReferenceKind =\n\t| 'media-asset'\n\t| 'stylesheet'\n\t| 'catalog-file'\n\t| 'source-xml'\n\t| 'assessment-item-ref'\n\t| 'other-asset';\n\nexport type PackageReferenceResolutionStrategy =\n\t| 'source-relative'\n\t| 'package-root'\n\t| 'unique-suffix'\n\t| 'unique-basename';\n\nexport type PackageReferenceUnresolvedStatus = 'skipped' | 'unsafe' | 'ambiguous' | 'missing';\n\nexport interface PackageReferenceDiagnostic {\n\tseverity: 'info' | 'warning' | 'error';\n\tcode: string;\n\tmessage: string;\n\tsourcePath?: string;\n\treference?: string;\n\tcandidatePaths?: string[];\n}\n\nexport interface PackageFileIndex {\n\treadonly exactPaths: ReadonlySet<string>;\n\treadonly pathsBySuffix: ReadonlyMap<string, readonly string[]>;\n\treadonly pathsByBasename: ReadonlyMap<string, readonly string[]>;\n\treadonly diagnostics: readonly PackageReferenceDiagnostic[];\n}\n\nexport interface ResolvePackageReferenceInput {\n\treadonly fileIndex: PackageFileIndex;\n\treadonly rawHref: string;\n\treadonly sourcePath?: string;\n\treadonly referenceKind: PackageReferenceKind;\n\treadonly heuristicsConfig?: QtiHeuristicsConfig;\n\treadonly manifestEvidencePaths?: ReadonlySet<string>;\n}\n\nexport interface ResolvedPackageReference {\n\treadonly status: 'resolved';\n\treadonly rawHref: string;\n\treadonly lookupHref: string;\n\treadonly renderHref: string;\n\treadonly resolvedPath: string;\n\treadonly strategy: PackageReferenceResolutionStrategy;\n\treadonly heuristic: boolean;\n\treadonly queryAndFragment: string;\n\treadonly diagnostics: readonly PackageReferenceDiagnostic[];\n}\n\nexport interface UnresolvedPackageReference {\n\treadonly status: PackageReferenceUnresolvedStatus;\n\treadonly rawHref: string;\n\treadonly lookupHref: string;\n\treadonly queryAndFragment: string;\n\treadonly diagnostics: readonly PackageReferenceDiagnostic[];\n\treadonly candidatePaths?: readonly string[];\n}\n\nexport type PackageReferenceResolution = ResolvedPackageReference | UnresolvedPackageReference;\n\ninterface NormalizedPathResult {\n\tpath: string;\n\tunsafe: boolean;\n}\n\nexport function buildPackageFileIndex(paths: readonly string[]): PackageFileIndex {\n\tconst exactPaths = new Set<string>();\n\tconst pathsBySuffix = new Map<string, string[]>();\n\tconst pathsByBasename = new Map<string, string[]>();\n\tconst diagnostics: PackageReferenceDiagnostic[] = [];\n\n\tfor (const rawPath of paths) {\n\t\tconst normalized = normalizePackagePath('', rawPath);\n\t\tif (hasUnsafeEncodedPathToken(rawPath) || normalized.unsafe || !normalized.path) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: 'warning',\n\t\t\t\tcode: 'IMS_CP_FILE_INDEX_UNSAFE_PATH',\n\t\t\t\tmessage: `Package file index skipped unsafe path: ${rawPath}.`,\n\t\t\t\treference: rawPath,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (exactPaths.has(normalized.path)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: 'warning',\n\t\t\t\tcode: 'IMS_CP_FILE_INDEX_COLLISION',\n\t\t\t\tmessage: `Package file index saw duplicate canonical path: ${normalized.path}.`,\n\t\t\t\treference: rawPath,\n\t\t\t\tcandidatePaths: [normalized.path],\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\texactPaths.add(normalized.path);\n\t\taddSuffixes(pathsBySuffix, normalized.path);\n\t\tconst basename = basenameOf(normalized.path);\n\t\tif (basename) {\n\t\t\tmapArrayFor(pathsByBasename, lookupKey(basename)).push(normalized.path);\n\t\t}\n\t}\n\n\treturn { exactPaths, pathsBySuffix, pathsByBasename, diagnostics };\n}\n\nexport function resolvePackageReference(input: ResolvePackageReferenceInput): PackageReferenceResolution {\n\tconst rawHref = input.rawHref;\n\tconst trimmed = String(rawHref ?? '').trim();\n\tconst split = splitLookupHref(trimmed);\n\tconst lookupHref = split.lookupHref.replaceAll('\\\\', '/').trim();\n\tconst diagnostics: PackageReferenceDiagnostic[] = [];\n\n\tif (!lookupHref || lookupHref.startsWith('#') || isExternalHref(lookupHref)) {\n\t\treturn {\n\t\t\tstatus: 'skipped',\n\t\t\trawHref,\n\t\t\tlookupHref,\n\t\t\tqueryAndFragment: split.queryAndFragment,\n\t\t\tdiagnostics,\n\t\t};\n\t}\n\tif (lookupHref.startsWith('/') || hasUnsafeEncodedPathToken(lookupHref)) {\n\t\treturn unsafeResolution(rawHref, lookupHref, split.queryAndFragment, input.sourcePath);\n\t}\n\n\tconst sourceBase = input.sourcePath ? dirname(input.sourcePath) : '';\n\tconst sourceCandidate = normalizePackagePath(sourceBase, lookupHref);\n\tif (sourceCandidate.unsafe) {\n\t\treturn unsafeResolution(rawHref, lookupHref, split.queryAndFragment, input.sourcePath);\n\t}\n\tconst sourceMatch = exactMatch(input.fileIndex, sourceCandidate.path);\n\tif (sourceMatch) {\n\t\treturn resolved(rawHref, lookupHref, split.queryAndFragment, sourceMatch, 'source-relative', false, diagnostics);\n\t}\n\n\tconst rootCandidate = normalizePackagePath('', lookupHref);\n\tif (!rootCandidate.unsafe) {\n\t\tconst rootMatch = exactMatch(input.fileIndex, rootCandidate.path);\n\t\tif (rootMatch) {\n\t\t\treturn resolved(rawHref, lookupHref, split.queryAndFragment, rootMatch, 'package-root', false, diagnostics);\n\t\t}\n\t}\n\n\tconst heuristics = normalizeHeuristicsConfig(input.heuristicsConfig ?? DEFAULT_HEURISTICS_CONFIG);\n\tif (!heuristics.enabled || !heuristics.lenientPackageResourcePaths) {\n\t\treturn missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, [\n\t\t\t{\n\t\t\t\tseverity: 'info',\n\t\t\t\tcode: 'IMS_CP_REFERENCE_HEURISTIC_DISABLED',\n\t\t\t\tmessage: `Heuristic package path resolution is disabled for ${lookupHref}.`,\n\t\t\t\tsourcePath: input.sourcePath,\n\t\t\t\treference: rawHref,\n\t\t\t},\n\t\t]);\n\t}\n\n\tconst suffixKeys = suffixLookupKeys(sourceCandidate.path, rootCandidate.path, lookupHref);\n\tlet ambiguousSuffixMatches: readonly string[] = [];\n\tlet suffixKey = suffixKeys[0] ?? '';\n\tlet eligibleSuffixMatches: readonly string[] = [];\n\tfor (const key of suffixKeys) {\n\t\tif (!canUseSingleSegmentSuffix(input.referenceKind) && !key.includes('/')) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst suffixMatches = uniqueSorted(input.fileIndex.pathsBySuffix.get(lookupKey(key)) ?? []);\n\t\tconst eligibleMatches = filterManifestEvidence(suffixMatches, input);\n\t\tif (eligibleMatches.length === 1) {\n\t\t\tsuffixKey = key;\n\t\t\teligibleSuffixMatches = eligibleMatches;\n\t\t\tbreak;\n\t\t}\n\t\tif (eligibleMatches.length > 1 && ambiguousSuffixMatches.length === 0) {\n\t\t\tsuffixKey = key;\n\t\t\tambiguousSuffixMatches = eligibleMatches;\n\t\t}\n\t}\n\tif (eligibleSuffixMatches.length === 1) {\n\t\treturn resolved(\n\t\t\trawHref,\n\t\t\tlookupHref,\n\t\t\tsplit.queryAndFragment,\n\t\t\teligibleSuffixMatches[0],\n\t\t\t'unique-suffix',\n\t\t\ttrue,\n\t\t\tdiagnostics\n\t\t);\n\t}\n\tif (ambiguousSuffixMatches.length > 1) {\n\t\treturn ambiguous(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, ambiguousSuffixMatches);\n\t}\n\n\tif (!canUseBasenameHeuristic(input.referenceKind, heuristics)) {\n\t\treturn missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, diagnostics);\n\t}\n\tconst basename = basenameOf(suffixKey);\n\tconst basenameMatches = uniqueSorted(input.fileIndex.pathsByBasename.get(lookupKey(basename)) ?? []);\n\tif (basenameMatches.length === 1) {\n\t\treturn resolved(\n\t\t\trawHref,\n\t\t\tlookupHref,\n\t\t\tsplit.queryAndFragment,\n\t\t\tbasenameMatches[0],\n\t\t\t'unique-basename',\n\t\t\ttrue,\n\t\t\tdiagnostics\n\t\t);\n\t}\n\tif (basenameMatches.length > 1) {\n\t\treturn ambiguous(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, basenameMatches);\n\t}\n\n\treturn missing(rawHref, lookupHref, split.queryAndFragment, input.sourcePath, diagnostics);\n}\n\nfunction exactMatch(fileIndex: PackageFileIndex, path: string): string | null {\n\treturn path && fileIndex.exactPaths.has(path) ? path : null;\n}\n\nfunction resolved(\n\trawHref: string,\n\tlookupHref: string,\n\tqueryAndFragment: string,\n\tresolvedPath: string,\n\tstrategy: PackageReferenceResolutionStrategy,\n\theuristic: boolean,\n\tdiagnostics: readonly PackageReferenceDiagnostic[]\n): ResolvedPackageReference {\n\treturn {\n\t\tstatus: 'resolved',\n\t\trawHref,\n\t\tlookupHref,\n\t\trenderHref: `${resolvedPath}${queryAndFragment}`,\n\t\tresolvedPath,\n\t\tstrategy,\n\t\theuristic,\n\t\tqueryAndFragment,\n\t\tdiagnostics,\n\t};\n}\n\nfunction missing(\n\trawHref: string,\n\tlookupHref: string,\n\tqueryAndFragment: string,\n\tsourcePath: string | undefined,\n\tdiagnostics: readonly PackageReferenceDiagnostic[]\n): UnresolvedPackageReference {\n\treturn {\n\t\tstatus: 'missing',\n\t\trawHref,\n\t\tlookupHref,\n\t\tqueryAndFragment,\n\t\tdiagnostics: diagnostics.length > 0\n\t\t\t? diagnostics\n\t\t\t: [\n\t\t\t\t\t{\n\t\t\t\t\t\tseverity: 'warning',\n\t\t\t\t\t\tcode: 'IMS_CP_REFERENCE_MISSING',\n\t\t\t\t\t\tmessage: `Package reference could not be resolved: ${lookupHref}.`,\n\t\t\t\t\t\tsourcePath,\n\t\t\t\t\t\treference: rawHref,\n\t\t\t\t\t},\n\t\t\t\t],\n\t};\n}\n\nfunction ambiguous(\n\trawHref: string,\n\tlookupHref: string,\n\tqueryAndFragment: string,\n\tsourcePath: string | undefined,\n\tcandidatePaths: readonly string[]\n): UnresolvedPackageReference {\n\treturn {\n\t\tstatus: 'ambiguous',\n\t\trawHref,\n\t\tlookupHref,\n\t\tqueryAndFragment,\n\t\tcandidatePaths,\n\t\tdiagnostics: [\n\t\t\t{\n\t\t\t\tseverity: 'warning',\n\t\t\t\tcode: 'IMS_CP_REFERENCE_AMBIGUOUS',\n\t\t\t\tmessage: `Package reference is ambiguous: ${lookupHref} matched ${candidatePaths.length} files.`,\n\t\t\t\tsourcePath,\n\t\t\t\treference: rawHref,\n\t\t\t\tcandidatePaths: [...candidatePaths],\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction unsafeResolution(\n\trawHref: string,\n\tlookupHref: string,\n\tqueryAndFragment: string,\n\tsourcePath: string | undefined\n): UnresolvedPackageReference {\n\treturn {\n\t\tstatus: 'unsafe',\n\t\trawHref,\n\t\tlookupHref,\n\t\tqueryAndFragment,\n\t\tdiagnostics: [\n\t\t\t{\n\t\t\t\tseverity: 'error',\n\t\t\t\tcode: 'IMS_CP_REFERENCE_UNSAFE',\n\t\t\t\tmessage: `Package reference escapes the package root or uses an absolute package path: ${lookupHref}.`,\n\t\t\t\tsourcePath,\n\t\t\t\treference: rawHref,\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction splitLookupHref(rawHref: string): { lookupHref: string; queryAndFragment: string } {\n\tconst queryIndex = rawHref.indexOf('?');\n\tconst fragmentIndex = rawHref.indexOf('#');\n\tconst indexes = [queryIndex, fragmentIndex].filter((index) => index >= 0);\n\tif (indexes.length === 0) {\n\t\treturn { lookupHref: rawHref, queryAndFragment: '' };\n\t}\n\tconst splitIndex = Math.min(...indexes);\n\treturn {\n\t\tlookupHref: rawHref.slice(0, splitIndex),\n\t\tqueryAndFragment: rawHref.slice(splitIndex),\n\t};\n}\n\nfunction isExternalHref(href: string): boolean {\n\treturn /^(?:[a-z][a-z0-9+.-]*:|\\/\\/)/i.test(href);\n}\n\nfunction hasUnsafeEncodedPathToken(href: string): boolean {\n\tlet current = href;\n\tfor (let i = 0; i < 3; i += 1) {\n\t\tif (/%(?:2e|2f|5c)/i.test(current)) {\n\t\t\treturn true;\n\t\t}\n\t\tconst decoded = safeDecodeURIComponent(current);\n\t\tif (decoded === current) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrent = decoded;\n\t}\n\treturn /%(?:2e|2f|5c)/i.test(current);\n}\n\nfunction safeDecodeURIComponent(value: string): string {\n\ttry {\n\t\treturn decodeURIComponent(value);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\nfunction normalizePackagePath(basePath: string | undefined, href: string): NormalizedPathResult {\n\tconst raw = href.replaceAll('\\\\', '/').trim();\n\tif (!raw || raw.startsWith('/')) {\n\t\treturn { path: '', unsafe: raw.startsWith('/') };\n\t}\n\tconst parts = [...(basePath ? basePath.replaceAll('\\\\', '/').split('/') : []), ...raw.split('/')];\n\tconst normalized: string[] = [];\n\tfor (const part of parts) {\n\t\tif (!part || part === '.') continue;\n\t\tif (part === '..') {\n\t\t\tif (normalized.length === 0) {\n\t\t\t\treturn { path: '', unsafe: true };\n\t\t\t}\n\t\t\tnormalized.pop();\n\t\t\tcontinue;\n\t\t}\n\t\tnormalized.push(part);\n\t}\n\treturn { path: normalized.join('/'), unsafe: false };\n}\n\nfunction suffixLookupKeys(sourceCandidate: string, rootCandidate: string, lookupHref: string): string[] {\n\treturn uniqueStrings([\n\t\trootCandidate,\n\t\tnormalizePackagePath('', lookupHref).path,\n\t\tsourceCandidate,\n\t\tlookupHref.replaceAll('\\\\', '/').replace(/^\\/+/, ''),\n\t].filter(Boolean));\n}\n\nfunction canUseBasenameHeuristic(\n\treferenceKind: PackageReferenceKind,\n\theuristics: ReturnType<typeof normalizeHeuristicsConfig>\n): boolean {\n\tif (!heuristics.lenientAssetBasenames) return false;\n\treturn referenceKind === 'media-asset';\n}\n\nfunction canUseSingleSegmentSuffix(referenceKind: PackageReferenceKind): boolean {\n\treturn referenceKind === 'media-asset';\n}\n\nfunction filterManifestEvidence(\n\tmatches: readonly string[],\n\tinput: ResolvePackageReferenceInput\n): readonly string[] {\n\tif (input.referenceKind !== 'source-xml' && input.referenceKind !== 'assessment-item-ref') {\n\t\treturn matches;\n\t}\n\tconst evidence = input.manifestEvidencePaths;\n\tif (!evidence) return [];\n\treturn matches.filter((match) => evidence.has(match));\n}\n\nfunction addSuffixes(index: Map<string, string[]>, path: string): void {\n\tconst parts = path.split('/');\n\tfor (let partIndex = 0; partIndex < parts.length; partIndex += 1) {\n\t\tconst suffix = parts.slice(partIndex).join('/');\n\t\tif (suffix) {\n\t\t\tmapArrayFor(index, lookupKey(suffix)).push(path);\n\t\t}\n\t}\n}\n\nfunction lookupKey(value: string): string {\n\treturn value.toLowerCase();\n}\n\nfunction mapArrayFor<K, V>(map: Map<K, V[]>, key: K): V[] {\n\tconst existing = map.get(key);\n\tif (existing) return existing;\n\tconst next: V[] = [];\n\tmap.set(key, next);\n\treturn next;\n}\n\nfunction basenameOf(path: string): string {\n\tconst index = path.lastIndexOf('/');\n\treturn index === -1 ? path : path.slice(index + 1);\n}\n\nfunction dirname(path: string): string {\n\tconst normalized = path.replaceAll('\\\\', '/');\n\tconst index = normalized.lastIndexOf('/');\n\treturn index === -1 ? '' : normalized.slice(0, index);\n}\n\nfunction uniqueSorted(values: readonly string[]): string[] {\n\treturn [...new Set(values)].sort((left, right) => left.localeCompare(right));\n}\n\nfunction uniqueStrings(values: readonly string[]): string[] {\n\treturn [...new Set(values)];\n}\n"]}
@@ -1,4 +1,6 @@
1
1
  import { type ManifestResource, type ParsedManifest } from './manifest-parser.js';
2
+ import { type PackageReferenceResolutionStrategy } from './package-file-resolver.js';
3
+ import type { QtiHeuristicsConfig } from './qti-heuristics.js';
2
4
  export type PackageDiagnosticSeverity = 'info' | 'warning' | 'error';
3
5
  export interface PackageDiagnostic {
4
6
  severity: PackageDiagnosticSeverity;
@@ -45,13 +47,16 @@ export interface PackageResourceNode {
45
47
  metadata?: ManifestResource['metadata'];
46
48
  }
47
49
  export interface PackageReference {
48
- kind: 'manifest-dependency' | 'assessment-item-ref' | 'asset' | 'stylesheet' | 'object' | 'catalog';
50
+ kind: 'manifest-dependency' | 'assessment-item-ref' | 'asset' | 'stylesheet' | 'object' | 'catalog' | 'stimulus';
49
51
  rawHref: string;
50
52
  resolvedPath?: string;
51
53
  sourcePath?: string;
52
54
  sourceElement?: string;
53
55
  sourceAttribute?: string;
54
56
  targetResourceId?: string;
57
+ resolutionStrategy?: PackageReferenceResolutionStrategy;
58
+ heuristic?: boolean;
59
+ renderHref?: string;
55
60
  }
56
61
  export interface PackageAssetRef {
57
62
  rawHref: string;
@@ -63,6 +68,9 @@ export interface PackageAssetRef {
63
68
  sourcePaths?: string[];
64
69
  sourceElement?: string;
65
70
  sourceAttribute?: string;
71
+ resolutionStrategy?: PackageReferenceResolutionStrategy;
72
+ heuristic?: boolean;
73
+ renderHref?: string;
66
74
  }
67
75
  export interface PackageResourceClosure {
68
76
  resourceId: string;
@@ -76,7 +84,7 @@ export interface PackageEntrypoint {
76
84
  kind: 'item' | 'test' | 'passage';
77
85
  href?: string;
78
86
  }
79
- export type PackageRelationshipKind = 'manifest-dependency' | 'assessment-item-ref' | 'shared-asset';
87
+ export type PackageRelationshipKind = 'manifest-dependency' | 'assessment-item-ref' | 'assessment-stimulus-ref' | 'shared-asset';
80
88
  export interface PackageRelationshipHint {
81
89
  kind: PackageRelationshipKind;
82
90
  sourceResourceId?: string;
@@ -120,6 +128,7 @@ export interface AnalyzeContentPackageInput {
120
128
  manifestXml: string;
121
129
  basePath?: string;
122
130
  fileAccess?: PackageFileAccess;
131
+ heuristicsConfig?: QtiHeuristicsConfig;
123
132
  }
124
- export declare function analyzeContentPackage({ packageId, manifestXml, basePath, fileAccess, }: AnalyzeContentPackageInput): Promise<AnalyzedContentPackage>;
133
+ export declare function analyzeContentPackage({ packageId, manifestXml, basePath, fileAccess, heuristicsConfig, }: AnalyzeContentPackageInput): Promise<AnalyzedContentPackage>;
125
134
  export declare function serializeContentPackageEvidence(packageGraph: AnalyzedContentPackage): SerializedContentPackageEvidence;