@4site/engrid-scripts 0.23.3 → 0.23.5

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/app.js CHANGED
@@ -74,6 +74,7 @@ export class App extends ENGrid {
74
74
  new ShowHideRadioCheckboxes("transaction.giveBySelect", "giveBySelect-");
75
75
  new ShowHideRadioCheckboxes("transaction.inmem", "inmem-");
76
76
  new ShowHideRadioCheckboxes("transaction.recurrpay", "recurrpay-");
77
+ new ShowHideRadioCheckboxes("transaction.shipenabled", "shipenabled-");
77
78
  // Automatically show/hide all radios
78
79
  let radioFields = [];
79
80
  const allRadios = document.querySelectorAll("input[type=radio]");
@@ -3,9 +3,11 @@ export declare class DataLayer {
3
3
  private dataLayer;
4
4
  private _form;
5
5
  private static instance;
6
+ private encoder;
6
7
  private endOfGiftProcessStorageKey;
7
8
  private excludedFields;
8
9
  private hashedFields;
10
+ private retainedFields;
9
11
  constructor();
10
12
  static getInstance(): DataLayer;
11
13
  private transformJSON;
@@ -14,6 +16,7 @@ export declare class DataLayer {
14
16
  private attachEventListeners;
15
17
  private handleFieldValueChange;
16
18
  private hash;
19
+ private shaHash;
17
20
  private getFieldLabel;
18
21
  addEndOfGiftProcessEvent(eventName: string, eventProperties?: object): void;
19
22
  addEndOfGiftProcessVariable(variableName: string, variableValue?: any): void;
@@ -7,12 +7,22 @@
7
7
  // are replayed after a successful gift process load.
8
8
  // Sensitive payment/bank fields are excluded; selected PII fields are Base64 “hashed” (btoa — not cryptographic).
9
9
  // Replace with a real hash (e.g., SHA‑256) if required.
10
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
17
+ });
18
+ };
10
19
  import { EngridLogger, ENGrid, EnForm, RememberMeEvents } from ".";
