@frontegg/js 6.139.0-alpha.2 → 6.139.0-alpha.4

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.
@@ -57,7 +57,6 @@ export declare class FronteggApp {
57
57
  logout(): void;
58
58
  loadScript(component: string): Promise<unknown>;
59
59
  loadLoginBox(): Promise<void>;
60
- loadGTM(): void;
61
60
  showAdminPortal(): Promise<void>;
62
61
  hideAdminPortal(): void;
63
62
  showCheckoutDialog(opts: FronteggCheckoutDialogOptions): Promise<void>;
@@ -13,6 +13,7 @@ import * as FronteggRestApi from '@frontegg/rest-api';
13
13
  import * as FronteggTypes from '@frontegg/types';
14
14
  import versions from '../version';
15
15
  import { mockFlagsList } from '../utils/mockFlagsList';
16
+ import { loadGTM } from './utils';
16
17
  export var FronteggApp = /*#__PURE__*/function () {
17
18
  function FronteggApp(_options, name) {
18
19
  var _this = this,
@@ -223,7 +224,7 @@ export var FronteggApp = /*#__PURE__*/function () {
223
224
  case 11:
224
225
  if (!this.options.previewMode && !this.options.customLoginBox) {
225
226
  this.loadLoginBox();
226
- this.loadGTM();
227
+ loadGTM(this.name);
227
228
  }
228
229
  if (!this.options.lazyLoadAdminPortal) {
229
230
  this.loadScript('FronteggAdminPortal');
@@ -367,30 +368,6 @@ export var FronteggApp = /*#__PURE__*/function () {
367
368
  }
368
369
  return loadLoginBox;
369
370
  }()
370
- }, {
371
- key: "loadGTM",
372
- value: function loadGTM() {
373
- // fetch key from backend. generate script and no script only when the gtm key is loaded
374
- // noscript is used for cases where js is not enabled in the browser. I think that noscript is not needed but it should be verified.
375
-
376
- // Q: where the key comes from?
377
- // Q: where the key is set in the metadata if so?
378
- var metadata = Metadata.getInstance(this.name);
379
- var gtmKeysConfig = metadata == null ? void 0 : metadata.integrations.gtm; //'GTM-PD6MBZX2';//'GTM-WG233XFQ';
380
-
381
- gtmKeysConfig == null ? void 0 : gtmKeysConfig.filter(function (_ref4) {
382
- var enabled = _ref4.enabled;
383
- return enabled;
384
- }).forEach(function (_ref5) {
385
- var id = _ref5.id;
386
- // Load GTM container script dynamically
387
- var script = document.createElement('script');
388
- script.innerHTML = "\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','".concat(id, "');\n ");
389
-
390
- // Q: Does it important where to locate the script? login box has a container, admin box as well - for the script
391
- document.body.appendChild(script);
392
- });
393
- }
394
371
  }, {
395
372
  key: "showAdminPortal",
396
373
  value: function () {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * load gtm scripts by using metadata gtm keys
3
+ * @param fronteggAppName
4
+ */
5
+ export declare const loadGTM: (fronteggAppName: string) => void;
@@ -0,0 +1,33 @@
1
+ import { Metadata } from '@frontegg/types';
2
+
3
+ /**
4
+ * To prevent XSS attack, this function check for gtm key validity
5
+ * XSS attack may happen if values are injected by postman because we don't have validity check in the BE
6
+ *
7
+ * @param key gtm key
8
+ * @returns true if gtm key is valid: starts with GTM- and contains letters and digits only
9
+ */
10
+ var isValidGTMKey = function isValidGTMKey(key) {
11
+ return /^GTM-[a-zA-Z0-9]+$/.test(key);
12
+ };
13
+
14
+ /**
15
+ * load gtm scripts by using metadata gtm keys
16
+ * @param fronteggAppName
17
+ */
18
+ export var loadGTM = function loadGTM(fronteggAppName) {
19
+ var _metadata$integration;
20
+ var metadata = Metadata.getInstance(fronteggAppName);
21
+ var gtmKeysConfig = metadata == null ? void 0 : (_metadata$integration = metadata.integrations) == null ? void 0 : _metadata$integration.gtm;
22
+ gtmKeysConfig == null ? void 0 : gtmKeysConfig.filter(function (_ref) {
23
+ var id = _ref.id,
24
+ enabled = _ref.enabled;
25
+ return enabled && isValidGTMKey(id);
26
+ }).forEach(function (_ref2) {
27
+ var id = _ref2.id;
28
+ // Load GTM container script dynamically
29
+ var script = document.createElement('script');
30
+ script.innerHTML = "\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','".concat(id, "');\n ");
31
+ document.body.appendChild(script);
32
+ });
33
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.139.0-alpha.2
1
+ /** @license Frontegg v6.139.0-alpha.4
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -18,6 +18,7 @@ var _AppHolder = require("../AppHolder");
18
18
  var FronteggRestApi = _interopRequireWildcard(require("@frontegg/rest-api"));
19
19
  var _version = _interopRequireDefault(require("../version"));
20
20
  var _mockFlagsList = require("../utils/mockFlagsList");
21
+ var _utils2 = require("./utils");
21
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
24
  var FronteggApp = /*#__PURE__*/function () {
@@ -230,7 +231,7 @@ var FronteggApp = /*#__PURE__*/function () {
230
231
  case 11:
231
232
  if (!this.options.previewMode && !this.options.customLoginBox) {
232
233
  this.loadLoginBox();
233
- this.loadGTM();
234
+ (0, _utils2.loadGTM)(this.name);
234
235
  }
235
236
  if (!this.options.lazyLoadAdminPortal) {
236
237
  this.loadScript('FronteggAdminPortal');
@@ -374,30 +375,6 @@ var FronteggApp = /*#__PURE__*/function () {
374
375
  }
375
376
  return loadLoginBox;
376
377
  }()
377
- }, {
378
- key: "loadGTM",
379
- value: function loadGTM() {
380
- // fetch key from backend. generate script and no script only when the gtm key is loaded
381
- // noscript is used for cases where js is not enabled in the browser. I think that noscript is not needed but it should be verified.
382
-
383
- // Q: where the key comes from?
384
- // Q: where the key is set in the metadata if so?
385
- var metadata = FronteggTypes.Metadata.getInstance(this.name);
386
- var gtmKeysConfig = metadata == null ? void 0 : metadata.integrations.gtm; //'GTM-PD6MBZX2';//'GTM-WG233XFQ';
387
-
388
- gtmKeysConfig == null ? void 0 : gtmKeysConfig.filter(function (_ref4) {
389
- var enabled = _ref4.enabled;
390
- return enabled;
391
- }).forEach(function (_ref5) {
392
- var id = _ref5.id;
393
- // Load GTM container script dynamically
394
- var script = document.createElement('script');
395
- script.innerHTML = "\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','".concat(id, "');\n ");
396
-
397
- // Q: Does it important where to locate the script? login box has a container, admin box as well - for the script
398
- document.body.appendChild(script);
399
- });
400
- }
401
378
  }, {
402
379
  key: "showAdminPortal",
403
380
  value: function () {
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadGTM = void 0;
7
+ var _types = require("@frontegg/types");
8
+ /**
9
+ * To prevent XSS attack, this function check for gtm key validity
10
+ * XSS attack may happen if values are injected by postman because we don't have validity check in the BE
11
+ *
12
+ * @param key gtm key
13
+ * @returns true if gtm key is valid: starts with GTM- and contains letters and digits only
14
+ */
15
+ var isValidGTMKey = function isValidGTMKey(key) {
16
+ return /^GTM-[a-zA-Z0-9]+$/.test(key);
17
+ };
18
+
19
+ /**
20
+ * load gtm scripts by using metadata gtm keys
21
+ * @param fronteggAppName
22
+ */
23
+ var loadGTM = function loadGTM(fronteggAppName) {
24
+ var _metadata$integration;
25
+ var metadata = _types.Metadata.getInstance(fronteggAppName);
26
+ var gtmKeysConfig = metadata == null ? void 0 : (_metadata$integration = metadata.integrations) == null ? void 0 : _metadata$integration.gtm;
27
+ gtmKeysConfig == null ? void 0 : gtmKeysConfig.filter(function (_ref) {
28
+ var id = _ref.id,
29
+ enabled = _ref.enabled;
30
+ return enabled && isValidGTMKey(id);
31
+ }).forEach(function (_ref2) {
32
+ var id = _ref2.id;
33
+ // Load GTM container script dynamically
34
+ var script = document.createElement('script');
35
+ script.innerHTML = "\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','".concat(id, "');\n ");
36
+ document.body.appendChild(script);
37
+ });
38
+ };
39
+ exports.loadGTM = loadGTM;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.139.0-alpha.2
1
+ /** @license Frontegg v6.139.0-alpha.4
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/node/version.js CHANGED
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _default = {
8
- cdnVersion: '6.139.0-alpha.2'
8
+ cdnVersion: '6.139.0-alpha.4'
9
9
  };
10
10
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@frontegg/js",
3
- "version": "6.139.0-alpha.2",
3
+ "version": "6.139.0-alpha.4",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/types": "6.139.0-alpha.2"
9
+ "@frontegg/types": "6.139.0-alpha.4"
10
10
  },
11
11
  "browserslist": {
12
12
  "production": [