@blotoutio/providers-auto-form-fill-sdk 0.8.1 → 0.8.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.
- package/index.js +39 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -125,6 +125,16 @@ var ProvidersAutoFormFillSdk = (function () {
|
|
|
125
125
|
return `AUTO_FILL_${selector}`;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
+
const sendAutoFillCountToWorker = (successCount, getEdgeData, sendEdgeData) => {
|
|
129
|
+
if (successCount) {
|
|
130
|
+
getEdgeData([formFillCountKey], (keys) => {
|
|
131
|
+
if (!isNaN(parseInt(keys[formFillCountKey]))) {
|
|
132
|
+
successCount = successCount + parseInt(keys[formFillCountKey]);
|
|
133
|
+
}
|
|
134
|
+
sendEdgeData({ [formFillCountKey]: successCount.toString() }, {}, { method: 'beacon' });
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
128
138
|
const init = (params) => {
|
|
129
139
|
const { manifest, getEdgeData, sendEdgeData, keyName } = params;
|
|
130
140
|
try {
|
|
@@ -138,24 +148,41 @@ var ProvidersAutoFormFillSdk = (function () {
|
|
|
138
148
|
console.error('Enter a valid form selectors to auto-fill');
|
|
139
149
|
return;
|
|
140
150
|
}
|
|
141
|
-
|
|
151
|
+
// forms which are present in curr page
|
|
152
|
+
const curFormSelectors = formSelectors.filter((item) => item && document.querySelector(item) != null);
|
|
153
|
+
if (!curFormSelectors || !curFormSelectors.length) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const formattedSelectors = curFormSelectors.map((item) => getFormattedSelectorName(item));
|
|
142
157
|
const sessionData = JSON.parse(sessionStorage.getItem(keyName) || '{}');
|
|
143
158
|
const kvData = sessionData && 'kv' in sessionData ? sessionData['kv'] : {};
|
|
144
159
|
const formSelectorsWOCache = formattedSelectors.filter((formSelector) => !Object.keys(kvData).includes(formSelector));
|
|
145
160
|
let successCount = 0;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
161
|
+
if (formSelectorsWOCache.length) {
|
|
162
|
+
getEdgeData(formSelectorsWOCache, (keys) => {
|
|
163
|
+
curFormSelectors.forEach((formSelector) => {
|
|
164
|
+
var _a;
|
|
165
|
+
const result = updateFormFields(formSelector, keys, kvData);
|
|
166
|
+
successCount = successCount + (result === true ? 1 : 0);
|
|
167
|
+
const formattedSelector = `AUTO_FILL_${formSelector}`;
|
|
168
|
+
// storing the form data in session if the form gets successfully auto-filled
|
|
169
|
+
if (formattedSelector in keys && result === true) {
|
|
170
|
+
const curSessionData = JSON.parse(sessionStorage.getItem(keyName) || '{}');
|
|
171
|
+
const curKvData = (_a = curSessionData['kv']) !== null && _a !== void 0 ? _a : {};
|
|
172
|
+
sessionStorage.setItem(keyName, JSON.stringify(Object.assign(Object.assign({}, curSessionData), { kv: Object.assign(Object.assign({}, curKvData), { [formattedSelector]: keys[formattedSelector].toString() }) })));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
sendAutoFillCountToWorker(successCount, getEdgeData, sendEdgeData);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
curFormSelectors.forEach((formSelector) => {
|
|
180
|
+
const result = updateFormFields(formSelector, {}, kvData);
|
|
149
181
|
successCount = successCount + (result === true ? 1 : 0);
|
|
150
182
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
sendEdgeData({ [formFillCountKey]: successCount.toString() }, {}, { method: 'beacon' });
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
formSelectors.forEach((formSelector) => {
|
|
183
|
+
sendAutoFillCountToWorker(successCount, getEdgeData, sendEdgeData);
|
|
184
|
+
}
|
|
185
|
+
curFormSelectors.forEach((formSelector) => {
|
|
159
186
|
const element = document.querySelector(formSelector);
|
|
160
187
|
if (element) {
|
|
161
188
|
element.addEventListener('submit', () => {
|