@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.
- package/dist/cohesion-wrapper/CohesionWrapper.js +3 -0
- package/dist/cohesion-wrapper/CohesionWrapper.js.map +1 -1
- package/dist/tracking/cookie.js +12 -35
- package/dist/tracking/cookie.js.map +1 -1
- package/package.json +1 -1
- package/src/cohesion-wrapper/CohesionWrapper.jsx +3 -0
- package/src/cohesion-wrapper/CohesionWrapper.test.jsx +1 -0
- package/src/tracking/cookie.js +10 -36
- package/src/tracking/cookie.test.js +2 -42
|
@@ -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;
|
|
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":[]}
|
package/dist/tracking/cookie.js
CHANGED
|
@@ -3,42 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
//
|
|
32
|
-
const
|
|
33
|
-
|
|
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":["
|
|
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
|
@@ -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
|
});
|
package/src/tracking/cookie.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
//
|
|
28
|
-
const
|
|
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('
|
|
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.
|
|
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
|
});
|