@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/index.js
CHANGED
|
@@ -1591,6 +1591,129 @@ function generateLrsBridgeCode(options) {
|
|
|
1591
1591
|
return hasValidMbox || hasValidAccount;
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
1594
|
+
// ========================================================================
|
|
1595
|
+
// CROSS-FRAME ACTOR SHARING
|
|
1596
|
+
// PA-Patcher injects the bridge into ALL HTML files in a SCORM package.
|
|
1597
|
+
// Rise courses have multiple HTML files (index.html, scormcontent/index.html),
|
|
1598
|
+
// each getting their own bridge instance with its own LRS.actor.
|
|
1599
|
+
// The skin overlay (email gate) only runs in one frame and sets the actor there.
|
|
1600
|
+
// Without sharing, other bridge instances keep the Anonymous Learner actor.
|
|
1601
|
+
// Solution: persist actor to localStorage so all bridge instances can use it.
|
|
1602
|
+
// ========================================================================
|
|
1603
|
+
var ACTOR_STORAGE_KEY = 'pa_lrs_shared_actor';
|
|
1604
|
+
|
|
1605
|
+
function isAnonymousActor(actor) {
|
|
1606
|
+
if (!actor) return true;
|
|
1607
|
+
if (!actor.name) return true;
|
|
1608
|
+
var n = actor.name.toLowerCase();
|
|
1609
|
+
return n === 'anonymous learner' || n === 'unknown learner' || n === 'anonymous' || n === 'unknown';
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Persist actor to localStorage for cross-frame sharing.
|
|
1614
|
+
* Only stores non-anonymous actors.
|
|
1615
|
+
*/
|
|
1616
|
+
function persistActor(actor) {
|
|
1617
|
+
if (!actor || isAnonymousActor(actor)) return;
|
|
1618
|
+
try {
|
|
1619
|
+
localStorage.setItem(ACTOR_STORAGE_KEY, JSON.stringify(actor));
|
|
1620
|
+
log('Actor persisted to localStorage:', actor.name);
|
|
1621
|
+
} catch (e) { /* localStorage unavailable */ }
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Load shared actor from localStorage.
|
|
1626
|
+
* Returns the stored actor or null.
|
|
1627
|
+
*/
|
|
1628
|
+
function loadSharedActor() {
|
|
1629
|
+
try {
|
|
1630
|
+
var stored = localStorage.getItem(ACTOR_STORAGE_KEY);
|
|
1631
|
+
if (stored) {
|
|
1632
|
+
var actor = JSON.parse(stored);
|
|
1633
|
+
if (actor && !isAnonymousActor(actor)) {
|
|
1634
|
+
return actor;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
} catch (e) { /* localStorage unavailable or parse error */ }
|
|
1638
|
+
return null;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* Get the best available actor for statement building.
|
|
1643
|
+
* ALWAYS checks localStorage because the skin overlay in another frame
|
|
1644
|
+
* may have updated the actor AFTER this bridge instance initialized.
|
|
1645
|
+
* (e.g., user enters email in skin overlay \u2192 actor persisted to localStorage,
|
|
1646
|
+
* but the bridge in scormcontent/index.html already loaded a stale actor at init)
|
|
1647
|
+
*/
|
|
1648
|
+
function getActor() {
|
|
1649
|
+
// Always check localStorage for the freshest actor \u2014 it may have been
|
|
1650
|
+
// updated by the skin overlay in another frame since our init
|
|
1651
|
+
var shared = loadSharedActor();
|
|
1652
|
+
if (shared) {
|
|
1653
|
+
// Only update if different from current (avoid unnecessary log spam)
|
|
1654
|
+
if (!LRS.actor || LRS.actor.name !== shared.name ||
|
|
1655
|
+
(LRS.actor.account && shared.account && LRS.actor.account.name !== shared.account.name)) {
|
|
1656
|
+
log('Actor updated from cross-frame storage:', shared.name);
|
|
1657
|
+
}
|
|
1658
|
+
LRS.actor = shared;
|
|
1659
|
+
return shared;
|
|
1660
|
+
}
|
|
1661
|
+
// Fallback to current actor or re-extract
|
|
1662
|
+
if (LRS.actor && !isAnonymousActor(LRS.actor)) {
|
|
1663
|
+
return LRS.actor;
|
|
1664
|
+
}
|
|
1665
|
+
return LRS.actor || extractActor();
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* Set actor on the bridge with cross-frame persistence.
|
|
1670
|
+
* Called by skins and external code via window.pa_patcher.lrs.setActor(actor)
|
|
1671
|
+
*/
|
|
1672
|
+
LRS.setActor = function(actor) {
|
|
1673
|
+
LRS.actor = actor;
|
|
1674
|
+
persistActor(actor);
|
|
1675
|
+
|
|
1676
|
+
// Propagate to ALL frames: walk UP parent chain AND DOWN into child iframes
|
|
1677
|
+
// UP: parent frames (e.g., if skin is in a child iframe)
|
|
1678
|
+
try {
|
|
1679
|
+
var w = window;
|
|
1680
|
+
for (var i = 0; i < 10; i++) {
|
|
1681
|
+
try {
|
|
1682
|
+
if (w !== window && w.pa_patcher && w.pa_patcher.lrs) {
|
|
1683
|
+
w.pa_patcher.lrs.actor = actor;
|
|
1684
|
+
}
|
|
1685
|
+
} catch (e) { /* cross-origin */ }
|
|
1686
|
+
if (w === w.parent) break;
|
|
1687
|
+
w = w.parent;
|
|
1688
|
+
}
|
|
1689
|
+
} catch (e) {}
|
|
1690
|
+
|
|
1691
|
+
// DOWN: child iframes (e.g., scormcontent/index.html has its own bridge)
|
|
1692
|
+
function setActorInChildren(win) {
|
|
1693
|
+
try {
|
|
1694
|
+
var frames = win.frames;
|
|
1695
|
+
for (var j = 0; j < frames.length; j++) {
|
|
1696
|
+
try {
|
|
1697
|
+
if (frames[j].pa_patcher && frames[j].pa_patcher.lrs) {
|
|
1698
|
+
frames[j].pa_patcher.lrs.actor = actor;
|
|
1699
|
+
log('Actor propagated to child frame', j);
|
|
1700
|
+
}
|
|
1701
|
+
// Recurse into nested iframes
|
|
1702
|
+
setActorInChildren(frames[j]);
|
|
1703
|
+
} catch (e) { /* cross-origin child */ }
|
|
1704
|
+
}
|
|
1705
|
+
} catch (e) {}
|
|
1706
|
+
}
|
|
1707
|
+
setActorInChildren(window);
|
|
1708
|
+
|
|
1709
|
+
if (window.console && window.console.info) {
|
|
1710
|
+
console.info('[PA-LRS] Actor set:', actor.name,
|
|
1711
|
+
actor.mbox ? '(' + actor.mbox + ')' : '',
|
|
1712
|
+
actor.account ? '(account: ' + actor.account.name + ')' : '',
|
|
1713
|
+
'\u2014 shared across frames');
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1594
1717
|
/**
|
|
1595
1718
|
* Async version that fetches Bravais session if needed
|
|
1596
1719
|
* Also re-checks all sources in case they became available
|
|
@@ -1602,6 +1725,7 @@ function generateLrsBridgeCode(options) {
|
|
|
1602
1725
|
// Try to enhance actor with email if missing
|
|
1603
1726
|
enhanceActorWithEmail(actor, function(enhancedActor) {
|
|
1604
1727
|
LRS.actor = enhancedActor;
|
|
1728
|
+
persistActor(enhancedActor);
|
|
1605
1729
|
callback(enhancedActor);
|
|
1606
1730
|
});
|
|
1607
1731
|
}
|
|
@@ -2608,7 +2732,7 @@ function generateLrsBridgeCode(options) {
|
|
|
2608
2732
|
|
|
2609
2733
|
var statement = {
|
|
2610
2734
|
id: generateUUID(),
|
|
2611
|
-
actor:
|
|
2735
|
+
actor: getActor(),
|
|
2612
2736
|
verb: typeof verb === 'string' ? (VERBS[verb] || { id: verb, display: { 'en-US': verb } }) : verb,
|
|
2613
2737
|
object: courseObj,
|
|
2614
2738
|
timestamp: new Date().toISOString()
|
|
@@ -3030,7 +3154,7 @@ function generateLrsBridgeCode(options) {
|
|
|
3030
3154
|
function buildStatementXyleme(verb, activityObject, result, additionalContext) {
|
|
3031
3155
|
var statement = {
|
|
3032
3156
|
id: generateUUID(),
|
|
3033
|
-
actor:
|
|
3157
|
+
actor: getActor(),
|
|
3034
3158
|
verb: typeof verb === 'string' ? (VERBS[verb] || { id: verb, display: { 'en-US': verb } }) : verb,
|
|
3035
3159
|
object: activityObject,
|
|
3036
3160
|
timestamp: new Date().toISOString()
|
|
@@ -4759,6 +4883,15 @@ function generateLrsBridgeCode(options) {
|
|
|
4759
4883
|
// Extract actor (sync first for immediate use)
|
|
4760
4884
|
extractActor();
|
|
4761
4885
|
|
|
4886
|
+
// Check localStorage for actor set by another frame (e.g., skin overlay in a different HTML file)
|
|
4887
|
+
if (isAnonymousActor(LRS.actor)) {
|
|
4888
|
+
var sharedActor = loadSharedActor();
|
|
4889
|
+
if (sharedActor) {
|
|
4890
|
+
LRS.actor = sharedActor;
|
|
4891
|
+
log('Loaded actor from cross-frame storage at init:', sharedActor.name);
|
|
4892
|
+
}
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4762
4895
|
log('Bridge initialized in mode:', LRS.mode);
|
|
4763
4896
|
log('Actor:', LRS.actor);
|
|
4764
4897
|
log('Course:', LRS.courseInfo);
|