@patch-adams/core 1.4.33 → 1.4.35

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 CHANGED
@@ -6,6 +6,7 @@ var fs = require('fs');
6
6
  var path = require('path');
7
7
  var chalk = require('chalk');
8
8
  var ora = require('ora');
9
+ var crypto = require('crypto');
9
10
  var AdmZip = require('adm-zip');
10
11
  var archiver = require('archiver');
11
12
  var stream = require('stream');
@@ -16,6 +17,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
17
 
17
18
  var chalk__default = /*#__PURE__*/_interopDefault(chalk);
18
19
  var ora__default = /*#__PURE__*/_interopDefault(ora);
20
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
19
21
  var AdmZip__default = /*#__PURE__*/_interopDefault(AdmZip);
20
22
  var archiver__default = /*#__PURE__*/_interopDefault(archiver);
21
23
 
@@ -5450,6 +5452,22 @@ $1</resource>`
5450
5452
  return [];
5451
5453
  }
5452
5454
  }
5455
+ /**
5456
+ * Update the manifest identifier attribute to a new value.
5457
+ * Used to ensure every course has a unique identifier (e.g., project UUID).
5458
+ */
5459
+ updateIdentifier(zip, newIdentifier) {
5460
+ const entry = zip.getEntry("imsmanifest.xml");
5461
+ if (!entry) return false;
5462
+ const xml = entry.getData().toString("utf-8");
5463
+ const updated = xml.replace(
5464
+ /(<manifest[^>]+identifier\s*=\s*["'])[^"']+(["'])/i,
5465
+ `$1${newIdentifier}$2`
5466
+ );
5467
+ if (updated === xml) return false;
5468
+ zip.updateFile("imsmanifest.xml", Buffer.from(updated, "utf-8"));
5469
+ return true;
5470
+ }
5453
5471
  /**
5454
5472
  * Get the file paths that will be added to the package
5455
5473
  */
@@ -5954,6 +5972,24 @@ var Patcher = class {
5954
5972
  if (metadata.description) console.log(` - Description: ${metadata.description.substring(0, 50)}...`);
5955
5973
  if (metadata.language) console.log(` - Language: ${metadata.language}`);
5956
5974
  if (metadata.masteryScore !== null) console.log(` - Mastery Score: ${metadata.masteryScore}`);
5975
+ const configDocGuid = this.config.lrsBridge?.documentGuid;
5976
+ if (configDocGuid) {
5977
+ console.log(`[Patcher] Overriding courseId with documentGuid: ${configDocGuid}`);
5978
+ metadata.courseId = configDocGuid;
5979
+ metadata.courseIdSource = "manifest";
5980
+ result.courseId = configDocGuid;
5981
+ if (this.manifestUpdater.updateIdentifier(zip, configDocGuid)) {
5982
+ console.log(`[Patcher] Updated manifest identifier to: ${configDocGuid}`);
5983
+ }
5984
+ } else if (metadata.courseIdSource === "fallback") {
5985
+ const generated = crypto__default.default.randomUUID();
5986
+ console.log(`[Patcher] No course identifier found, generating UUID: ${generated}`);
5987
+ metadata.courseId = generated;
5988
+ result.courseId = generated;
5989
+ if (this.manifestUpdater.updateIdentifier(zip, generated)) {
5990
+ console.log(`[Patcher] Wrote generated UUID to manifest identifier`);
5991
+ }
5992
+ }
5957
5993
  const htmlInjector = this.getHtmlInjector(toolInfo.tool);
5958
5994
  htmlInjector.setMetadata(metadata);
5959
5995
  let fetchedFallbacks = {};