@patch-adams/core 1.4.15 → 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.cjs CHANGED
@@ -387,7 +387,11 @@ var LrsBridgeConfigSchema = zod.z.object({
387
387
  /** Course homepage IRI for xAPI context */
388
388
  courseHomepage: zod.z.string().optional(),
389
389
  /** Auto-detect Bravais LRS endpoint from parent frame URL (default: true) */
390
- autoDetectLrs: zod.z.boolean().default(true)
390
+ autoDetectLrs: zod.z.boolean().default(true),
391
+ /** Basic auth credentials for LRS (Base64 encoded "username:password") - used when no cookie session exists */
392
+ lrsAuth: zod.z.string().optional(),
393
+ /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
394
+ lrsProxyEndpoint: zod.z.string().optional()
391
395
  });
392
396
  var BlockingAssetConfigSchema = zod.z.object({
393
397
  /** Filename for the asset */
@@ -730,6 +734,8 @@ function generateLrsBridgeCode(options) {
730
734
  const lrsEndpoint = options.lrsEndpoint || "";
731
735
  const courseHomepage = options.courseHomepage || "";
732
736
  const employeeApiEndpoint = options.employeeApiEndpoint || "";
737
+ const lrsAuth = options.lrsAuth || "";
738
+ const lrsProxyEndpoint = options.lrsProxyEndpoint || "";
733
739
  return `
734
740
  // ==========================================================================
735
741
  // PATCH-ADAMS LRS BRIDGE v2.2.0
@@ -752,6 +758,8 @@ function generateLrsBridgeCode(options) {
752
758
  var COURSE_HOMEPAGE = '${courseHomepage}';
753
759
  var AUTO_DETECT_LRS = ${options.autoDetectLrs ?? true};
754
760
  var EMPLOYEE_API_ENDPOINT = '${employeeApiEndpoint}';
761
+ var LRS_AUTH = '${lrsAuth}';
762
+ var LRS_PROXY_ENDPOINT = '${lrsProxyEndpoint}';
755
763
 
756
764
  // Bravais LRS endpoint pattern: https://lrs-{tenant}.bravais.com/XAPI/statements
757
765
  // Example: core-acme.bravais.com -> lrs-acme.bravais.com
@@ -3181,24 +3189,41 @@ function generateLrsBridgeCode(options) {
3181
3189
  }
3182
3190
 
3183
3191
  function sendViaDirectLRS(statement) {
3192
+ // Use proxy endpoint if configured, otherwise direct LRS
3193
+ var useProxy = LRS_PROXY_ENDPOINT && LRS_PROXY_ENDPOINT.length > 0;
3194
+ var endpoint = useProxy ? LRS_PROXY_ENDPOINT : LRS_ENDPOINT;
3195
+
3196
+ if (!endpoint || endpoint.length === 0) {
3197
+ warn('No LRS endpoint available');
3198
+ LRS.stats.statementsFailed++;
3199
+ return Promise.reject(new Error('No LRS endpoint'));
3200
+ }
3201
+
3184
3202
  return new Promise(function(resolve, reject) {
3185
3203
  var xhr = new XMLHttpRequest();
3186
- xhr.open('POST', LRS_ENDPOINT, true);
3204
+ // POST to proxy (proxy handles PUT to LRS), POST to direct LRS
3205
+ xhr.open('POST', endpoint, true);
3187
3206
 
3188
- // xAPI required headers (Bravais LRS requires version 1.0)
3207
+ // xAPI required headers
3189
3208
  xhr.setRequestHeader('Content-Type', 'application/json');
3190
3209
  xhr.setRequestHeader('X-Experience-API-Version', '1.0');
3191
3210
 
3192
- if (LRS_WITH_CREDENTIALS) {
3211
+ if (useProxy) {
3212
+ // Proxy handles auth server-side, no auth headers needed
3213
+ log('Sending via LRS proxy:', endpoint);
3214
+ } else if (LRS_AUTH && LRS_AUTH.length > 0) {
3215
+ xhr.setRequestHeader('Authorization', 'Basic ' + LRS_AUTH);
3216
+ log('Using Basic Auth for LRS request');
3217
+ } else if (LRS_WITH_CREDENTIALS) {
3193
3218
  xhr.withCredentials = true;
3194
3219
  }
3195
3220
 
3196
3221
  xhr.onreadystatechange = function() {
3197
3222
  if (xhr.readyState === 4) {
3198
3223
  if (xhr.status >= 200 && xhr.status < 300) {
3199
- log('Statement sent successfully:', statement.verb.display['en-US']);
3224
+ log('Statement sent successfully:', statement.verb.display['en-US'], useProxy ? '(via proxy)' : '(direct)');
3200
3225
  LRS.stats.statementsSent++;
3201
- resolve({ sent: true, via: 'directLRS', status: xhr.status });
3226
+ resolve({ sent: true, via: useProxy ? 'proxy' : 'directLRS', status: xhr.status });
3202
3227
  } else {
3203
3228
  warn('Statement send failed:', xhr.status, xhr.statusText);
3204
3229
  LRS.stats.statementsFailed++;
@@ -4540,7 +4565,13 @@ function buildJsBeforeOptions(config, metadata) {
4540
4565
  trackQuizzes: lrsBridgeConfig.trackQuizzes ?? true,
4541
4566
  trackInteractions: lrsBridgeConfig.trackInteractions ?? true,
4542
4567
  customStatements: lrsBridgeConfig.customStatements ?? true,
4543
- debug: lrsBridgeConfig.debug ?? false
4568
+ debug: lrsBridgeConfig.debug ?? false,
4569
+ lrsEndpoint: lrsBridgeConfig.lrsEndpoint,
4570
+ lrsWithCredentials: lrsBridgeConfig.lrsWithCredentials,
4571
+ courseHomepage: lrsBridgeConfig.courseHomepage,
4572
+ autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4573
+ lrsAuth: lrsBridgeConfig.lrsAuth,
4574
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4544
4575
  };
4545
4576
  return {
4546
4577
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,