@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/index.cjs CHANGED
@@ -39,7 +39,11 @@ var LrsBridgeConfigSchema = zod.z.object({
39
39
  /** Course homepage IRI for xAPI context */
40
40
  courseHomepage: zod.z.string().optional(),
41
41
  /** Auto-detect Bravais LRS endpoint from parent frame URL (default: true) */
42
- autoDetectLrs: zod.z.boolean().default(true)
42
+ autoDetectLrs: zod.z.boolean().default(true),
43
+ /** Basic auth credentials for LRS (Base64 encoded "username:password") - used when no cookie session exists */
44
+ lrsAuth: zod.z.string().optional(),
45
+ /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
46
+ lrsProxyEndpoint: zod.z.string().optional()
43
47
  });
44
48
  var BlockingAssetConfigSchema = zod.z.object({
45
49
  /** Filename for the asset */
@@ -382,7 +386,9 @@ var DEFAULT_LRS_OPTIONS = {
382
386
  lrsWithCredentials: true,
383
387
  courseHomepage: "",
384
388
  autoDetectLrs: true,
385
- employeeApiEndpoint: ""
389
+ employeeApiEndpoint: "",
390
+ lrsAuth: "",
391
+ lrsProxyEndpoint: ""
386
392
  };
387
393
  function generateLrsBridgeCode(options) {
388
394
  if (!options.enabled) {
@@ -394,6 +400,8 @@ function generateLrsBridgeCode(options) {
394
400
  const lrsEndpoint = options.lrsEndpoint || "";
395
401
  const courseHomepage = options.courseHomepage || "";
396
402
  const employeeApiEndpoint = options.employeeApiEndpoint || "";
403
+ const lrsAuth = options.lrsAuth || "";
404
+ const lrsProxyEndpoint = options.lrsProxyEndpoint || "";
397
405
  return `
398
406
  // ==========================================================================
399
407
  // PATCH-ADAMS LRS BRIDGE v2.2.0
@@ -416,6 +424,8 @@ function generateLrsBridgeCode(options) {
416
424
  var COURSE_HOMEPAGE = '${courseHomepage}';
417
425
  var AUTO_DETECT_LRS = ${options.autoDetectLrs ?? true};
418
426
  var EMPLOYEE_API_ENDPOINT = '${employeeApiEndpoint}';
427
+ var LRS_AUTH = '${lrsAuth}';
428
+ var LRS_PROXY_ENDPOINT = '${lrsProxyEndpoint}';
419
429
 
420
430
  // Bravais LRS endpoint pattern: https://lrs-{tenant}.bravais.com/XAPI/statements
421
431
  // Example: core-acme.bravais.com -> lrs-acme.bravais.com
@@ -2845,24 +2855,41 @@ function generateLrsBridgeCode(options) {
2845
2855
  }
2846
2856
 
2847
2857
  function sendViaDirectLRS(statement) {
2858
+ // Use proxy endpoint if configured, otherwise direct LRS
2859
+ var useProxy = LRS_PROXY_ENDPOINT && LRS_PROXY_ENDPOINT.length > 0;
2860
+ var endpoint = useProxy ? LRS_PROXY_ENDPOINT : LRS_ENDPOINT;
2861
+
2862
+ if (!endpoint || endpoint.length === 0) {
2863
+ warn('No LRS endpoint available');
2864
+ LRS.stats.statementsFailed++;
2865
+ return Promise.reject(new Error('No LRS endpoint'));
2866
+ }
2867
+
2848
2868
  return new Promise(function(resolve, reject) {
2849
2869
  var xhr = new XMLHttpRequest();
2850
- xhr.open('POST', LRS_ENDPOINT, true);
2870
+ // POST to proxy (proxy handles PUT to LRS), POST to direct LRS
2871
+ xhr.open('POST', endpoint, true);
2851
2872
 
2852
- // xAPI required headers (Bravais LRS requires version 1.0)
2873
+ // xAPI required headers
2853
2874
  xhr.setRequestHeader('Content-Type', 'application/json');
2854
2875
  xhr.setRequestHeader('X-Experience-API-Version', '1.0');
2855
2876
 
2856
- if (LRS_WITH_CREDENTIALS) {
2877
+ if (useProxy) {
2878
+ // Proxy handles auth server-side, no auth headers needed
2879
+ log('Sending via LRS proxy:', endpoint);
2880
+ } else if (LRS_AUTH && LRS_AUTH.length > 0) {
2881
+ xhr.setRequestHeader('Authorization', 'Basic ' + LRS_AUTH);
2882
+ log('Using Basic Auth for LRS request');
2883
+ } else if (LRS_WITH_CREDENTIALS) {
2857
2884
  xhr.withCredentials = true;
2858
2885
  }
2859
2886
 
2860
2887
  xhr.onreadystatechange = function() {
2861
2888
  if (xhr.readyState === 4) {
2862
2889
  if (xhr.status >= 200 && xhr.status < 300) {
2863
- log('Statement sent successfully:', statement.verb.display['en-US']);
2890
+ log('Statement sent successfully:', statement.verb.display['en-US'], useProxy ? '(via proxy)' : '(direct)');
2864
2891
  LRS.stats.statementsSent++;
2865
- resolve({ sent: true, via: 'directLRS', status: xhr.status });
2892
+ resolve({ sent: true, via: useProxy ? 'proxy' : 'directLRS', status: xhr.status });
2866
2893
  } else {
2867
2894
  warn('Statement send failed:', xhr.status, xhr.statusText);
2868
2895
  LRS.stats.statementsFailed++;
@@ -4208,7 +4235,9 @@ function buildJsBeforeOptions(config, metadata) {
4208
4235
  lrsEndpoint: lrsBridgeConfig.lrsEndpoint,
4209
4236
  lrsWithCredentials: lrsBridgeConfig.lrsWithCredentials,
4210
4237
  courseHomepage: lrsBridgeConfig.courseHomepage,
4211
- autoDetectLrs: lrsBridgeConfig.autoDetectLrs
4238
+ autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4239
+ lrsAuth: lrsBridgeConfig.lrsAuth,
4240
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4212
4241
  };
4213
4242
  return {
4214
4243
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,