Skip to content

Commit

Permalink
chore: move partial save behind feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Dec 17, 2024
1 parent 8f8c68b commit b96ed0a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 29 deletions.
22 changes: 16 additions & 6 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/DeviceInterface/InterfacePrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,17 @@ class InterfacePrototype {
}
}

/**
* Checks if partial save can be triggered
* @param {DataStorageObject} values
* @returns {boolean}
*/
shouldTriggerPartialSave(values) {
// If credentials has only username field, and no password field, then trigger is a partialSave
const isUsernameOnly = Object.keys(values?.credentials || {}).length === 1 && Boolean(values?.credentials?.username);
return isUsernameOnly && Boolean(this.settings.featureToggles.partial_form_saves);
}

/**
* `postSubmit` gives features a one-time-only opportunity to perform an
* action directly after a form submission was observed.
Expand All @@ -799,17 +810,15 @@ class InterfacePrototype {
postSubmit(values, form) {
if (!form.form) return;
if (!form.hasValues(values)) return;

const isUsernameOnly = Object.keys(values?.credentials || {}).length === 1 && values?.credentials?.username;
const checks = [form.shouldPromptToStoreData && !form.submitHandlerExecuted, this.passwordGenerator.generated, isUsernameOnly];
const shouldPartialSave = this.shouldTriggerPartialSave(values);
const checks = [form.shouldPromptToStoreData && !form.submitHandlerExecuted, this.passwordGenerator.generated, shouldPartialSave];
if (checks.some(Boolean)) {
const formData = appendGeneratedKey(values, {
password: this.passwordGenerator.password,
username: this.emailProtection.lastGenerated,
});

// If credentials has only username field, and no password field, then trigger is a partialSave
const trigger = isUsernameOnly ? 'partialSave' : 'formSubmission';
const trigger = shouldPartialSave ? 'partialSave' : 'formSubmission';
this.storeFormData(formData, trigger);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/deviceApiCalls/__generated__/validators-ts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/deviceApiCalls/__generated__/validators.zod.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/deviceApiCalls/schemas/autofill-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"unknown_username_categorization": {
"type": "boolean",
"description": "If true, we will attempt categorizaing username, based on the rest of the input fields in the form"
},
"partial_form_saves": {
"type": "boolean",
"description": "If true, we will trigger a partial save if the form has only username field, and no password field"
}
},
"required": []
Expand All @@ -49,4 +53,4 @@
"required": [
"featureToggles"
]
}
}
22 changes: 16 additions & 6 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b96ed0a

Please sign in to comment.