@patch-adams/core 1.4.16 → 1.4.18

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.js CHANGED
@@ -378,7 +378,11 @@ var LrsBridgeConfigSchema = z.object({
378
378
  /** Course homepage IRI for xAPI context */
379
379
  courseHomepage: z.string().optional(),
380
380
  /** Auto-detect Bravais LRS endpoint from parent frame URL (default: true) */
381
- autoDetectLrs: z.boolean().default(true)
381
+ autoDetectLrs: z.boolean().default(true),
382
+ /** Basic auth credentials for LRS (Base64 encoded "username:password") - used when no cookie session exists */
383
+ lrsAuth: z.string().optional(),
384
+ /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
385
+ lrsProxyEndpoint: z.string().optional()
382
386
  });
383
387
  var BlockingAssetConfigSchema = z.object({
384
388
  /** Filename for the asset */
@@ -721,6 +725,8 @@ function generateLrsBridgeCode(options) {
721
725
  const lrsEndpoint = options.lrsEndpoint || "";
722
726
  const courseHomepage = options.courseHomepage || "";
723
727
  const employeeApiEndpoint = options.employeeApiEndpoint || "";
728
+ const lrsAuth = options.lrsAuth || "";
729
+ const lrsProxyEndpoint = options.lrsProxyEndpoint || "";
724
730
  return `
725
731
  // ==========================================================================
726
732
  // PATCH-ADAMS LRS BRIDGE v2.2.0
@@ -743,6 +749,8 @@ function generateLrsBridgeCode(options) {
743
749
  var COURSE_HOMEPAGE = '${courseHomepage}';
744
750
  var AUTO_DETECT_LRS = ${options.autoDetectLrs ?? true};
745
751
  var EMPLOYEE_API_ENDPOINT = '${employeeApiEndpoint}';
752
+ var LRS_AUTH = '${lrsAuth}';
753
+ var LRS_PROXY_ENDPOINT = '${lrsProxyEndpoint}';
746
754
 
747
755
  // Bravais LRS endpoint pattern: https://lrs-{tenant}.bravais.com/XAPI/statements
748
756
  // Example: core-acme.bravais.com -> lrs-acme.bravais.com
@@ -3172,24 +3180,41 @@ function generateLrsBridgeCode(options) {
3172
3180
  }
3173
3181
 
3174
3182
  function sendViaDirectLRS(statement) {
3183
+ // Use proxy endpoint if configured, otherwise direct LRS
3184
+ var useProxy = LRS_PROXY_ENDPOINT && LRS_PROXY_ENDPOINT.length > 0;
3185
+ var endpoint = useProxy ? LRS_PROXY_ENDPOINT : LRS_ENDPOINT;
3186
+
3187
+ if (!endpoint || endpoint.length === 0) {
3188
+ warn('No LRS endpoint available');
3189
+ LRS.stats.statementsFailed++;
3190
+ return Promise.reject(new Error('No LRS endpoint'));
3191
+ }
3192
+
3175
3193
  return new Promise(function(resolve, reject) {
3176
3194
  var xhr = new XMLHttpRequest();
3177
- xhr.open('POST', LRS_ENDPOINT, true);
3195
+ // POST to proxy (proxy handles PUT to LRS), POST to direct LRS
3196
+ xhr.open('POST', endpoint, true);
3178
3197
 
3179
- // xAPI required headers (Bravais LRS requires version 1.0)
3198
+ // xAPI required headers
3180
3199
  xhr.setRequestHeader('Content-Type', 'application/json');
3181
3200
  xhr.setRequestHeader('X-Experience-API-Version', '1.0');
3182
3201
 
3183
- if (LRS_WITH_CREDENTIALS) {
3202
+ if (useProxy) {
3203
+ // Proxy handles auth server-side, no auth headers needed
3204
+ log('Sending via LRS proxy:', endpoint);
3205
+ } else if (LRS_AUTH && LRS_AUTH.length > 0) {
3206
+ xhr.setRequestHeader('Authorization', 'Basic ' + LRS_AUTH);
3207
+ log('Using Basic Auth for LRS request');
3208
+ } else if (LRS_WITH_CREDENTIALS) {
3184
3209
  xhr.withCredentials = true;
3185
3210
  }
3186
3211
 
3187
3212
  xhr.onreadystatechange = function() {
3188
3213
  if (xhr.readyState === 4) {
3189
3214
  if (xhr.status >= 200 && xhr.status < 300) {
3190
- log('Statement sent successfully:', statement.verb.display['en-US']);
3215
+ log('Statement sent successfully:', statement.verb.display['en-US'], useProxy ? '(via proxy)' : '(direct)');
3191
3216
  LRS.stats.statementsSent++;
3192
- resolve({ sent: true, via: 'directLRS', status: xhr.status });
3217
+ resolve({ sent: true, via: useProxy ? 'proxy' : 'directLRS', status: xhr.status });
3193
3218
  } else {
3194
3219
  warn('Statement send failed:', xhr.status, xhr.statusText);
3195
3220
  LRS.stats.statementsFailed++;
@@ -4535,7 +4560,9 @@ function buildJsBeforeOptions(config, metadata) {
4535
4560
  lrsEndpoint: lrsBridgeConfig.lrsEndpoint,
4536
4561
  lrsWithCredentials: lrsBridgeConfig.lrsWithCredentials,
4537
4562
  courseHomepage: lrsBridgeConfig.courseHomepage,
4538
- autoDetectLrs: lrsBridgeConfig.autoDetectLrs
4563
+ autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4564
+ lrsAuth: lrsBridgeConfig.lrsAuth,
4565
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4539
4566
  };
4540
4567
  return {
4541
4568
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,