@4site/engrid-scripts 0.24.5 → 0.25.0
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.d.ts +1 -0
- package/dist/app.js +8 -0
- package/dist/digital-wallets.d.ts +5 -0
- package/dist/digital-wallets.js +42 -1
- package/dist/events/en-form.d.ts +28 -1
- package/dist/events/en-form.js +35 -3
- package/dist/interfaces/options.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/app.d.ts
CHANGED
package/dist/app.js
CHANGED
|
@@ -94,6 +94,7 @@ export class App extends ENGrid {
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
// Client onSubmit and onError functions
|
|
97
|
+
this._form.onIntentSubmit.subscribe(() => this.onIntentSubmit());
|
|
97
98
|
this._form.onSubmit.subscribe(() => this.onSubmit());
|
|
98
99
|
this._form.onError.subscribe(() => this.onError());
|
|
99
100
|
this._form.onValidate.subscribe(() => this.onValidate());
|
|
@@ -111,6 +112,7 @@ export class App extends ENGrid {
|
|
|
111
112
|
window.enOnSubmit = () => {
|
|
112
113
|
this._form.submit = true;
|
|
113
114
|
this._form.submitPromise = false;
|
|
115
|
+
this._form.dispatchIntentSubmit();
|
|
114
116
|
this._form.dispatchSubmit();
|
|
115
117
|
ENGrid.watchForError(ENGrid.enableSubmit);
|
|
116
118
|
if (!this._form.submit)
|
|
@@ -331,6 +333,12 @@ export class App extends ENGrid {
|
|
|
331
333
|
this.options.onValidate();
|
|
332
334
|
}
|
|
333
335
|
}
|
|
336
|
+
onIntentSubmit() {
|
|
337
|
+
if (this.options.onIntentSubmit) {
|
|
338
|
+
this.logger.log("Client onIntentSubmit Triggered");
|
|
339
|
+
this.options.onIntentSubmit();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
334
342
|
onSubmit() {
|
|
335
343
|
if (this.options.onSubmit) {
|
|
336
344
|
this.logger.log("Client onSubmit Triggered");
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export declare class DigitalWallets {
|
|
2
|
+
private logger;
|
|
3
|
+
private _form;
|
|
2
4
|
constructor();
|
|
3
5
|
private addStripeDigitalWallets;
|
|
4
6
|
private addPaypalTouchDigitalWallets;
|
|
5
7
|
private addDAF;
|
|
6
8
|
private addOptionToPaymentTypeField;
|
|
7
9
|
private checkForWalletsBeingAdded;
|
|
10
|
+
private addPaypalOneTouchListener;
|
|
11
|
+
private addStripeDigitalWalletListener;
|
|
12
|
+
private addDAFListener;
|
|
8
13
|
}
|
package/dist/digital-wallets.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ENGrid } from "./engrid";
|
|
2
|
+
import { EnForm } from "./events";
|
|
3
|
+
import { EngridLogger } from "./logger";
|
|
2
4
|
export class DigitalWallets {
|
|
3
5
|
constructor() {
|
|
6
|
+
this.logger = new EngridLogger("DigitalWallets", "#fff", "#333", "👛");
|
|
7
|
+
this._form = EnForm.getInstance();
|
|
4
8
|
//digital wallets not enabled.
|
|
5
9
|
if (!document.getElementById("en__digitalWallet")) {
|
|
6
10
|
ENGrid.setBodyData("payment-type-option-stripedigitalwallet", "false");
|
|
@@ -9,6 +13,7 @@ export class DigitalWallets {
|
|
|
9
13
|
ENGrid.setBodyData("payment-type-option-paypal-one-touch", "false");
|
|
10
14
|
ENGrid.setBodyData("payment-type-option-venmo", "false");
|
|
11
15
|
ENGrid.setBodyData("payment-type-option-daf", "false");
|
|
16
|
+
this.logger.log("No digital wallet container found, skipping digital wallet setup.");
|
|
12
17
|
return;
|
|
13
18
|
}
|
|
14
19
|
// Add giveBySelect classes to the separate wallet containers
|
|
@@ -86,6 +91,7 @@ export class DigitalWallets {
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
addStripeDigitalWallets() {
|
|
94
|
+
this.logger.log("Stripe Digital Wallets detected");
|
|
89
95
|
this.addOptionToPaymentTypeField("stripedigitalwallet", "GooglePay / ApplePay");
|
|
90
96
|
// ENGrid.setBodyData(
|
|
91
97
|
// "payment-type-option-apple-pay",
|
|
@@ -99,15 +105,26 @@ export class DigitalWallets {
|
|
|
99
105
|
ENGrid.setBodyData("payment-type-option-apple-pay", "true");
|
|
100
106
|
ENGrid.setBodyData("payment-type-option-google-pay", "true");
|
|
101
107
|
ENGrid.setBodyData("payment-type-option-stripedigitalwallet", "true");
|
|
108
|
+
this.addStripeDigitalWalletListener()
|
|
109
|
+
? this.logger.log("Stripe Digital Wallet listener added successfully")
|
|
110
|
+
: this.logger.log("Failed to add Stripe Digital Wallet listener");
|
|
102
111
|
}
|
|
103
112
|
addPaypalTouchDigitalWallets() {
|
|
113
|
+
this.logger.log("Paypal Touch Digital Wallets detected");
|
|
104
114
|
this.addOptionToPaymentTypeField("paypaltouch", "Paypal / Venmo");
|
|
105
115
|
ENGrid.setBodyData("payment-type-option-paypal-one-touch", "true");
|
|
106
116
|
ENGrid.setBodyData("payment-type-option-venmo", "true");
|
|
117
|
+
this.addPaypalOneTouchListener()
|
|
118
|
+
? this.logger.log("Paypal Touch listener added successfully")
|
|
119
|
+
: this.logger.log("Failed to add Paypal Touch listener");
|
|
107
120
|
}
|
|
108
121
|
addDAF() {
|
|
122
|
+
this.logger.log("DAF Digital Wallet detected");
|
|
109
123
|
this.addOptionToPaymentTypeField("daf", "Donor Advised Fund");
|
|
110
124
|
ENGrid.setBodyData("payment-type-option-daf", "true");
|
|
125
|
+
this.addDAFListener()
|
|
126
|
+
? this.logger.log("DAF listener added successfully")
|
|
127
|
+
: this.logger.log("Failed to add DAF listener");
|
|
111
128
|
}
|
|
112
129
|
addOptionToPaymentTypeField(value, label) {
|
|
113
130
|
const paymentTypeField = document.querySelector('[name="transaction.paymenttype"]');
|
|
@@ -144,12 +161,36 @@ export class DigitalWallets {
|
|
|
144
161
|
else if (walletType === "daf") {
|
|
145
162
|
this.addDAF();
|
|
146
163
|
}
|
|
147
|
-
//Disconnect observer to prevent multiple additions
|
|
164
|
+
//Disconnect observer and break loop to prevent multiple additions
|
|
148
165
|
observer.disconnect();
|
|
166
|
+
break;
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
};
|
|
152
170
|
const observer = new MutationObserver(callback);
|
|
153
171
|
observer.observe(node, { childList: true, subtree: true });
|
|
154
172
|
}
|
|
173
|
+
addPaypalOneTouchListener() {
|
|
174
|
+
var _a, _b, _c, _d, _e;
|
|
175
|
+
const paypalTouch = (_d = (_c = (_b = (_a = window.EngagingNetworks) === null || _a === void 0 ? void 0 : _a.require) === null || _b === void 0 ? void 0 : _b._defined) === null || _c === void 0 ? void 0 : _c.enPaypalTouch) === null || _d === void 0 ? void 0 : _d.paypalTouch;
|
|
176
|
+
if (!((_e = paypalTouch === null || paypalTouch === void 0 ? void 0 : paypalTouch.library) === null || _e === void 0 ? void 0 : _e.Buttons)) {
|
|
177
|
+
this.logger.log("Paypal Touch library not found, cannot add listener");
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
const buttons = paypalTouch.library.Buttons.bind(paypalTouch.library);
|
|
181
|
+
paypalTouch.library.Buttons = (o) => buttons(Object.assign(Object.assign({}, o), { onClick: (d, a) => (this._form.dispatchIntentSubmit(),
|
|
182
|
+
o.onClick && o.onClick(d, a)) }));
|
|
183
|
+
paypalTouch.unloadButton && paypalTouch.unloadButton();
|
|
184
|
+
paypalTouch.loadButton && paypalTouch.loadButton();
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
addStripeDigitalWalletListener() {
|
|
188
|
+
var _a, _b, _c, _d, _e, _f;
|
|
189
|
+
return !!((_f = (_e = (_d = (_c = (_b = (_a = window.EngagingNetworks) === null || _a === void 0 ? void 0 : _a.require) === null || _b === void 0 ? void 0 : _b._defined) === null || _c === void 0 ? void 0 : _c.enStripeButtons) === null || _d === void 0 ? void 0 : _d.stripeButtons) === null || _e === void 0 ? void 0 : _e.paymentRequest) === null || _f === void 0 ? void 0 : _f.on("paymentmethod", this._form.dispatchIntentSubmit.bind(this._form)));
|
|
190
|
+
}
|
|
191
|
+
addDAFListener() {
|
|
192
|
+
const chariotButton = document.getElementById("chariot-button");
|
|
193
|
+
chariotButton === null || chariotButton === void 0 ? void 0 : chariotButton.addEventListener("click", this._form.dispatchIntentSubmit.bind(this._form));
|
|
194
|
+
return !!chariotButton;
|
|
195
|
+
}
|
|
155
196
|
}
|
package/dist/events/en-form.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare class EnForm {
|
|
2
2
|
private logger;
|
|
3
|
+
private _onIntentSubmit;
|
|
3
4
|
private _onSubmit;
|
|
4
5
|
private _onValidate;
|
|
5
6
|
private _onError;
|
|
@@ -10,11 +11,37 @@ export declare class EnForm {
|
|
|
10
11
|
private static instance;
|
|
11
12
|
private constructor();
|
|
12
13
|
static getInstance(): EnForm;
|
|
14
|
+
dispatchIntentSubmit(): void;
|
|
13
15
|
dispatchSubmit(): void;
|
|
14
16
|
dispatchValidate(): void;
|
|
15
17
|
dispatchError(): void;
|
|
16
18
|
submitForm(): void;
|
|
19
|
+
/**
|
|
20
|
+
* onIntentSubmit is dispatched when a submit button is clicked,
|
|
21
|
+
* or a digital wallet submission is initiated,
|
|
22
|
+
* but before server-side validation or the actual submit event.
|
|
23
|
+
* This allows you to run code at the moment the user intends to submit,
|
|
24
|
+
* such as triggering data formatting, analytics events, or other pre-submit actions.
|
|
25
|
+
* Actions that rely on fully processed form data or validation results should use the onSubmit event instead.
|
|
26
|
+
* Note: onSubmit will also dispatch onIntentSubmit, so do not repeat actions in both events.
|
|
27
|
+
*/
|
|
28
|
+
get onIntentSubmit(): import("strongly-typed-events").ISignal;
|
|
29
|
+
/**
|
|
30
|
+
* onSubmit is dispatched when the form is submitted, after validation has passed.
|
|
31
|
+
* This is the main event to listen to for form submissions, as it indicates that the user has successfully submitted the form and all validation checks have been passed.
|
|
32
|
+
* This event uses window.enOnSubmit, which is called by Engaging Networks' JavaScript when the form is submitted.
|
|
33
|
+
* At the time of writing, enOnSubmit does not trigger when a user submits via a digital wallet, use onIntentSubmit to listen for those submission attempts.
|
|
34
|
+
* Note: onSubmit will also dispatch onIntentSubmit, so do not repeat actions in both events.
|
|
35
|
+
*/
|
|
17
36
|
get onSubmit(): import("strongly-typed-events").ISignal;
|
|
18
|
-
|
|
37
|
+
/**
|
|
38
|
+
* onValidate is dispatched using window.enOnValidate, which is called by Engaging Networks' JavaScript
|
|
39
|
+
* when the form is being validated, before submission. This only occurs after ENgrid's client-side validation has passed, but before server-side validation.
|
|
40
|
+
*/
|
|
19
41
|
get onValidate(): import("strongly-typed-events").ISignal;
|
|
42
|
+
/**
|
|
43
|
+
* onError is dispatched using window.enOnError, which is called by Engaging Networks' JavaScript when a server-side validation error occurs on form submission.
|
|
44
|
+
* This allows you to listen for validation errors and respond accordingly, such as displaying custom error messages or triggering analytics events.
|
|
45
|
+
*/
|
|
46
|
+
get onError(): import("strongly-typed-events").ISignal;
|
|
20
47
|
}
|
package/dist/events/en-form.js
CHANGED
|
@@ -3,6 +3,7 @@ import { EngridLogger } from "..";
|
|
|
3
3
|
export class EnForm {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.logger = new EngridLogger("EnForm");
|
|
6
|
+
this._onIntentSubmit = new SignalDispatcher();
|
|
6
7
|
this._onSubmit = new SignalDispatcher();
|
|
7
8
|
this._onValidate = new SignalDispatcher();
|
|
8
9
|
this._onError = new SignalDispatcher();
|
|
@@ -17,6 +18,10 @@ export class EnForm {
|
|
|
17
18
|
}
|
|
18
19
|
return EnForm.instance;
|
|
19
20
|
}
|
|
21
|
+
dispatchIntentSubmit() {
|
|
22
|
+
this._onIntentSubmit.dispatch();
|
|
23
|
+
this.logger.log("dispatchIntentSubmit");
|
|
24
|
+
}
|
|
20
25
|
dispatchSubmit() {
|
|
21
26
|
this._onSubmit.dispatch();
|
|
22
27
|
this.logger.log("dispatchSubmit");
|
|
@@ -40,13 +45,40 @@ export class EnForm {
|
|
|
40
45
|
this.logger.log("submitForm");
|
|
41
46
|
}
|
|
42
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* onIntentSubmit is dispatched when a submit button is clicked,
|
|
50
|
+
* or a digital wallet submission is initiated,
|
|
51
|
+
* but before server-side validation or the actual submit event.
|
|
52
|
+
* This allows you to run code at the moment the user intends to submit,
|
|
53
|
+
* such as triggering data formatting, analytics events, or other pre-submit actions.
|
|
54
|
+
* Actions that rely on fully processed form data or validation results should use the onSubmit event instead.
|
|
55
|
+
* Note: onSubmit will also dispatch onIntentSubmit, so do not repeat actions in both events.
|
|
56
|
+
*/
|
|
57
|
+
get onIntentSubmit() {
|
|
58
|
+
return this._onIntentSubmit.asEvent();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* onSubmit is dispatched when the form is submitted, after validation has passed.
|
|
62
|
+
* This is the main event to listen to for form submissions, as it indicates that the user has successfully submitted the form and all validation checks have been passed.
|
|
63
|
+
* This event uses window.enOnSubmit, which is called by Engaging Networks' JavaScript when the form is submitted.
|
|
64
|
+
* At the time of writing, enOnSubmit does not trigger when a user submits via a digital wallet, use onIntentSubmit to listen for those submission attempts.
|
|
65
|
+
* Note: onSubmit will also dispatch onIntentSubmit, so do not repeat actions in both events.
|
|
66
|
+
*/
|
|
43
67
|
get onSubmit() {
|
|
44
68
|
return this._onSubmit.asEvent();
|
|
45
69
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
/**
|
|
71
|
+
* onValidate is dispatched using window.enOnValidate, which is called by Engaging Networks' JavaScript
|
|
72
|
+
* when the form is being validated, before submission. This only occurs after ENgrid's client-side validation has passed, but before server-side validation.
|
|
73
|
+
*/
|
|
49
74
|
get onValidate() {
|
|
50
75
|
return this._onValidate.asEvent();
|
|
51
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* onError is dispatched using window.enOnError, which is called by Engaging Networks' JavaScript when a server-side validation error occurs on form submission.
|
|
79
|
+
* This allows you to listen for validation errors and respond accordingly, such as displaying custom error messages or triggering analytics events.
|
|
80
|
+
*/
|
|
81
|
+
get onError() {
|
|
82
|
+
return this._onError.asEvent();
|
|
83
|
+
}
|
|
52
84
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.
|
|
1
|
+
export declare const AppVersion = "0.25.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.
|
|
1
|
+
export const AppVersion = "0.25.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
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": "6f0962a8be8ef7211c383a7d8d7b2c188091408d",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|