@4site/engrid-scripts 0.23.12 → 0.24.1

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
@@ -1,5 +1,5 @@
1
1
  import { DonationAmount, DonationFrequency, EnForm, ProcessingFees, Country, } from "./events";
2
- import { AmountLabel, Loader, ProgressBar, UpsellLightbox, ENGrid, OptionsDefaults, setRecurrFreq, PageBackground, MediaAttribution, ApplePay, A11y, CapitalizeFields, Ecard, ClickToExpand, Advocacy, DataAttributes, LiveVariables, iFrame, InputPlaceholders, InputHasValueAndFocus, ShowHideRadioCheckboxes, AutoCountrySelect, SkipToMainContentLink, SrcDefer, NeverBounce, AutoYear, Autocomplete, RememberMe, TranslateFields, ShowIfAmount, EngridLogger, OtherAmount, MinMaxAmount, Ticker, DataReplace, DataHide, AddNameToMessage, ExpandRegionName, AppVersion, UrlToForm, RequiredIfVisible, TidyContact, DataLayer, LiveCurrency, Autosubmit, EventTickets, SwapAmounts, DebugPanel, DebugHiddenFields, FreshAddress, BrandingHtml, CountryDisable, PremiumGift, DigitalWallets, MobileCTA, LiveFrequency, UniversalOptIn, Plaid, GiveBySelect, UrlParamsToBodyAttrs, ExitIntentLightbox, SupporterHub, FastFormFill, SetAttr, ShowIfPresent, ENValidators, CustomCurrency, VGS, PostalCodeValidator, CountryRedirect, WelcomeBack, EcardToTarget, UsOnlyForm, ThankYouPageConditionalContent, EmbeddedEcard, CheckboxLabel, UpsellCheckbox, PostDonationEmbed, FrequencyUpsell, CustomPremium, PreferredPaymentMethod, } from ".";
2
+ import { AmountLabel, Loader, ProgressBar, UpsellLightbox, ENGrid, OptionsDefaults, setRecurrFreq, PageBackground, MediaAttribution, ApplePay, A11y, CapitalizeFields, Ecard, ClickToExpand, Advocacy, DataAttributes, LiveVariables, iFrame, InputPlaceholders, InputHasValueAndFocus, ShowHideRadioCheckboxes, AutoCountrySelect, SkipToMainContentLink, SrcDefer, NeverBounce, AutoYear, Autocomplete, RememberMe, TranslateFields, ShowIfAmount, EngridLogger, OtherAmount, MinMaxAmount, Ticker, DataReplace, DataHide, AddNameToMessage, ExpandRegionName, AppVersion, UrlToForm, RequiredIfVisible, TidyContact, DataLayer, LiveCurrency, Autosubmit, EventTickets, SwapAmounts, DebugPanel, DebugHiddenFields, FreshAddress, BrandingHtml, CountryDisable, PremiumGift, DigitalWallets, MobileCTA, LiveFrequency, UniversalOptIn, StripeFinancialConnections, GiveBySelect, UrlParamsToBodyAttrs, ExitIntentLightbox, SupporterHub, FastFormFill, SetAttr, ShowIfPresent, ENValidators, CustomCurrency, VGS, PostalCodeValidator, CountryRedirect, WelcomeBack, EcardToTarget, UsOnlyForm, ThankYouPageConditionalContent, EmbeddedEcard, CheckboxLabel, UpsellCheckbox, PostDonationEmbed, FrequencyUpsell, CustomPremium, PreferredPaymentMethod, } from ".";
3
3
  export class App extends ENGrid {
4
4
  constructor(options) {
5
5
  super();
@@ -262,9 +262,7 @@ export class App extends ENGrid {
262
262
  new LiveFrequency();
263
263
  // Universal Opt In
264
264
  new UniversalOptIn();
265
- // Plaid
266
- if (this.options.Plaid)
267
- new Plaid();
265
+ new StripeFinancialConnections();
268
266
  //Exit Intent Lightbox
269
267
  new ExitIntentLightbox();
270
268
  new UrlParamsToBodyAttrs();
@@ -15,4 +15,6 @@ export declare class FreshAddress {
15
15
  private callAPI;
16
16
  private validateResponse;
17
17
  private validate;
18
+ private callProxy;
19
+ private validateProxyResponse;
18
20
  }
@@ -9,6 +9,7 @@ import { ENGrid, EngridLogger } from ".";
9
9
  import { EnForm } from "./events";
10
10
  export class FreshAddress {
11
11
  constructor() {
12
+ var _a;
12
13
  this.form = EnForm.getInstance();
13
14
  this.emailField = null;
14
15
  this.emailWrapper = document.querySelector(".en__field--emailAddress");
@@ -18,8 +19,10 @@ export class FreshAddress {
18
19
  this.logger = new EngridLogger("FreshAddress", "#039bc4", "#dfdfdf", "📧");
19
20
  this.shouldRun = true;
20
21
  this.options = ENGrid.getOption("FreshAddress");
21
- if (this.options === false || !window.FreshAddress)
22
+ if (this.options === false ||
23
+ (!window.FreshAddress && !((_a = this.options) === null || _a === void 0 ? void 0 : _a.proxyUrl))) {
22
24
  return;
25
+ }
23
26
  this.emailField = document.getElementById("en__field_supporter_emailAddress");
24
27
  if (this.emailField) {
25
28
  this.createFields();
@@ -89,7 +92,12 @@ export class FreshAddress {
89
92
  return;
90
93
  }
91
94
  this.logger.log("Validating " + ((_b = this.emailField) === null || _b === void 0 ? void 0 : _b.value));
92
- this.callAPI();
95
+ if (this.options && this.options.proxyUrl) {
96
+ this.callProxy();
97
+ }
98
+ else {
99
+ this.callAPI();
100
+ }
93
101
  });
94
102
  // Add event listener to submit
95
103
  this.form.onValidate.subscribe(this.validate.bind(this));
@@ -192,7 +200,7 @@ export class FreshAddress {
192
200
  else if (this.faStatus.value === "Invalid") {
193
201
  this.form.validate = false;
194
202
  window.setTimeout(() => {
195
- ENGrid.setError(this.emailWrapper, this.faMessage.value);
203
+ ENGrid.setError(this.emailWrapper, "This email address is not valid.");
196
204
  }, 100);
197
205
  (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.focus();
198
206
  ENGrid.enableSubmit();
@@ -201,4 +209,69 @@ export class FreshAddress {
201
209
  this.form.validate = true;
202
210
  return true;
203
211
  }
212
+ callProxy() {
213
+ var _a;
214
+ if (!this.options || !this.shouldRun)
215
+ return;
216
+ window.FreshAddressStatus = "validating";
217
+ ENGrid.disableSubmit("Validating Email Address...");
218
+ fetch(this.options.proxyUrl, {
219
+ method: "POST",
220
+ headers: {
221
+ "Content-Type": "application/json",
222
+ },
223
+ body: JSON.stringify({ email: (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.value }),
224
+ signal: AbortSignal.timeout(5000),
225
+ })
226
+ .then((response) => {
227
+ if (!response.ok) {
228
+ throw new Error(`HTTP error ${response.status}`);
229
+ }
230
+ return response.json();
231
+ })
232
+ .then((data) => {
233
+ this.logger.log("Proxy API Response", data);
234
+ this.validateProxyResponse(data);
235
+ })
236
+ .catch((error) => {
237
+ if (error.name === "AbortError") {
238
+ this.logger.log("Proxy API request timed out");
239
+ this.writeToFields("Request Timeout", "The request took too long.");
240
+ }
241
+ else {
242
+ this.logger.log("Proxy API Error", error);
243
+ this.writeToFields("Service Error", error.toString());
244
+ }
245
+ })
246
+ .finally(() => {
247
+ window.FreshAddressStatus = "idle";
248
+ ENGrid.enableSubmit();
249
+ });
250
+ }
251
+ /*
252
+ * Validate a request proxied to AtData's Safe To Send API.
253
+ * https://docs.atdata.com/reference/safe-to-send
254
+ * https://docs.atdata.com/reference/email-status
255
+ * https://docs.atdata.com/reference/status-codes-safe-to-send
256
+ */
257
+ validateProxyResponse(data) {
258
+ var _a;
259
+ // If response is not in expected format, log error and let through.
260
+ if (!data.safe_to_send) {
261
+ this.logger.log("Invalid Proxy Response");
262
+ this.writeToFields("Service Error", "Invalid Proxy Response");
263
+ return true;
264
+ }
265
+ const res = data.safe_to_send;
266
+ ENGrid.removeError(this.emailWrapper);
267
+ this.writeToFields(res.status, res.status_code);
268
+ if (["invalid", "trap"].includes(res.status)) {
269
+ this.writeToFields("Invalid", res.status_code); // Must be "Invalid" to trigger validation error on submit
270
+ ENGrid.setError(this.emailWrapper, "This email address is not valid.");
271
+ (_a = this.emailField) === null || _a === void 0 ? void 0 : _a.focus();
272
+ if (res.email_corrections && res.email_corrections.length > 0) {
273
+ ENGrid.setError(this.emailWrapper, `This email address is not valid. Did you mean ${res.email_corrections[0]}?`);
274
+ }
275
+ }
276
+ }
204
277
  }
package/dist/index.d.ts CHANGED
@@ -63,7 +63,7 @@ export * from "./digital-wallets";
63
63
  export * from "./mobile-cta";
64
64
  export * from "./live-frequency";
65
65
  export * from "./universal-opt-in";
66
- export * from "./plaid";
66
+ export * from "./stripe-financial-connections";
67
67
  export * from "./give-by-select";
68
68
  export * from "./url-params-to-body-attrs";
69
69
  export * from "./exit-intent-lightbox";
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ export * from "./digital-wallets";
63
63
  export * from "./mobile-cta";
64
64
  export * from "./live-frequency";
65
65
  export * from "./universal-opt-in";
66
- export * from "./plaid";
66
+ export * from "./stripe-financial-connections";
67
67
  export * from "./give-by-select";
68
68
  export * from "./url-params-to-body-attrs";
69
69
  export * from "./exit-intent-lightbox";
@@ -28,6 +28,7 @@ export interface Options {
28
28
  dateFieldFormat?: string;
29
29
  statusField?: string;
30
30
  messageField?: string;
31
+ proxyUrl?: string;
31
32
  };
32
33
  ProgressBar?: boolean | null;
33
34
  AutoYear?: boolean;
@@ -82,7 +83,6 @@ export interface Options {
82
83
  }[];
83
84
  PageLayouts?: string[];
84
85
  CountryDisable?: string[];
85
- Plaid?: boolean;
86
86
  Placeholders?: false | {
87
87
  [key: string]: string;
88
88
  };
@@ -31,7 +31,6 @@ export const OptionsDefaults = {
31
31
  TidyContact: false,
32
32
  RegionLongFormat: "",
33
33
  CountryDisable: [],
34
- Plaid: false,
35
34
  Placeholders: false,
36
35
  ENValidators: false,
37
36
  MobileCTA: false,
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This component improves EN's implementation of Stripe Financial Connections.
3
+ * Enhancements:
4
+ * - When the modal is closed, it re-enables the submit button.
5
+ */
6
+ export declare class StripeFinancialConnections {
7
+ private stripeModalOpen;
8
+ private logger;
9
+ constructor();
10
+ isStripeModalNode(node: Node): boolean;
11
+ isStripeModalNodeWIthIframe(node: Node): boolean;
12
+ onStripeModalOpen(): void;
13
+ onStripeModalClose(): void;
14
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * This component improves EN's implementation of Stripe Financial Connections.
3
+ * Enhancements:
4
+ * - When the modal is closed, it re-enables the submit button.
5
+ */
6
+ import { ENGrid, EngridLogger } from ".";
7
+ export class StripeFinancialConnections {
8
+ constructor() {
9
+ this.stripeModalOpen = false;
10
+ this.logger = new EngridLogger("Stripe Financial Connections", "black", "pink", "🏛️");
11
+ const observer = new MutationObserver((mutations) => {
12
+ mutations.forEach((mutation) => {
13
+ mutation.addedNodes.forEach((node) => {
14
+ if (!this.stripeModalOpen && this.isStripeModalNodeWIthIframe(node)) {
15
+ this.logger.log("Stripe Financial Connections modal opened.");
16
+ this.onStripeModalOpen();
17
+ }
18
+ });
19
+ mutation.removedNodes.forEach((node) => {
20
+ if (this.stripeModalOpen && this.isStripeModalNode(node)) {
21
+ this.logger.log("Stripe Financial Connections modal closed.");
22
+ this.onStripeModalClose();
23
+ }
24
+ });
25
+ });
26
+ });
27
+ observer.observe(document.body, {
28
+ childList: true,
29
+ subtree: true,
30
+ });
31
+ }
32
+ isStripeModalNode(node) {
33
+ return (node instanceof HTMLElement &&
34
+ node.hasAttribute("data-react-aria-top-layer"));
35
+ }
36
+ isStripeModalNodeWIthIframe(node) {
37
+ return !!(this.isStripeModalNode(node) &&
38
+ node instanceof HTMLElement &&
39
+ node.querySelector('iframe[src*="js.stripe.com"]'));
40
+ }
41
+ onStripeModalOpen() {
42
+ this.stripeModalOpen = true;
43
+ }
44
+ onStripeModalClose() {
45
+ this.stripeModalOpen = false;
46
+ ENGrid.enableSubmit();
47
+ }
48
+ }
@@ -34,7 +34,7 @@ export class SupporterHub {
34
34
  }
35
35
  });
36
36
  });
37
- // Start observing the Link ID #plaid-link-button
37
+ // Start observing the Link ID
38
38
  observer.observe(form, {
39
39
  childList: true,
40
40
  subtree: true,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.23.12";
1
+ export declare const AppVersion = "0.24.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.23.12";
1
+ export const AppVersion = "0.24.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.23.12",
3
+ "version": "0.24.1",
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": "56771f22187848dc03f76e0440d369f48ea68b9a",
28
+ "gitHead": "ca933a40728608f61a724761ce9a6f7abc8db035",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }