@edx/frontend-platform 4.6.2 → 4.6.3

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.
Files changed (229) hide show
  1. package/package.json +1 -1
  2. package/.env.development +0 -30
  3. package/.env.test +0 -30
  4. package/.eslintignore +0 -6
  5. package/.eslintrc.js +0 -28
  6. package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  7. package/.github/workflows/add-depr-ticket-to-depr-board.yml +0 -19
  8. package/.github/workflows/add-remove-label-on-comment.yml +0 -20
  9. package/.github/workflows/ci.yml +0 -42
  10. package/.github/workflows/commitlint.yml +0 -10
  11. package/.github/workflows/lockfileversion-check.yml +0 -13
  12. package/.github/workflows/manual-publish.yml +0 -43
  13. package/.github/workflows/npm-deprecate.yml +0 -22
  14. package/.github/workflows/release.yml +0 -45
  15. package/.github/workflows/self-assign-issue.yml +0 -12
  16. package/.github/workflows/update-browserslist-db.yml +0 -12
  17. package/.nvmrc +0 -1
  18. package/.releaserc +0 -32
  19. package/catalog-info.yaml +0 -21
  20. package/dist/LICENSE +0 -661
  21. package/dist/README.md +0 -155
  22. package/dist/package.json +0 -86
  23. package/docs/addTagsPlugin.js +0 -10
  24. package/docs/auth-API.md +0 -114
  25. package/docs/decisions/0001-record-architecture-decisions.rst +0 -32
  26. package/docs/decisions/0002-frontend-base-design-goals.rst +0 -222
  27. package/docs/decisions/0003-consolidation-into-frontend-platform.rst +0 -71
  28. package/docs/decisions/0004-axios-caching-implementation.rst +0 -88
  29. package/docs/decisions/0005-token-null-after-successful-refresh.rst +0 -69
  30. package/docs/decisions/0006-middleware-support-for-http-clients.rst +0 -44
  31. package/docs/decisions/0007-javascript-file-configuration.rst +0 -143
  32. package/docs/how_tos/automatic-case-conversion.rst +0 -58
  33. package/docs/how_tos/caching.rst +0 -93
  34. package/docs/how_tos/i18n.rst +0 -305
  35. package/docs/removeExport.js +0 -24
  36. package/docs/template/edx/README.md +0 -12
  37. package/docs/template/edx/publish.js +0 -713
  38. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  39. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.svg +0 -1830
  40. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  41. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  42. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  43. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  44. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  45. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.svg +0 -1830
  46. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  47. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.eot +0 -0
  48. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.svg +0 -1831
  49. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.woff +0 -0
  50. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  51. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  52. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  53. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  54. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.svg +0 -1831
  55. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  56. package/docs/template/edx/static/scripts/linenumber.js +0 -25
  57. package/docs/template/edx/static/scripts/prettify/Apache-License-2.0.txt +0 -202
  58. package/docs/template/edx/static/scripts/prettify/lang-css.js +0 -2
  59. package/docs/template/edx/static/scripts/prettify/prettify.js +0 -28
  60. package/docs/template/edx/static/styles/jsdoc-default.css +0 -356
  61. package/docs/template/edx/static/styles/prettify-jsdoc.css +0 -111
  62. package/docs/template/edx/static/styles/prettify-tomorrow.css +0 -132
  63. package/docs/template/edx/tmpl/augments.tmpl +0 -10
  64. package/docs/template/edx/tmpl/container.tmpl +0 -196
  65. package/docs/template/edx/tmpl/details.tmpl +0 -143
  66. package/docs/template/edx/tmpl/example.tmpl +0 -2
  67. package/docs/template/edx/tmpl/examples.tmpl +0 -13
  68. package/docs/template/edx/tmpl/exceptions.tmpl +0 -32
  69. package/docs/template/edx/tmpl/layout.tmpl +0 -39
  70. package/docs/template/edx/tmpl/mainpage.tmpl +0 -10
  71. package/docs/template/edx/tmpl/members.tmpl +0 -38
  72. package/docs/template/edx/tmpl/method.tmpl +0 -131
  73. package/docs/template/edx/tmpl/modifies.tmpl +0 -14
  74. package/docs/template/edx/tmpl/params.tmpl +0 -131
  75. package/docs/template/edx/tmpl/properties.tmpl +0 -108
  76. package/docs/template/edx/tmpl/returns.tmpl +0 -19
  77. package/docs/template/edx/tmpl/source.tmpl +0 -8
  78. package/docs/template/edx/tmpl/tutorial.tmpl +0 -19
  79. package/docs/template/edx/tmpl/type.tmpl +0 -7
  80. package/env.config.js +0 -8
  81. package/jsdoc.json +0 -36
  82. package/openedx.yaml +0 -12
  83. package/service-interface.png +0 -0
  84. package/src/analytics/MockAnalyticsService.js +0 -71
  85. package/src/analytics/SegmentAnalyticsService.js +0 -243
  86. package/src/analytics/index.js +0 -12
  87. package/src/analytics/interface.js +0 -142
  88. package/src/auth/AxiosCsrfTokenService.js +0 -60
  89. package/src/auth/AxiosJwtAuthService.js +0 -364
  90. package/src/auth/AxiosJwtTokenService.js +0 -134
  91. package/src/auth/LocalForageCache.js +0 -78
  92. package/src/auth/MockAuthService.js +0 -285
  93. package/src/auth/index.js +0 -19
  94. package/src/auth/interceptors/createCsrfTokenProviderInterceptor.js +0 -37
  95. package/src/auth/interceptors/createJwtTokenProviderInterceptor.js +0 -38
  96. package/src/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js +0 -20
  97. package/src/auth/interceptors/createRetryInterceptor.js +0 -72
  98. package/src/auth/interface.js +0 -309
  99. package/src/auth/utils.js +0 -105
  100. package/src/config.js +0 -327
  101. package/src/constants.js +0 -66
  102. package/src/i18n/countries.js +0 -57
  103. package/src/i18n/index.js +0 -123
  104. package/src/i18n/injectIntlWithShim.jsx +0 -45
  105. package/src/i18n/languages.js +0 -60
  106. package/src/i18n/lib.js +0 -282
  107. package/src/i18n/scripts/README.md +0 -29
  108. package/src/i18n/scripts/intl-imports.js +0 -259
  109. package/src/i18n/scripts/transifex-utils.js +0 -75
  110. package/src/index.js +0 -42
  111. package/src/initialize.js +0 -357
  112. package/src/logging/MockLoggingService.js +0 -31
  113. package/src/logging/NewRelicLoggingService.js +0 -181
  114. package/src/logging/index.js +0 -9
  115. package/src/logging/interface.js +0 -110
  116. package/src/pubSub.js +0 -47
  117. package/src/react/AppContext.jsx +0 -24
  118. package/src/react/AppProvider.jsx +0 -93
  119. package/src/react/AuthenticatedPageRoute.jsx +0 -60
  120. package/src/react/ErrorBoundary.jsx +0 -44
  121. package/src/react/ErrorPage.jsx +0 -76
  122. package/src/react/LoginRedirect.jsx +0 -16
  123. package/src/react/OptionalReduxProvider.jsx +0 -28
  124. package/src/react/PageRoute.jsx +0 -31
  125. package/src/react/hooks.js +0 -50
  126. package/src/react/index.js +0 -16
  127. package/src/scripts/GoogleAnalyticsLoader.js +0 -53
  128. package/src/scripts/index.js +0 -2
  129. package/src/testing/index.js +0 -9
  130. package/src/testing/initializeMockApp.js +0 -77
  131. package/src/testing/mockMessages.js +0 -21
  132. package/src/utils.js +0 -167
  133. /package/{dist/analytics → analytics}/MockAnalyticsService.js +0 -0
  134. /package/{dist/analytics → analytics}/MockAnalyticsService.js.map +0 -0
  135. /package/{dist/analytics → analytics}/SegmentAnalyticsService.js +0 -0
  136. /package/{dist/analytics → analytics}/SegmentAnalyticsService.js.map +0 -0
  137. /package/{dist/analytics → analytics}/index.js +0 -0
  138. /package/{dist/analytics → analytics}/index.js.map +0 -0
  139. /package/{dist/analytics → analytics}/interface.js +0 -0
  140. /package/{dist/analytics → analytics}/interface.js.map +0 -0
  141. /package/{dist/auth → auth}/AxiosCsrfTokenService.js +0 -0
  142. /package/{dist/auth → auth}/AxiosCsrfTokenService.js.map +0 -0
  143. /package/{dist/auth → auth}/AxiosJwtAuthService.js +0 -0
  144. /package/{dist/auth → auth}/AxiosJwtAuthService.js.map +0 -0
  145. /package/{dist/auth → auth}/AxiosJwtTokenService.js +0 -0
  146. /package/{dist/auth → auth}/AxiosJwtTokenService.js.map +0 -0
  147. /package/{dist/auth → auth}/LocalForageCache.js +0 -0
  148. /package/{dist/auth → auth}/LocalForageCache.js.map +0 -0
  149. /package/{dist/auth → auth}/MockAuthService.js +0 -0
  150. /package/{dist/auth → auth}/MockAuthService.js.map +0 -0
  151. /package/{dist/auth → auth}/index.js +0 -0
  152. /package/{dist/auth → auth}/index.js.map +0 -0
  153. /package/{dist/auth → auth}/interceptors/createCsrfTokenProviderInterceptor.js +0 -0
  154. /package/{dist/auth → auth}/interceptors/createCsrfTokenProviderInterceptor.js.map +0 -0
  155. /package/{dist/auth → auth}/interceptors/createJwtTokenProviderInterceptor.js +0 -0
  156. /package/{dist/auth → auth}/interceptors/createJwtTokenProviderInterceptor.js.map +0 -0
  157. /package/{dist/auth → auth}/interceptors/createProcessAxiosRequestErrorInterceptor.js +0 -0
  158. /package/{dist/auth → auth}/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +0 -0
  159. /package/{dist/auth → auth}/interceptors/createRetryInterceptor.js +0 -0
  160. /package/{dist/auth → auth}/interceptors/createRetryInterceptor.js.map +0 -0
  161. /package/{dist/auth → auth}/interface.js +0 -0
  162. /package/{dist/auth → auth}/interface.js.map +0 -0
  163. /package/{dist/auth → auth}/utils.js +0 -0
  164. /package/{dist/auth → auth}/utils.js.map +0 -0
  165. /package/{dist/config.js → config.js} +0 -0
  166. /package/{dist/config.js.map → config.js.map} +0 -0
  167. /package/{dist/constants.js → constants.js} +0 -0
  168. /package/{dist/constants.js.map → constants.js.map} +0 -0
  169. /package/{dist/i18n → i18n}/countries.js +0 -0
  170. /package/{dist/i18n → i18n}/countries.js.map +0 -0
  171. /package/{dist/i18n → i18n}/index.js +0 -0
  172. /package/{dist/i18n → i18n}/index.js.map +0 -0
  173. /package/{dist/i18n → i18n}/injectIntlWithShim.js +0 -0
  174. /package/{dist/i18n → i18n}/injectIntlWithShim.js.map +0 -0
  175. /package/{dist/i18n → i18n}/languages.js +0 -0
  176. /package/{dist/i18n → i18n}/languages.js.map +0 -0
  177. /package/{dist/i18n → i18n}/lib.js +0 -0
  178. /package/{dist/i18n → i18n}/lib.js.map +0 -0
  179. /package/{dist/i18n → i18n}/scripts/README.md +0 -0
  180. /package/{dist/i18n → i18n}/scripts/intl-imports.js +0 -0
  181. /package/{dist/i18n → i18n}/scripts/intl-imports.js.map +0 -0
  182. /package/{dist/i18n → i18n}/scripts/transifex-utils.js +0 -0
  183. /package/{dist/i18n → i18n}/scripts/transifex-utils.js.map +0 -0
  184. /package/{dist/index.js → index.js} +0 -0
  185. /package/{dist/index.js.map → index.js.map} +0 -0
  186. /package/{dist/initialize.js → initialize.js} +0 -0
  187. /package/{dist/initialize.js.map → initialize.js.map} +0 -0
  188. /package/{dist/logging → logging}/MockLoggingService.js +0 -0
  189. /package/{dist/logging → logging}/MockLoggingService.js.map +0 -0
  190. /package/{dist/logging → logging}/NewRelicLoggingService.js +0 -0
  191. /package/{dist/logging → logging}/NewRelicLoggingService.js.map +0 -0
  192. /package/{dist/logging → logging}/index.js +0 -0
  193. /package/{dist/logging → logging}/index.js.map +0 -0
  194. /package/{dist/logging → logging}/interface.js +0 -0
  195. /package/{dist/logging → logging}/interface.js.map +0 -0
  196. /package/{dist/pubSub.js → pubSub.js} +0 -0
  197. /package/{dist/pubSub.js.map → pubSub.js.map} +0 -0
  198. /package/{dist/react → react}/AppContext.js +0 -0
  199. /package/{dist/react → react}/AppContext.js.map +0 -0
  200. /package/{dist/react → react}/AppProvider.js +0 -0
  201. /package/{dist/react → react}/AppProvider.js.map +0 -0
  202. /package/{dist/react → react}/AuthenticatedPageRoute.js +0 -0
  203. /package/{dist/react → react}/AuthenticatedPageRoute.js.map +0 -0
  204. /package/{dist/react → react}/ErrorBoundary.js +0 -0
  205. /package/{dist/react → react}/ErrorBoundary.js.map +0 -0
  206. /package/{dist/react → react}/ErrorPage.js +0 -0
  207. /package/{dist/react → react}/ErrorPage.js.map +0 -0
  208. /package/{dist/react → react}/LoginRedirect.js +0 -0
  209. /package/{dist/react → react}/LoginRedirect.js.map +0 -0
  210. /package/{dist/react → react}/OptionalReduxProvider.js +0 -0
  211. /package/{dist/react → react}/OptionalReduxProvider.js.map +0 -0
  212. /package/{dist/react → react}/PageRoute.js +0 -0
  213. /package/{dist/react → react}/PageRoute.js.map +0 -0
  214. /package/{dist/react → react}/hooks.js +0 -0
  215. /package/{dist/react → react}/hooks.js.map +0 -0
  216. /package/{dist/react → react}/index.js +0 -0
  217. /package/{dist/react → react}/index.js.map +0 -0
  218. /package/{dist/scripts → scripts}/GoogleAnalyticsLoader.js +0 -0
  219. /package/{dist/scripts → scripts}/GoogleAnalyticsLoader.js.map +0 -0
  220. /package/{dist/scripts → scripts}/index.js +0 -0
  221. /package/{dist/scripts → scripts}/index.js.map +0 -0
  222. /package/{dist/testing → testing}/index.js +0 -0
  223. /package/{dist/testing → testing}/index.js.map +0 -0
  224. /package/{dist/testing → testing}/initializeMockApp.js +0 -0
  225. /package/{dist/testing → testing}/initializeMockApp.js.map +0 -0
  226. /package/{dist/testing → testing}/mockMessages.js +0 -0
  227. /package/{dist/testing → testing}/mockMessages.js.map +0 -0
  228. /package/{dist/utils.js → utils.js} +0 -0
  229. /package/{dist/utils.js.map → utils.js.map} +0 -0
@@ -1,243 +0,0 @@
1
- import formurlencoded from 'form-urlencoded';
2
- import { snakeCaseObject } from '../utils';
3
-
4
- /**
5
- * @implements {AnalyticsService}
6
- * @memberof module:Analytics
7
- */
8
- class SegmentAnalyticsService {
9
- constructor({ httpClient, loggingService, config }) {
10
- this.loggingService = loggingService;
11
- this.httpClient = httpClient;
12
- this.trackingLogApiUrl = `${config.LMS_BASE_URL}/event`;
13
- this.segmentKey = config.SEGMENT_KEY;
14
- this.hasIdentifyBeenCalled = false;
15
- this.segmentInitialized = false;
16
-
17
- if (this.segmentKey) {
18
- this.initializeSegment();
19
- }
20
- }
21
-
22
- // The code in this function is from Segment's website, with a few updates:
23
- // - It uses the segmentKey from the SegmentAnalyticsService instance.
24
- // - It also saves a "segmentInitialized" variable on the SegmentAnalyticsService instance so
25
- // that the service can keep track of its own initialization state.
26
- // Reference:
27
- // https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/
28
- initializeSegment() {
29
- // Create a queue, but don't obliterate an existing one!
30
- global.analytics = global.analytics || [];
31
- const { analytics } = global;
32
-
33
- // If the real analytics.js is already on the page return.
34
- if (analytics.initialize) {
35
- this.segmentInitialized = true;
36
- return;
37
- }
38
-
39
- // If the snippet was invoked do nothing.
40
- if (analytics.invoked) {
41
- this.segmentInitialized = true;
42
- return;
43
- }
44
-
45
- // Invoked flag, to make sure the snippet
46
- // is never invoked twice.
47
- analytics.invoked = true;
48
-
49
- // A list of the methods in Analytics.js to stub.
50
- analytics.methods = [
51
- 'trackSubmit',
52
- 'trackClick',
53
- 'trackLink',
54
- 'trackForm',
55
- 'pageview',
56
- 'identify',
57
- 'reset',
58
- 'group',
59
- 'track',
60
- 'ready',
61
- 'alias',
62
- 'debug',
63
- 'page',
64
- 'once',
65
- 'off',
66
- 'on',
67
- ];
68
-
69
- // Define a factory to create stubs. These are placeholders
70
- // for methods in Analytics.js so that you never have to wait
71
- // for it to load to actually record data. The `method` is
72
- // stored as the first argument, so we can replay the data.
73
- analytics.factory = method => ((...args) => {
74
- args.unshift(method);
75
- analytics.push(args);
76
- return analytics;
77
- });
78
-
79
- // For each of our methods, generate a queueing stub.
80
- analytics.methods.forEach((key) => {
81
- analytics[key] = analytics.factory(key);
82
- });
83
-
84
- // Define a method to load Analytics.js from our CDN,
85
- // and that will be sure to only ever load it once.
86
- analytics.load = (key, options) => {
87
- // Create an async script element based on your key.
88
- const script = document.createElement('script');
89
- script.type = 'text/javascript';
90
- script.onerror = () => {
91
- this.segmentInitialized = false;
92
- const event = new Event('segmentFailed');
93
- document.dispatchEvent(event);
94
- };
95
- script.async = true;
96
- script.src = `https://cdn.segment.com/analytics.js/v1/${key}/analytics.min.js`;
97
-
98
- // Insert our script next to the first script element.
99
- const first = document.getElementsByTagName('script')[0];
100
- first.parentNode.insertBefore(script, first);
101
- analytics._loadOptions = options; // eslint-disable-line no-underscore-dangle
102
-
103
- this.segmentInitialized = true;
104
- };
105
-
106
- // Add a version to keep track of what's in the wild.
107
- analytics.SNIPPET_VERSION = '4.1.0';
108
-
109
- // Load Analytics.js with your key, which will automatically
110
- // load the tools you've enabled for your account. Boosh!
111
- analytics.load(this.segmentKey);
112
- }
113
-
114
- /**
115
- * Checks that identify was first called. Otherwise, logs error.
116
- *
117
- */
118
- checkIdentifyCalled() {
119
- if (!this.hasIdentifyBeenCalled) {
120
- this.loggingService.logError('Identify must be called before other tracking events.');
121
- }
122
- }
123
-
124
- /**
125
- * Logs events to tracking log and downstream.
126
- * For tracking log event documentation, see
127
- * https://openedx.atlassian.net/wiki/spaces/AN/pages/13205895/Event+Design+and+Review+Process
128
- *
129
- * @param {string} eventName (event_type on backend, but named to match Segment api)
130
- * @param {Object} properties (event on backend, but named properties to match Segment api)
131
- * @returns {Promise} The promise returned by HttpClient.post.
132
- */
133
- sendTrackingLogEvent(eventName, properties) {
134
- const snakeEventData = snakeCaseObject(properties, { deep: true });
135
- const serverData = {
136
- event_type: eventName,
137
- event: JSON.stringify(snakeEventData),
138
- page: global.location.href,
139
- };
140
- return this.httpClient.post(
141
- this.trackingLogApiUrl,
142
- formurlencoded(serverData),
143
- {
144
- headers: {
145
- 'Content-Type': 'application/x-www-form-urlencoded',
146
- },
147
- },
148
- ).catch((error) => {
149
- this.loggingService.logError(error);
150
- });
151
- }
152
-
153
- /**
154
- * * Send identify call to Segment.
155
- *
156
- * @param {string} userId
157
- * @param {*} [traits]
158
- */
159
- identifyAuthenticatedUser(userId, traits) {
160
- if (!userId) {
161
- throw new Error('UserId is required for identifyAuthenticatedUser.');
162
- }
163
-
164
- if (!this.segmentInitialized) {
165
- return;
166
- }
167
- global.analytics.identify(userId, traits);
168
- this.hasIdentifyBeenCalled = true;
169
- }
170
-
171
- /**
172
- * Send anonymous identify call to Segment's identify.
173
- *
174
- * @param {*} [traits]
175
- * @returns {Promise} Promise that will resolve once the document readyState is complete
176
- */
177
- identifyAnonymousUser(traits) { // eslint-disable-line no-unused-vars
178
- if (!this.segmentInitialized) {
179
- return Promise.resolve();
180
- }
181
- // if we do not have an authenticated user (indicated by being in this method),
182
- // but we still have a user id associated in segment, reset the local segment state
183
- // This has to be wrapped in the analytics.ready() callback because the analytics.user()
184
- // function isn't available until the analytics.js package has finished initializing.
185
- return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
186
- global.analytics.ready(() => {
187
- if (global.analytics.user().id()) {
188
- global.analytics.reset();
189
- }
190
- // We don’t need to call `identify` for anonymous users and can just make the value of
191
- // hasIdentifyBeenCalled true. Segment automatically assigns them an anonymousId, so
192
- // just calling `page` and `track` works fine without identify.
193
- this.hasIdentifyBeenCalled = true;
194
- resolve();
195
- });
196
-
197
- // this is added to handle a specific use-case where if a user has blocked the analytics
198
- // tools in their browser, this promise does not get resolved and user sees a blank
199
- // page. Dispatching this event in script.onerror callback in analytics.load.
200
- document.addEventListener('segmentFailed', resolve);
201
- // This is added to handle the google analytics blocked case which is injected into
202
- // the DOM by segment.min.js.
203
- setTimeout(() => {
204
- if (!global.ga || !global.ga.create || !global.google_tag_manager) {
205
- this.segmentInitialized = false;
206
- resolve();
207
- }
208
- }, 2000);
209
- });
210
- }
211
-
212
- /**
213
- * Sends a track event to Segment and downstream.
214
- * Note: For links and forms, you should use trackLink and trackForm instead.
215
- *
216
- * @param {*} eventName
217
- * @param {*} [properties]
218
- */
219
- sendTrackEvent(eventName, properties) {
220
- if (!this.segmentInitialized) {
221
- return;
222
- }
223
- this.checkIdentifyCalled();
224
- global.analytics.track(eventName, properties);
225
- }
226
-
227
- /**
228
- * Sends a page event to Segment and downstream.
229
- *
230
- * @param {*} [name] If only one string arg provided, assumed to be name.
231
- * @param {*} [category] Name is required to pass a category.
232
- * @param {*} [properties]
233
- */
234
- sendPageEvent(category, name, properties) {
235
- if (!this.segmentInitialized) {
236
- return;
237
- }
238
- this.checkIdentifyCalled();
239
- global.analytics.page(category, name, properties);
240
- }
241
- }
242
-
243
- export default SegmentAnalyticsService;
@@ -1,12 +0,0 @@
1
- export {
2
- configure,
3
- identifyAnonymousUser,
4
- identifyAuthenticatedUser,
5
- sendPageEvent,
6
- sendTrackEvent,
7
- sendTrackingLogEvent,
8
- getAnalyticsService,
9
- resetAnalyticsService,
10
- } from './interface';
11
- export { default as SegmentAnalyticsService } from './SegmentAnalyticsService';
12
- export { default as MockAnalyticsService } from './MockAnalyticsService';
@@ -1,142 +0,0 @@
1
- /**
2
- * #### Import members from **@edx/frontend-platform/analytics**
3
- *
4
- * Contains a shared interface for tracking events. Has a default implementation of
5
- * SegmentAnalyticsService, which supports Segment and the Tracking Log API (hosted in LMS).
6
- *
7
- * The `initialize` function performs much of the analytics configuration for you. If, however,
8
- * you're not using the `initialize` function, analytics can be configured via:
9
- *
10
- * ```
11
- * import { configure, SegmentAnalyticsService } from '@edx/frontend-platform/analytics';
12
- * import { getConfig } from '@edx/frontend-platform';
13
- * import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
14
- * import { getLoggingService } from '@edx/frontend-platform/logging';
15
- *
16
- * configure(SegmentAnalyticsService, {
17
- * config: getConfig(),
18
- * loggingService: getLoggingService(),
19
- * httpClient: getAuthenticatedHttpClient(),
20
- * });
21
- * ```
22
- *
23
- * As shown in this example, analytics depends on the configuration document, logging, and having
24
- * an authenticated HTTP client.
25
- *
26
- * @module Analytics
27
- */
28
- import PropTypes from 'prop-types';
29
-
30
- const optionsShape = {
31
- config: PropTypes.object.isRequired,
32
- httpClient: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
33
- loggingService: PropTypes.shape({
34
- logError: PropTypes.func.isRequired,
35
- logInfo: PropTypes.func.isRequired,
36
- }).isRequired,
37
- };
38
-
39
- const serviceShape = {
40
- sendTrackingLogEvent: PropTypes.func.isRequired,
41
- identifyAuthenticatedUser: PropTypes.func.isRequired,
42
- identifyAnonymousUser: PropTypes.func.isRequired,
43
- sendTrackEvent: PropTypes.func.isRequired,
44
- sendPageEvent: PropTypes.func.isRequired,
45
- };
46
-
47
- let service;
48
-
49
- /**
50
- *
51
- * @param {class} AnalyticsService
52
- * @param {*} options
53
- * @returns {AnalyticsService}
54
- */
55
- export function configure(AnalyticsService, options) {
56
- PropTypes.checkPropTypes(optionsShape, options, 'property', 'Analytics');
57
- service = new AnalyticsService(options);
58
- PropTypes.checkPropTypes(serviceShape, service, 'property', 'AnalyticsService');
59
- return service;
60
- }
61
-
62
- /**
63
- *
64
- * @param {*} eventName
65
- * @param {*} properties
66
- * @returns {Promise}
67
- */
68
- export function sendTrackingLogEvent(eventName, properties) {
69
- return service.sendTrackingLogEvent(eventName, properties);
70
- }
71
-
72
- /**
73
- *
74
- *
75
- * @param {*} userId
76
- * @param {*} traits
77
- */
78
- export function identifyAuthenticatedUser(userId, traits) {
79
- service.identifyAuthenticatedUser(userId, traits);
80
- }
81
-
82
- /**
83
- *
84
- *
85
- * @param {*} traits
86
- * @returns {Promise}
87
- */
88
- export function identifyAnonymousUser(traits) {
89
- return service.identifyAnonymousUser(traits);
90
- }
91
-
92
- /**
93
- *
94
- *
95
- * @param {*} eventName
96
- * @param {*} properties
97
- */
98
- export function sendTrackEvent(eventName, properties) {
99
- service.sendTrackEvent(eventName, properties);
100
- }
101
-
102
- /**
103
- *
104
- *
105
- * @param {*} category
106
- * @param {*} name
107
- * @param {*} properties
108
- */
109
- export function sendPageEvent(category, name, properties) {
110
- service.sendPageEvent(category, name, properties);
111
- }
112
-
113
- /**
114
- *
115
- *
116
- * @returns {AnalyticsService}
117
- */
118
- export function getAnalyticsService() {
119
- if (!service) {
120
- throw Error('You must first configure the analytics service.');
121
- }
122
-
123
- return service;
124
- }
125
-
126
- /**
127
- *
128
- */
129
- export function resetAnalyticsService() {
130
- service = null;
131
- }
132
-
133
- /**
134
- * @name AnalyticsService
135
- * @interface
136
- * @memberof module:Analytics
137
- * @property {function} identifyAnonymousUser
138
- * @property {function} identifyAuthenticatedUser
139
- * @property {function} sendPageEvent
140
- * @property {function} sendTrackEvent
141
- * @property {function} sendTrackingLogEvent
142
- */
@@ -1,60 +0,0 @@
1
- import axios from 'axios';
2
- import { getUrlParts, processAxiosErrorAndThrow } from './utils';
3
-
4
- export default class AxiosCsrfTokenService {
5
- constructor(csrfTokenApiPath) {
6
- this.csrfTokenApiPath = csrfTokenApiPath;
7
- this.httpClient = axios.create();
8
- // Set withCredentials to true. Enables cross-site Access-Control requests
9
- // to be made using cookies, authorization headers or TLS client
10
- // certificates. More on MDN:
11
- // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
12
- this.httpClient.defaults.withCredentials = true;
13
- this.httpClient.defaults.headers.common['USE-JWT-COOKIE'] = true;
14
-
15
- this.csrfTokenCache = {};
16
- this.csrfTokenRequestPromises = {};
17
- }
18
-
19
- async getCsrfToken(url) {
20
- let urlParts;
21
- try {
22
- urlParts = getUrlParts(url);
23
- } catch (e) {
24
- // If the url is not parsable it's likely because a relative
25
- // path was supplied as the url. This is acceptable and in
26
- // this case we should use the current origin of the page.
27
- urlParts = getUrlParts(global.location.origin);
28
- }
29
-
30
- const { protocol, domain } = urlParts;
31
- const csrfToken = this.csrfTokenCache[domain];
32
-
33
- if (csrfToken) {
34
- return csrfToken;
35
- }
36
-
37
- if (!this.csrfTokenRequestPromises[domain]) {
38
- this.csrfTokenRequestPromises[domain] = this.httpClient
39
- .get(`${protocol}://${domain}${this.csrfTokenApiPath}`)
40
- .then((response) => {
41
- this.csrfTokenCache[domain] = response.data.csrfToken;
42
- return this.csrfTokenCache[domain];
43
- })
44
- .catch(processAxiosErrorAndThrow)
45
- .finally(() => {
46
- delete this.csrfTokenRequestPromises[domain];
47
- });
48
- }
49
-
50
- return this.csrfTokenRequestPromises[domain];
51
- }
52
-
53
- clearCsrfTokenCache() {
54
- this.csrfTokenCache = {};
55
- }
56
-
57
- getHttpClient() {
58
- return this.httpClient;
59
- }
60
- }