@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/index.cjs CHANGED
@@ -4,14 +4,15 @@ var zod = require('zod');
4
4
  var fs = require('fs');
5
5
  var path = require('path');
6
6
  var url = require('url');
7
+ var crypto = require('crypto');
7
8
  var AdmZip = require('adm-zip');
8
9
  var archiver = require('archiver');
9
10
  var stream = require('stream');
10
- var crypto = require('crypto');
11
11
  var chalk = require('chalk');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
15
16
  var AdmZip__default = /*#__PURE__*/_interopDefault(AdmZip);
16
17
  var archiver__default = /*#__PURE__*/_interopDefault(archiver);
17
18
  var chalk__default = /*#__PURE__*/_interopDefault(chalk);
@@ -5118,6 +5119,22 @@ $1</resource>`
5118
5119
  return [];
5119
5120
  }
5120
5121
  }
5122
+ /**
5123
+ * Update the manifest identifier attribute to a new value.
5124
+ * Used to ensure every course has a unique identifier (e.g., project UUID).
5125
+ */
5126
+ updateIdentifier(zip, newIdentifier) {
5127
+ const entry = zip.getEntry("imsmanifest.xml");
5128
+ if (!entry) return false;
5129
+ const xml = entry.getData().toString("utf-8");
5130
+ const updated = xml.replace(
5131
+ /(<manifest[^>]+identifier\s*=\s*["'])[^"']+(["'])/i,
5132
+ `$1${newIdentifier}$2`
5133
+ );
5134
+ if (updated === xml) return false;
5135
+ zip.updateFile("imsmanifest.xml", Buffer.from(updated, "utf-8"));
5136
+ return true;
5137
+ }
5121
5138
  /**
5122
5139
  * Get the file paths that will be added to the package
5123
5140
  */
@@ -5932,6 +5949,24 @@ var Patcher = class {
5932
5949
  if (metadata.description) console.log(` - Description: ${metadata.description.substring(0, 50)}...`);
5933
5950
  if (metadata.language) console.log(` - Language: ${metadata.language}`);
5934
5951
  if (metadata.masteryScore !== null) console.log(` - Mastery Score: ${metadata.masteryScore}`);
5952
+ const configDocGuid = this.config.lrsBridge?.documentGuid;
5953
+ if (configDocGuid) {
5954
+ console.log(`[Patcher] Overriding courseId with documentGuid: ${configDocGuid}`);
5955
+ metadata.courseId = configDocGuid;
5956
+ metadata.courseIdSource = "manifest";
5957
+ result.courseId = configDocGuid;
5958
+ if (this.manifestUpdater.updateIdentifier(zip, configDocGuid)) {
5959
+ console.log(`[Patcher] Updated manifest identifier to: ${configDocGuid}`);
5960
+ }
5961
+ } else if (metadata.courseIdSource === "fallback") {
5962
+ const generated = crypto__default.default.randomUUID();
5963
+ console.log(`[Patcher] No course identifier found, generating UUID: ${generated}`);
5964
+ metadata.courseId = generated;
5965
+ result.courseId = generated;
5966
+ if (this.manifestUpdater.updateIdentifier(zip, generated)) {
5967
+ console.log(`[Patcher] Wrote generated UUID to manifest identifier`);
5968
+ }
5969
+ }
5935
5970
  const htmlInjector = this.getHtmlInjector(toolInfo.tool);
5936
5971
  htmlInjector.setMetadata(metadata);
5937
5972
  let fetchedFallbacks = {};