@4site/engrid-scripts 0.24.1 → 0.24.2
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/freshaddress.js +24 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/freshaddress.js
CHANGED
|
@@ -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: (
|
|
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
|
-
|
|
242
|
-
|
|
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
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.24.
|
|
1
|
+
export declare const AppVersion = "0.24.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.24.
|
|
1
|
+
export const AppVersion = "0.24.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.2",
|
|
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": "
|
|
28
|
+
"gitHead": "194597168e8ecb8a919e4b838cd8aaa71952575f",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|