11
20
  export class DataLayer {
12
21
  constructor() {
13
22
  this.logger = new EngridLogger("DataLayer", "#f1e5bc", "#009cdc", "📊");
14
23
  this.dataLayer = window.dataLayer || [];
15
24
  this._form = EnForm.getInstance();
25
+ this.encoder = new TextEncoder();
16
26
  this.endOfGiftProcessStorageKey = "ENGRID_END_OF_GIFT_PROCESS_EVENTS";
17
27
  this.excludedFields = [
18
28
  // Credit Card
@@ -45,6 +55,14 @@ export class DataLayer {
45
55
  "supporter.billingAddress2",
46
56
  "supporter.billingAddress3",
47
57
  ];
58
+ this.retainedFields = [
59
+ // Supporter Address, Phone Numbers, and Address
60
+ "supporter.emailAddress",
61
+ "supporter.phoneNumber2",
62
+ "supporter.address1",
63
+ "supporter.address2",
64
+ "supporter.address3",
65
+ ];
48
66
  if (ENGrid.getOption("RememberMe")) {
49
67
  RememberMeEvents.getInstance().onLoad.subscribe((hasData) => {
50
68
  this.logger.log("Remember me - onLoad", hasData);
@@ -102,6 +120,13 @@ export class DataLayer {
102
120
  dataLayerData[`EN_URLPARAM_${key.toUpperCase()}`] =
103
121
  this.transformJSON(value);
104
122
  });
123
+ this.retainedFields.forEach((fieldName) => {
124
+ const storedValue = localStorage.getItem(`EN_RETAINED_FIELD_${fieldName.toUpperCase()}`);
125
+ if (storedValue) {
126
+ dataLayerData[`EN_RETAINED_FIELD_${fieldName.toUpperCase()}`] =
127
+ storedValue;
128
+ }
129
+ });
105
130
  if (ENGrid.getPageType() === "DONATION") {
106
131
  const recurrFreqEls = document.querySelectorAll('[name="transaction.recurrfreq"]');
107
132
  const recurrValues = [...recurrFreqEls].map((el) => el.value);
@@ -151,45 +176,70 @@ export class DataLayer {
151
176
  }
152
177
  handleFieldValueChange(el) {
153
178
  var _a, _b, _c;
154
- if (el.value === "" || this.excludedFields.includes(el.name))
155
- return;
156
- const value = this.hashedFields.includes(el.name)
157
- ? this.hash(el.value)
158
- : el.value;
159
- if (["checkbox", "radio"].includes(el.type)) {
160
- if (el.checked) {
161
- if (el.name === "en__pg") {
162
- //Premium gift handling
163
- this.dataLayer.push({
164
- event: "EN_FORM_VALUE_UPDATED",
165
- enFieldName: el.name,
166
- enFieldLabel: "Premium Gift",
167
- enFieldValue: (_b = (_a = el
168
- .closest(".en__pg__body")) === null || _a === void 0 ? void 0 : _a.querySelector(".en__pg__name")) === null || _b === void 0 ? void 0 : _b.textContent,
169
- enProductId: (_c = document.querySelector('[name="transaction.selprodvariantid"]')) === null || _c === void 0 ? void 0 : _c.value,
170
- });
171
- }
172
- else {
173
- this.dataLayer.push({
174
- event: "EN_FORM_VALUE_UPDATED",
175
- enFieldName: el.name,
176
- enFieldLabel: this.getFieldLabel(el),
177
- enFieldValue: value,
178
- });
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ if (el.value === "" || this.excludedFields.includes(el.name))
181
+ return;
182
+ const value = this.hashedFields.includes(el.name)
183
+ ? this.hash(el.value)
184
+ : el.value;
185
+ if (["checkbox", "radio"].includes(el.type)) {
186
+ if (el.checked) {
187
+ if (el.name === "en__pg") {
188
+ //Premium gift handling
189
+ this.dataLayer.push({
190
+ event: "EN_FORM_VALUE_UPDATED",
191
+ enFieldName: el.name,
192
+ enFieldLabel: "Premium Gift",
193
+ enFieldValue: (_b = (_a = el
194
+ .closest(".en__pg__body")) === null || _a === void 0 ? void 0 : _a.querySelector(".en__pg__name")) === null || _b === void 0 ? void 0 : _b.textContent,
195
+ enProductId: (_c = document.querySelector('[name="transaction.selprodvariantid"]')) === null || _c === void 0 ? void 0 : _c.value,
196
+ });
197
+ }
198
+ else {
199
+ this.dataLayer.push({
200
+ event: "EN_FORM_VALUE_UPDATED",
201
+ enFieldName: el.name,
202
+ enFieldLabel: this.getFieldLabel(el),
203
+ enFieldValue: value,
204
+ });
205
+ }
179
206
  }
207
+ return;
180
208
  }
181
- return;
182
- }
183
- this.dataLayer.push({
184
- event: "EN_FORM_VALUE_UPDATED",
185
- enFieldName: el.name,
186
- enFieldLabel: this.getFieldLabel(el),
187
- enFieldValue: value,
209
+ if (this.retainedFields.includes(el.name)) {
210
+ const sha256value = yield this.shaHash(el.value);
211
+ localStorage.setItem(`EN_RETAINED_FIELD_${el.name.toUpperCase()}`, sha256value);
212
+ this.dataLayer.push({
213
+ event: "EN_RETAINED_VALUE_UPDATED",
214
+ enFieldName: el.name,
215
+ enFieldLabel: this.getFieldLabel(el),
216
+ enFieldValue: sha256value,
217
+ });
218
+ }
219
+ this.dataLayer.push({
220
+ event: "EN_FORM_VALUE_UPDATED",
221
+ enFieldName: el.name,
222
+ enFieldLabel: this.getFieldLabel(el),
223
+ enFieldValue: value,
224
+ });
188
225
  });
189
226
  }
190
227
  hash(value) {
191
228
  return btoa(value);
192
229
  }
230
+ // TODO: Replace the hash function with this secure SHA-256 implementation later
231
+ shaHash(value) {
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ const data = this.encoder.encode(value);
234
+ const hashBuffer = yield crypto.subtle.digest('SHA-256', data);
235
+ return Array.from(new Uint8Array(hashBuffer))
236
+ .map((byte) => {
237
+ const hex = byte.toString(16);
238
+ return hex.length === 1 ? "0" + hex : hex;
239
+ })
240
+ .join("");
241
+ });
242
+ }
193
243
  getFieldLabel(el) {
194
244
  var _a, _b;
195
245
  return ((_b = (_a = el.closest(".en__field")) === null || _a === void 0 ? void 0 : _a.querySelector("label")) === null || _b === void 0 ? void 0 : _b.textContent) || "";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.23.3";
1
+ export declare const AppVersion = "0.23.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.23.3";
1
+ export const AppVersion = "0.23.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.23.3",
3
+ "version": "0.23.5",
4
4
  "description": "Scripts for the ENGRID Project",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "strongly-typed-events": "^2.0.9"
26
26
  },
27
27
  "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
- "gitHead": "22de6d3bbd7da161d1a2b388fc2f824316cd7362",
28
+ "gitHead": "166eb2c31cb56ed112802d6bb08cd64dd415dd6a",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }