@salesforcedevs/dx-components 1.3.184 → 1.3.186

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/lwc.config.json CHANGED
@@ -88,6 +88,7 @@
88
88
  "dx/toast",
89
89
  "dx/toc",
90
90
  "dx/tooltip",
91
+ "dx/trafficLabeler",
91
92
  "dx/tree",
92
93
  "dx/typeBadge",
93
94
  "dx/vimeoPlayer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.3.184",
3
+ "version": "1.3.186",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -41,5 +41,5 @@
41
41
  "eventsourcemock": "^2.0.0",
42
42
  "luxon": "^3.1.0"
43
43
  },
44
- "gitHead": "62d15dbba57a10ae9fb4aa365f7a0b85cd6bbc44"
44
+ "gitHead": "b6fed79dc4289f3cc19a3c9dc623d19e24465d66"
45
45
  }
@@ -0,0 +1 @@
1
+ <template></template>
@@ -0,0 +1,71 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ const REDUNDANT_INSTANCE_ERROR_MESSAGE =
4
+ "Multiple <dx-traffic-labeler>s detected, this should never be the case.";
5
+
6
+ declare module globalThis {
7
+ let singletonTrafficLabelerConnected: boolean;
8
+ }
9
+
10
+ export default class TrafficLabeler extends LightningElement {
11
+ @api internalIps?: string;
12
+ @api clearbitPublicKey?: string;
13
+
14
+ connectedCallback(): void {
15
+ if (!globalThis.singletonTrafficLabelerConnected) {
16
+ globalThis.singletonTrafficLabelerConnected = true;
17
+ if (this.clearbitPublicKey) {
18
+ this.loadClearBitData();
19
+ }
20
+ if (this.internalIps) {
21
+ this.evaluateVPNAddress();
22
+ }
23
+ } else {
24
+ console.error(REDUNDANT_INSTANCE_ERROR_MESSAGE);
25
+ }
26
+ }
27
+
28
+ async loadClearBitData() {
29
+ try {
30
+ const result = await fetch(
31
+ `https://reveal.clearbit.com/v1/companies/reveal?authorization=${this.clearbitPublicKey}`
32
+ );
33
+ const json = await result.json();
34
+ if (json?.company?.name?.toLowerCase().includes("salesforce")) {
35
+ this.setTrafficType("internal");
36
+ }
37
+ } catch (error) {
38
+ console.error("fetch failed ", error);
39
+ }
40
+ }
41
+
42
+ async evaluateVPNAddress() {
43
+ try {
44
+ const ipifyResult = await fetch(
45
+ "https://api.ipify.org/?format=json"
46
+ );
47
+ const result = await ipifyResult.json();
48
+
49
+ const internalIps = this.internalIps?.split(",");
50
+
51
+ const isInternal = internalIps?.some((value) => {
52
+ const regex = new RegExp(value);
53
+ return regex.test(result.ip);
54
+ });
55
+
56
+ if (isInternal) {
57
+ this.setTrafficType("internal");
58
+ }
59
+ } catch (error) {
60
+ console.error("fetch failed ", error);
61
+ }
62
+ }
63
+
64
+ setTrafficType(trafficType: "internal" | "external") {
65
+ // @ts-ignore)
66
+ const dataLayer = (window.dataLayer = window.dataLayer || []);
67
+ dataLayer.push({
68
+ traffic_type: trafficType
69
+ });
70
+ }
71
+ }