@4site/engrid-scripts 0.24.1 → 0.24.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.
@@ -210,17 +210,28 @@ export class FreshAddress {
210
210
  return true;
211
211
  }
212
212
  callProxy() {
213
- var _a;
213
+ var _a, _b;
214
214
  if (!this.options || !this.shouldRun)
215
215
  return;
216
216
  window.FreshAddressStatus = "validating";
217
217
  ENGrid.disableSubmit("Validating Email Address...");
218
+ // Before calling the API, do a basic check to see if the email is in a valid format.
219
+ // This is to prevent unnecessary API calls.
220
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
221
+ if (!emailRegex.test(this.emailField.value)) {
222
+ this.logger.log("Invalid Email Format from Basic Check");
223
+ this.writeToFields("Invalid", "Invalid Email Format");
224
+ ENGrid.setError(this.emailWrapper, "This email address is not valid.");
225
+ (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.focus();
226
+ ENGrid.enableSubmit();
227
+ return;
228
+ }
218
229
  fetch(this.options.proxyUrl, {
219
230
  method: "POST",
220
231
  headers: {
221
232
  "Content-Type": "application/json",
222
233
  },
223
- body: JSON.stringify({ email: (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.value }),
234
+ body: JSON.stringify({ email: (_b = this.emailField) === null || _b === void 0 ? void 0 : _b.value }),
224
235
  signal: AbortSignal.timeout(5000),
225
236
  })
226
237
  .then((response) => {
@@ -234,14 +245,20 @@ export class FreshAddress {
234
245
  this.validateProxyResponse(data);
235
246
  })
236
247
  .catch((error) => {
248
+ // 422 (Unprocessable Content) - This means the email is in an invalid format.
249
+ if (error.message.includes("422")) {
250
+ this.logger.log("Invalid Email Format");
251
+ this.writeToFields("Invalid", "Invalid Email Format");
252
+ ENGrid.setError(this.emailWrapper, "This email address is not valid.");
253
+ return;
254
+ }
237
255
  if (error.name === "AbortError") {
238
256
  this.logger.log("Proxy API request timed out");
239
257
  this.writeToFields("Request Timeout", "The request took too long.");
258
+ return;
240
259
  }
241
- else {
242
- this.logger.log("Proxy API Error", error);
243
- this.writeToFields("Service Error", error.toString());
244
- }
260
+ this.logger.log("Proxy API Error", error);
261
+ this.writeToFields("Service Error", error.toString());
245
262
  })
246
263
  .finally(() => {
247
264
  window.FreshAddressStatus = "idle";
@@ -270,6 +287,7 @@ export class FreshAddress {
270
287
  ENGrid.setError(this.emailWrapper, "This email address is not valid.");
271
288
  (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.focus();
272
289
  if (res.email_corrections && res.email_corrections.length > 0) {
290
+ this.emailField.value = res.email_corrections[0];
273
291
  ENGrid.setError(this.emailWrapper, `This email address is not valid. Did you mean ${res.email_corrections[0]}?`);
274
292
  }
275
293
  }
@@ -148,6 +148,7 @@ export interface Options {
148
148
  editText: string;
149
149
  anchor: string;
150
150
  placement: "beforebegin" | "afterbegin" | "beforeend" | "afterend";
151
+ showPhoneNumber?: boolean;
151
152
  };
152
153
  };
153
154
  OptInLadder?: false | {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.24.1";
1
+ export declare const AppVersion = "0.24.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.24.1";
1
+ export const AppVersion = "0.24.3";
@@ -100,7 +100,7 @@ export class WelcomeBack {
100
100
  ${this.supporterDetails["firstName"]} ${this.supporterDetails["lastName"]}
101
101
  <br>
102
102
  ${this.supporterDetails["emailAddress"]}
103
- ${this.supporterDetails["mobilePhone"]
103
+ ${this.supporterDetails["mobilePhone"] && options.showPhoneNumber
104
104
  ? `<br>${this.supporterDetails["mobilePhone"]}`
105
105
  : ""}
106
106
  </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.24.1",
3
+ "version": "0.24.3",
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": "ca933a40728608f61a724761ce9a6f7abc8db035",
28
+ "gitHead": "6f807e8e6ad0b1fcf0b6d3f72de44cc93cdd2fe1",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }