@edx/frontend-plugin-learner-dashboard 1.7.0 → 1.7.1

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.
@@ -7,6 +7,9 @@ exports.default = void 0;
7
7
  var _react = require("react");
8
8
  const CohesionWrapper = () => {
9
9
  const [isLoaded, setLoaded] = (0, _react.useState)(false);
10
+
11
+ // set pageType value
12
+ window.chsn_pageType = 'lms-homepage';
10
13
  (0, _react.useEffect)(() => {
11
14
  if (isLoaded) {
12
15
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"CohesionWrapper.js","names":["_react","require","CohesionWrapper","isLoaded","setLoaded","useState","useEffect","head","document","getElementsByTagName","script","createElement","src","defer","dataset","testId","appendChild","_default","exports","default"],"sources":["../../src/cohesion-wrapper/CohesionWrapper.jsx"],"sourcesContent":["import { useState, useEffect } from 'react';\n\nconst CohesionWrapper = () => {\n const [isLoaded, setLoaded] = useState(false);\n\n useEffect(() => {\n if (isLoaded) {\n return null;\n }\n\n const head = document.getElementsByTagName('head')[0];\n const script = document.createElement('script');\n script.src = 'https://www.edx.org/beam-wrapper.js';\n script.defer = true;\n script.dataset.testId = 'cohesion-test';\n head.appendChild(script);\n setLoaded(true);\n return null;\n }, [isLoaded]);\n\n return null;\n};\n\nexport default CohesionWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,MAAMC,eAAe,GAAGA,CAAA,KAAM;EAC5B,MAAM,CAACC,QAAQ,EAAEC,SAAS,CAAC,GAAG,IAAAC,eAAQ,EAAC,KAAK,CAAC;EAE7C,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAIH,QAAQ,EAAE;MACZ,OAAO,IAAI;IACb;IAEA,MAAMI,IAAI,GAAGC,QAAQ,CAACC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrD,MAAMC,MAAM,GAAGF,QAAQ,CAACG,aAAa,CAAC,QAAQ,CAAC;IAC/CD,MAAM,CAACE,GAAG,GAAG,qCAAqC;IAClDF,MAAM,CAACG,KAAK,GAAG,IAAI;IACnBH,MAAM,CAACI,OAAO,CAACC,MAAM,GAAG,eAAe;IACvCR,IAAI,CAACS,WAAW,CAACN,MAAM,CAAC;IACxBN,SAAS,CAAC,IAAI,CAAC;IACf,OAAO,IAAI;EACb,CAAC,EAAE,CAACD,QAAQ,CAAC,CAAC;EAEd,OAAO,IAAI;AACb,CAAC;AAAC,IAAAc,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEajB,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"CohesionWrapper.js","names":["_react","require","CohesionWrapper","isLoaded","setLoaded","useState","window","chsn_pageType","useEffect","head","document","getElementsByTagName","script","createElement","src","defer","dataset","testId","appendChild","_default","exports","default"],"sources":["../../src/cohesion-wrapper/CohesionWrapper.jsx"],"sourcesContent":["import { useState, useEffect } from 'react';\n\nconst CohesionWrapper = () => {\n const [isLoaded, setLoaded] = useState(false);\n\n // set pageType value\n window.chsn_pageType = 'lms-homepage';\n\n useEffect(() => {\n if (isLoaded) {\n return null;\n }\n\n const head = document.getElementsByTagName('head')[0];\n const script = document.createElement('script');\n script.src = 'https://www.edx.org/beam-wrapper.js';\n script.defer = true;\n script.dataset.testId = 'cohesion-test';\n head.appendChild(script);\n setLoaded(true);\n return null;\n }, [isLoaded]);\n\n return null;\n};\n\nexport default CohesionWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,MAAMC,eAAe,GAAGA,CAAA,KAAM;EAC5B,MAAM,CAACC,QAAQ,EAAEC,SAAS,CAAC,GAAG,IAAAC,eAAQ,EAAC,KAAK,CAAC;;EAE7C;EACAC,MAAM,CAACC,aAAa,GAAG,cAAc;EAErC,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAIL,QAAQ,EAAE;MACZ,OAAO,IAAI;IACb;IAEA,MAAMM,IAAI,GAAGC,QAAQ,CAACC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrD,MAAMC,MAAM,GAAGF,QAAQ,CAACG,aAAa,CAAC,QAAQ,CAAC;IAC/CD,MAAM,CAACE,GAAG,GAAG,qCAAqC;IAClDF,MAAM,CAACG,KAAK,GAAG,IAAI;IACnBH,MAAM,CAACI,OAAO,CAACC,MAAM,GAAG,eAAe;IACvCR,IAAI,CAACS,WAAW,CAACN,MAAM,CAAC;IACxBR,SAAS,CAAC,IAAI,CAAC;IACf,OAAO,IAAI;EACb,CAAC,EAAE,CAACD,QAAQ,CAAC,CAAC;EAEd,OAAO,IAAI;AACb,CAAC;AAAC,IAAAgB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanB,eAAe","ignoreList":[]}
@@ -3,42 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setCorrelationIDCookie = exports.handleCorrelationIDCookie = exports.getCorrelationIDCookie = void 0;
7
- const getCorrelationIDCookie = () => {
8
- const name = 'tglr_correlation_id=';
9
- const decodedCookie = decodeURIComponent(document.cookie);
10
- const cookieArray = decodedCookie.split(';');
11
- for (let i = 0; i < cookieArray.length; i++) {
12
- const cookie = cookieArray[i].trim();
13
- if (cookie.indexOf(name) === 0) {
14
- return cookie.substring(name.length, cookie.length);
15
- }
16
- }
17
- return '';
18
- };
19
- exports.getCorrelationIDCookie = getCorrelationIDCookie;
20
- const setCorrelationIDCookie = correlationId => {
21
- const now = new Date();
22
- const time = now.getTime();
23
-
24
- // Cookie expires in 30 minutes, same as when set in marketing page
25
- const expireTime = time + 1800;
26
- now.setTime(expireTime);
27
- document.cookie = `tglr_correlation_id=${correlationId}; expires=${now.toUTCString()}; path=/`;
28
- };
29
- exports.setCorrelationIDCookie = setCorrelationIDCookie;
6
+ exports.handleCorrelationIDCookie = void 0;
7
+ exports.setCookie = setCookie;
8
+ // general cookie setter, expires after 30 minutes
9
+ function setCookie(cookieName, cookieValue) {
10
+ const a = new Date();
11
+ // set to expire after 30 minutes, or 1.8 million milliseconds
12
+ a.setTime(a.getTime() + 1800000);
13
+ document.cookie = `${cookieName}\x3d${cookieValue}; expires\x3d${a.toGMTString()}; path\x3d/; domain\x3d.edx.org;`;
14
+ }
30
15
  const handleCorrelationIDCookie = () => {
31
- // Get correlation ID from URL or cookies if it exists, otherwise set to random UUID
32
- const queryString = window.location.search;
33
- const urlParams = new URLSearchParams(queryString);
34
- const correlationCookie = getCorrelationIDCookie();
35
- const randomUUID = window.crypto.randomUUID();
36
- const correlationId = urlParams.get('correlationId') || correlationCookie || randomUUID;
37
-
38
- // Set CorrelationID cookie if one wasn't set
39
- if (correlationCookie !== correlationId) {
40
- setCorrelationIDCookie(correlationId);
41
- }
16
+ // set correlation ID to a random UUID
17
+ const correlationId = window.crypto.randomUUID();
18
+ setCookie('tglr_correlation_id', correlationId);
42
19
  return correlationId;
43
20
  };
44
21
  exports.handleCorrelationIDCookie = handleCorrelationIDCookie;
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","names":["getCorrelationIDCookie","name","decodedCookie","decodeURIComponent","document","cookie","cookieArray","split","i","length","trim","indexOf","substring","exports","setCorrelationIDCookie","correlationId","now","Date","time","getTime","expireTime","setTime","toUTCString","handleCorrelationIDCookie","queryString","window","location","search","urlParams","URLSearchParams","correlationCookie","randomUUID","crypto","get"],"sources":["../../src/tracking/cookie.js"],"sourcesContent":["export const getCorrelationIDCookie = () => {\n const name = 'tglr_correlation_id=';\n const decodedCookie = decodeURIComponent(document.cookie);\n const cookieArray = decodedCookie.split(';');\n\n for (let i = 0; i < cookieArray.length; i++) {\n const cookie = cookieArray[i].trim();\n if (cookie.indexOf(name) === 0) {\n return cookie.substring(name.length, cookie.length);\n }\n }\n\n return '';\n};\n\nexport const setCorrelationIDCookie = (correlationId) => {\n const now = new Date();\n const time = now.getTime();\n\n // Cookie expires in 30 minutes, same as when set in marketing page\n const expireTime = time + 1800;\n now.setTime(expireTime);\n document.cookie = `tglr_correlation_id=${correlationId}; expires=${now.toUTCString()}; path=/`;\n};\n\nexport const handleCorrelationIDCookie = () => {\n // Get correlation ID from URL or cookies if it exists, otherwise set to random UUID\n const queryString = window.location.search;\n const urlParams = new URLSearchParams(queryString);\n const correlationCookie = getCorrelationIDCookie();\n const randomUUID = window.crypto.randomUUID();\n\n const correlationId = urlParams.get('correlationId') || correlationCookie || randomUUID;\n\n // Set CorrelationID cookie if one wasn't set\n if (correlationCookie !== correlationId) {\n setCorrelationIDCookie(correlationId);\n }\n\n return correlationId;\n};\n"],"mappings":";;;;;;AAAO,MAAMA,sBAAsB,GAAGA,CAAA,KAAM;EAC1C,MAAMC,IAAI,GAAG,sBAAsB;EACnC,MAAMC,aAAa,GAAGC,kBAAkB,CAACC,QAAQ,CAACC,MAAM,CAAC;EACzD,MAAMC,WAAW,GAAGJ,aAAa,CAACK,KAAK,CAAC,GAAG,CAAC;EAE5C,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,WAAW,CAACG,MAAM,EAAED,CAAC,EAAE,EAAE;IAC3C,MAAMH,MAAM,GAAGC,WAAW,CAACE,CAAC,CAAC,CAACE,IAAI,CAAC,CAAC;IACpC,IAAIL,MAAM,CAACM,OAAO,CAACV,IAAI,CAAC,KAAK,CAAC,EAAE;MAC9B,OAAOI,MAAM,CAACO,SAAS,CAACX,IAAI,CAACQ,MAAM,EAAEJ,MAAM,CAACI,MAAM,CAAC;IACrD;EACF;EAEA,OAAO,EAAE;AACX,CAAC;AAACI,OAAA,CAAAb,sBAAA,GAAAA,sBAAA;AAEK,MAAMc,sBAAsB,GAAIC,aAAa,IAAK;EACvD,MAAMC,GAAG,GAAG,IAAIC,IAAI,CAAC,CAAC;EACtB,MAAMC,IAAI,GAAGF,GAAG,CAACG,OAAO,CAAC,CAAC;;EAE1B;EACA,MAAMC,UAAU,GAAGF,IAAI,GAAG,IAAI;EAC9BF,GAAG,CAACK,OAAO,CAACD,UAAU,CAAC;EACvBhB,QAAQ,CAACC,MAAM,GAAG,uBAAuBU,aAAa,aAAaC,GAAG,CAACM,WAAW,CAAC,CAAC,UAAU;AAChG,CAAC;AAACT,OAAA,CAAAC,sBAAA,GAAAA,sBAAA;AAEK,MAAMS,yBAAyB,GAAGA,CAAA,KAAM;EAC7C;EACA,MAAMC,WAAW,GAAGC,MAAM,CAACC,QAAQ,CAACC,MAAM;EAC1C,MAAMC,SAAS,GAAG,IAAIC,eAAe,CAACL,WAAW,CAAC;EAClD,MAAMM,iBAAiB,GAAG9B,sBAAsB,CAAC,CAAC;EAClD,MAAM+B,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACD,UAAU,CAAC,CAAC;EAE7C,MAAMhB,aAAa,GAAGa,SAAS,CAACK,GAAG,CAAC,eAAe,CAAC,IAAIH,iBAAiB,IAAIC,UAAU;;EAEvF;EACA,IAAID,iBAAiB,KAAKf,aAAa,EAAE;IACvCD,sBAAsB,CAACC,aAAa,CAAC;EACvC;EAEA,OAAOA,aAAa;AACtB,CAAC;AAACF,OAAA,CAAAU,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"file":"cookie.js","names":["setCookie","cookieName","cookieValue","a","Date","setTime","getTime","document","cookie","toGMTString","handleCorrelationIDCookie","correlationId","window","crypto","randomUUID","exports"],"sources":["../../src/tracking/cookie.js"],"sourcesContent":["// general cookie setter, expires after 30 minutes\nexport function setCookie(cookieName, cookieValue) {\n const a = new Date();\n // set to expire after 30 minutes, or 1.8 million milliseconds\n a.setTime(a.getTime() + 1800000);\n document.cookie = `${cookieName}\\x3d${cookieValue}; expires\\x3d${a.toGMTString()}; path\\x3d/; domain\\x3d.edx.org;`;\n}\n\nexport const handleCorrelationIDCookie = () => {\n // set correlation ID to a random UUID\n const correlationId = window.crypto.randomUUID();\n\n setCookie('tglr_correlation_id', correlationId);\n return correlationId;\n};\n"],"mappings":";;;;;;;AAAA;AACO,SAASA,SAASA,CAACC,UAAU,EAAEC,WAAW,EAAE;EACjD,MAAMC,CAAC,GAAG,IAAIC,IAAI,CAAC,CAAC;EACpB;EACAD,CAAC,CAACE,OAAO,CAACF,CAAC,CAACG,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;EAChCC,QAAQ,CAACC,MAAM,GAAG,GAAGP,UAAU,OAAOC,WAAW,gBAAgBC,CAAC,CAACM,WAAW,CAAC,CAAC,kCAAkC;AACpH;AAEO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C;EACA,MAAMC,aAAa,GAAGC,MAAM,CAACC,MAAM,CAACC,UAAU,CAAC,CAAC;EAEhDd,SAAS,CAAC,qBAAqB,EAAEW,aAAa,CAAC;EAC/C,OAAOA,aAAa;AACtB,CAAC;AAACI,OAAA,CAAAL,yBAAA,GAAAA,yBAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-plugin-learner-dashboard",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Repository for Learner Dashboard MFE frontend plugins",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -3,6 +3,9 @@ import { useState, useEffect } from 'react';
3
3
  const CohesionWrapper = () => {
4
4
  const [isLoaded, setLoaded] = useState(false);
5
5
 
6
+ // set pageType value
7
+ window.chsn_pageType = 'lms-homepage';
8
+
6
9
  useEffect(() => {
7
10
  if (isLoaded) {
8
11
  return null;
@@ -10,6 +10,7 @@ describe('Cohesion Wrapper loads', () => {
10
10
  render(<CohesionWrapper />);
11
11
  const script = document.getElementsByTagName('script')[0];
12
12
 
13
+ expect(window.chsn_pageType).toEqual('lms-homepage');
13
14
  expect(script.dataset.testId).toEqual('cohesion-test');
14
15
  });
15
16
  });
@@ -1,41 +1,15 @@
1
- export const getCorrelationIDCookie = () => {
2
- const name = 'tglr_correlation_id=';
3
- const decodedCookie = decodeURIComponent(document.cookie);
4
- const cookieArray = decodedCookie.split(';');
5
-
6
- for (let i = 0; i < cookieArray.length; i++) {
7
- const cookie = cookieArray[i].trim();
8
- if (cookie.indexOf(name) === 0) {
9
- return cookie.substring(name.length, cookie.length);
10
- }
11
- }
12
-
13
- return '';
14
- };
15
-
16
- export const setCorrelationIDCookie = (correlationId) => {
17
- const now = new Date();
18
- const time = now.getTime();
19
-
20
- // Cookie expires in 30 minutes, same as when set in marketing page
21
- const expireTime = time + 1800;
22
- now.setTime(expireTime);
23
- document.cookie = `tglr_correlation_id=${correlationId}; expires=${now.toUTCString()}; path=/`;
24
- };
1
+ // general cookie setter, expires after 30 minutes
2
+ export function setCookie(cookieName, cookieValue) {
3
+ const a = new Date();
4
+ // set to expire after 30 minutes, or 1.8 million milliseconds
5
+ a.setTime(a.getTime() + 1800000);
6
+ document.cookie = `${cookieName}\x3d${cookieValue}; expires\x3d${a.toGMTString()}; path\x3d/; domain\x3d.edx.org;`;
7
+ }
25
8
 
26
9
  export const handleCorrelationIDCookie = () => {
27
- // Get correlation ID from URL or cookies if it exists, otherwise set to random UUID
28
- const queryString = window.location.search;
29
- const urlParams = new URLSearchParams(queryString);
30
- const correlationCookie = getCorrelationIDCookie();
31
- const randomUUID = window.crypto.randomUUID();
32
-
33
- const correlationId = urlParams.get('correlationId') || correlationCookie || randomUUID;
34
-
35
- // Set CorrelationID cookie if one wasn't set
36
- if (correlationCookie !== correlationId) {
37
- setCorrelationIDCookie(correlationId);
38
- }
10
+ // set correlation ID to a random UUID
11
+ const correlationId = window.crypto.randomUUID();
39
12
 
13
+ setCookie('tglr_correlation_id', correlationId);
40
14
  return correlationId;
41
15
  };
@@ -12,63 +12,23 @@ describe('cookie functions for Correlation ID', () => {
12
12
  randomUUID: jest.fn(() => 'mocked-random-uuid'),
13
13
  },
14
14
  });
15
-
16
- jest.spyOn(global, 'decodeURIComponent').mockImplementation((val) => val);
17
15
  });
18
16
 
19
17
  afterEach(() => {
20
18
  jest.restoreAllMocks(); // Restore the original document.cookie
21
19
  });
22
20
 
23
- describe('getCorrelationIDCookie', () => {
24
- it('returns the Correlation ID cookie if present', () => {
25
- document.cookie = 'tglr_correlation_id=some_uuid_string;another_cookie=another_string';
26
- decodeURIComponent.mockReturnValue(document.cookie);
27
-
28
- expect(cookieFunctions.getCorrelationIDCookie()).toEqual('some_uuid_string');
29
- });
30
-
31
- it('returns an empty string when there is no CorrelationID present', () => {
32
- document.cookie = 'cookie=string';
33
- decodeURIComponent.mockReturnValue(document.cookie);
34
-
35
- expect(cookieFunctions.getCorrelationIDCookie()).toEqual('');
36
- });
37
- });
38
-
39
- describe('setCorrelationIDCookie', () => {
21
+ describe('setCookie', () => {
40
22
  it('sets the Correlation ID cookie', () => {
41
23
  const correlationCookie = 'some_uuid_string';
42
- cookieFunctions.setCorrelationIDCookie(correlationCookie);
24
+ cookieFunctions.setCookie('tglr_correlation_id', correlationCookie);
43
25
 
44
26
  expect(document.cookie).toContain(`tglr_correlation_id=${correlationCookie}`);
45
27
  });
46
28
  });
47
29
 
48
30
  describe('handleCorrelationIDCookie', () => {
49
- it('returns the correlation ID from the URL parameters', () => {
50
- jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('correlation_id_uuid');
51
-
52
- expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('correlation_id_uuid');
53
- expect(document.cookie).toContain('tglr_correlation_id=correlation_id_uuid');
54
- });
55
-
56
- it('returns the correlation ID from the cookies', () => {
57
- Object.defineProperty(document, 'cookie', {
58
- writable: true,
59
- value: 'tglr_correlation_id=correlation_id_cookie',
60
- });
61
-
62
- jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('');
63
- jest.spyOn(cookieFunctions, 'getCorrelationIDCookie').mockImplementation(() => 'correlation_id_cookie');
64
-
65
- expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('correlation_id_cookie');
66
- });
67
-
68
31
  it('returns the correlation ID provided by a random UUID generator', () => {
69
- jest.spyOn(URLSearchParams.prototype, 'get').mockReturnValueOnce('');
70
- jest.spyOn(cookieFunctions, 'getCorrelationIDCookie').mockImplementation(() => '');
71
-
72
32
  expect(cookieFunctions.handleCorrelationIDCookie()).toEqual('mocked-random-uuid');
73
33
  });
74
34
  });