@patch-adams/core 1.5.19 → 1.5.21
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/cli.cjs +135 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +135 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +135 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +135 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1922,6 +1922,129 @@ function generateLrsBridgeCode(options) {
|
|
|
1922
1922
|
return hasValidMbox || hasValidAccount;
|
|
1923
1923
|
}
|
|
1924
1924
|
|
|
1925
|
+
// ========================================================================
|
|
1926
|
+
// CROSS-FRAME ACTOR SHARING
|
|
1927
|
+
// PA-Patcher injects the bridge into ALL HTML files in a SCORM package.
|
|
1928
|
+
// Rise courses have multiple HTML files (index.html, scormcontent/index.html),
|
|
1929
|
+
// each getting their own bridge instance with its own LRS.actor.
|
|
1930
|
+
// The skin overlay (email gate) only runs in one frame and sets the actor there.
|
|
1931
|
+
// Without sharing, other bridge instances keep the Anonymous Learner actor.
|
|
1932
|
+
// Solution: persist actor to localStorage so all bridge instances can use it.
|
|
1933
|
+
// ========================================================================
|
|
1934
|
+
var ACTOR_STORAGE_KEY = 'pa_lrs_shared_actor';
|
|
1935
|
+
|
|
1936
|
+
function isAnonymousActor(actor) {
|
|
1937
|
+
if (!actor) return true;
|
|
1938
|
+
if (!actor.name) return true;
|
|
1939
|
+
var n = actor.name.toLowerCase();
|
|
1940
|
+
return n === 'anonymous learner' || n === 'unknown learner' || n === 'anonymous' || n === 'unknown';
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/**
|
|
1944
|
+
* Persist actor to localStorage for cross-frame sharing.
|
|
1945
|
+
* Only stores non-anonymous actors.
|
|
1946
|
+
*/
|
|
1947
|
+
function persistActor(actor) {
|
|
1948
|
+
if (!actor || isAnonymousActor(actor)) return;
|
|
1949
|
+
try {
|
|
1950
|
+
localStorage.setItem(ACTOR_STORAGE_KEY, JSON.stringify(actor));
|
|
1951
|
+
log('Actor persisted to localStorage:', actor.name);
|
|
1952
|
+
} catch (e) { /* localStorage unavailable */ }
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
/**
|
|
1956
|
+
* Load shared actor from localStorage.
|
|
1957
|
+
* Returns the stored actor or null.
|
|
1958
|
+
*/
|
|
1959
|
+
function loadSharedActor() {
|
|
1960
|
+
try {
|
|
1961
|
+
var stored = localStorage.getItem(ACTOR_STORAGE_KEY);
|
|
1962
|
+
if (stored) {
|
|
1963
|
+
var actor = JSON.parse(stored);
|
|
1964
|
+
if (actor && !isAnonymousActor(actor)) {
|
|
1965
|
+
return actor;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
} catch (e) { /* localStorage unavailable or parse error */ }
|
|
1969
|
+
return null;
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* Get the best available actor for statement building.
|
|
1974
|
+
* ALWAYS checks localStorage because the skin overlay in another frame
|
|
1975
|
+
* may have updated the actor AFTER this bridge instance initialized.
|
|
1976
|
+
* (e.g., user enters email in skin overlay \u2192 actor persisted to localStorage,
|
|
1977
|
+
* but the bridge in scormcontent/index.html already loaded a stale actor at init)
|
|
1978
|
+
*/
|
|
1979
|
+
function getActor() {
|
|
1980
|
+
// Always check localStorage for the freshest actor \u2014 it may have been
|
|
1981
|
+
// updated by the skin overlay in another frame since our init
|
|
1982
|
+
var shared = loadSharedActor();
|
|
1983
|
+
if (shared) {
|
|
1984
|
+
// Only update if different from current (avoid unnecessary log spam)
|
|
1985
|
+
if (!LRS.actor || LRS.actor.name !== shared.name ||
|
|
1986
|
+
(LRS.actor.account && shared.account && LRS.actor.account.name !== shared.account.name)) {
|
|
1987
|
+
log('Actor updated from cross-frame storage:', shared.name);
|
|
1988
|
+
}
|
|
1989
|
+
LRS.actor = shared;
|
|
1990
|
+
return shared;
|
|
1991
|
+
}
|
|
1992
|
+
// Fallback to current actor or re-extract
|
|
1993
|
+
if (LRS.actor && !isAnonymousActor(LRS.actor)) {
|
|
1994
|
+
return LRS.actor;
|
|
1995
|
+
}
|
|
1996
|
+
return LRS.actor || extractActor();
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* Set actor on the bridge with cross-frame persistence.
|
|
2001
|
+
* Called by skins and external code via window.pa_patcher.lrs.setActor(actor)
|
|
2002
|
+
*/
|
|
2003
|
+
LRS.setActor = function(actor) {
|
|
2004
|
+
LRS.actor = actor;
|
|
2005
|
+
persistActor(actor);
|
|
2006
|
+
|
|
2007
|
+
// Propagate to ALL frames: walk UP parent chain AND DOWN into child iframes
|
|
2008
|
+
// UP: parent frames (e.g., if skin is in a child iframe)
|
|
2009
|
+
try {
|
|
2010
|
+
var w = window;
|
|
2011
|
+
for (var i = 0; i < 10; i++) {
|
|
2012
|
+
try {
|
|
2013
|
+
if (w !== window && w.pa_patcher && w.pa_patcher.lrs) {
|
|
2014
|
+
w.pa_patcher.lrs.actor = actor;
|
|
2015
|
+
}
|
|
2016
|
+
} catch (e) { /* cross-origin */ }
|
|
2017
|
+
if (w === w.parent) break;
|
|
2018
|
+
w = w.parent;
|
|
2019
|
+
}
|
|
2020
|
+
} catch (e) {}
|
|
2021
|
+
|
|
2022
|
+
// DOWN: child iframes (e.g., scormcontent/index.html has its own bridge)
|
|
2023
|
+
function setActorInChildren(win) {
|
|
2024
|
+
try {
|
|
2025
|
+
var frames = win.frames;
|
|
2026
|
+
for (var j = 0; j < frames.length; j++) {
|
|
2027
|
+
try {
|
|
2028
|
+
if (frames[j].pa_patcher && frames[j].pa_patcher.lrs) {
|
|
2029
|
+
frames[j].pa_patcher.lrs.actor = actor;
|
|
2030
|
+
log('Actor propagated to child frame', j);
|
|
2031
|
+
}
|
|
2032
|
+
// Recurse into nested iframes
|
|
2033
|
+
setActorInChildren(frames[j]);
|
|
2034
|
+
} catch (e) { /* cross-origin child */ }
|
|
2035
|
+
}
|
|
2036
|
+
} catch (e) {}
|
|
2037
|
+
}
|
|
2038
|
+
setActorInChildren(window);
|
|
2039
|
+
|
|
2040
|
+
if (window.console && window.console.info) {
|
|
2041
|
+
console.info('[PA-LRS] Actor set:', actor.name,
|
|
2042
|
+
actor.mbox ? '(' + actor.mbox + ')' : '',
|
|
2043
|
+
actor.account ? '(account: ' + actor.account.name + ')' : '',
|
|
2044
|
+
'\u2014 shared across frames');
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
|
|
1925
2048
|
/**
|
|
1926
2049
|
* Async version that fetches Bravais session if needed
|
|
1927
2050
|
* Also re-checks all sources in case they became available
|
|
@@ -1933,6 +2056,7 @@ function generateLrsBridgeCode(options) {
|
|
|
1933
2056
|
// Try to enhance actor with email if missing
|
|
1934
2057
|
enhanceActorWithEmail(actor, function(enhancedActor) {
|
|
1935
2058
|
LRS.actor = enhancedActor;
|
|
2059
|
+
persistActor(enhancedActor);
|
|
1936
2060
|
callback(enhancedActor);
|
|
1937
2061
|
});
|
|
1938
2062
|
}
|
|
@@ -2939,7 +3063,7 @@ function generateLrsBridgeCode(options) {
|
|
|
2939
3063
|
|
|
2940
3064
|
var statement = {
|
|
2941
3065
|
id: generateUUID(),
|
|
2942
|
-
actor:
|
|
3066
|
+
actor: getActor(),
|
|
2943
3067
|
verb: typeof verb === 'string' ? (VERBS[verb] || { id: verb, display: { 'en-US': verb } }) : verb,
|
|
2944
3068
|
object: courseObj,
|
|
2945
3069
|
timestamp: new Date().toISOString()
|
|
@@ -3361,7 +3485,7 @@ function generateLrsBridgeCode(options) {
|
|
|
3361
3485
|
function buildStatementXyleme(verb, activityObject, result, additionalContext) {
|
|
3362
3486
|
var statement = {
|
|
3363
3487
|
id: generateUUID(),
|
|
3364
|
-
actor:
|
|
3488
|
+
actor: getActor(),
|
|
3365
3489
|
verb: typeof verb === 'string' ? (VERBS[verb] || { id: verb, display: { 'en-US': verb } }) : verb,
|
|
3366
3490
|
object: activityObject,
|
|
3367
3491
|
timestamp: new Date().toISOString()
|
|
@@ -5090,6 +5214,15 @@ function generateLrsBridgeCode(options) {
|
|
|
5090
5214
|
// Extract actor (sync first for immediate use)
|
|
5091
5215
|
extractActor();
|
|
5092
5216
|
|
|
5217
|
+
// Check localStorage for actor set by another frame (e.g., skin overlay in a different HTML file)
|
|
5218
|
+
if (isAnonymousActor(LRS.actor)) {
|
|
5219
|
+
var sharedActor = loadSharedActor();
|
|
5220
|
+
if (sharedActor) {
|
|
5221
|
+
LRS.actor = sharedActor;
|
|
5222
|
+
log('Loaded actor from cross-frame storage at init:', sharedActor.name);
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5093
5226
|
log('Bridge initialized in mode:', LRS.mode);
|
|
5094
5227
|
log('Actor:', LRS.actor);
|
|
5095
5228
|
log('Course:', LRS.courseInfo);
|