Skip to content

Add credit card bulk-import APIs for store migration - #7585

Merged
DimiDL merged 3 commits into
mozilla:mainfrom
DimiDL:autofill-credit-card-with-meta
Sep 7, 2026
Merged

Add credit card bulk-import APIs for store migration#7585
DimiDL merged 3 commits into
mozilla:mainfrom
DimiDL:autofill-credit-card-with-meta

Conversation

@DimiDL

@DimiDL DimiDL commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

with_savepoint, timestamp_from_millis and CounterUpdate were added to
addresses.rs for the address with-meta import. Credit cards need all three for
the same reason, and none of them is address-specific, so share them rather
than duplicating.

No behaviour change: with_savepoint goes from module-private to pub(crate) and
CounterUpdate's re-export moves from crate::db::addresses to crate::db, which is
the only caller change.
Mirrors the address with-meta API for credit cards, so an application
migrating a credit card collection into this store can keep each record's
guid, timestamps and change counter:

  add_credit_card_with_meta
  add_many_credit_cards_with_meta
  update_credit_card_with_meta
  add_many_credit_card_tombstones
  delete_all_credit_cards

Mostly wrappers over add_internal_credit_card, which already took the
metadata. The exception is update_internal_credit_card, which took
`flag_as_changed: bool` and could only increment the change counter. It now
takes CounterUpdate, as the address side does, because an imported record's
counter is owned by the caller and has to be set rather than bumped. The sync
caller is unchanged in behaviour.

cc_number_enc is stored exactly as supplied and is not checked against the
store's key, matching add_credit_card: Desktop's interim migration carries
ciphertext produced by the OS key store, which this component cannot decrypt
by design. Note the cost of that. An imported record is absent from the
mirror, so it is always selected for upload, and one undecryptable row fails
the whole outgoing batch - so credit card sync stops until
scrub_undecryptable_credit_card_data_for_remote_replacement blanks it.

@jo jo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's slick!

At this point let's introduce timestamp validation, similar to

entry_with_meta.meta = entry_with_meta.meta.sanitize_timestamps();

@DimiDL
DimiDL force-pushed the autofill-credit-card-with-meta branch from 1dce8cd to 8cb95d1 Compare September 7, 2026 11:00
Logins got this in bug 2066257: a timestamp outside the range a JS Date can
represent is reported as 0, "we don't know when". Autofill now does the same, at
all three places a timestamp enters:

  - metadata an application supplies to the bulk-import APIs
  - every read out of the local database (addresses, credit cards, passports)
  - incoming sync payloads (addresses, credit cards)

timestamp_from_millis only clamped negatives, which missed the values actually
seen in telemetry: the negative-to-u64 reinterpretation happens in JS before the
value reaches us, so they arrive already huge and .max(0) passed them through.

MAX_DATE_MS and sanitize_timestamp move to the types crate, next to Timestamp,
so logins and autofill cannot drift on what a representable date is. Logins
reaches them via a re-export and is unchanged in behaviour.
@DimiDL
DimiDL force-pushed the autofill-credit-card-with-meta branch from 8cb95d1 to e2abbe8 Compare September 7, 2026 11:15

@jo jo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@DimiDL
DimiDL added this pull request to the merge queue Sep 7, 2026
Merged via the queue into mozilla:main with commit e1f6fe8 Sep 7, 2026
15 checks passed
@DimiDL
DimiDL deleted the autofill-credit-card-with-meta branch September 7, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants