Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Stop FinanceKit data disagreements from ending ingestion (#3678)

Juan José Mata65ddc81d1037
diff --git a/app/controllers/api/v1/financekit/base_controller.rb b/app/controllers/api/v1/financekit/base_controller.rb
index 5e68e54cee..473a0d3d3f 100644
--- a/app/controllers/api/v1/financekit/base_controller.rb
+++ b/app/controllers/api/v1/financekit/base_controller.rb
@@ -9,14 +9,14 @@ class Api::V1::Financekit::BaseController < Api::V1::BaseController
private
+ # Publishing is admin-only, as connecting any provider is: it writes into
+ # accounts the whole family reads. Nothing else gates it -- there is no
+ # server-side feature flag, and no per-user preview opt-in. Whether a build
+ # offers Wallet sync at all is the iOS client's decision, made through
+ # StoreKit, which the server has no way to check and does not try to.
def require_financekit_access
return unless authorize_scope!(request.get? || request.head? ? :read : :write)
- unless current_resource_owner.admin? && current_resource_owner.preview_features_enabled?
- raise Financekit::Error.new("publisher_forbidden", 403)
- end
- unless action_name == "capabilities" || Financekit.enabled?(current_resource_owner.family) || action_name == "destroy"
- raise Financekit::Error.new("unavailable", 503)
- end
+ raise Financekit::Error.new("publisher_forbidden", 403) unless current_resource_owner.admin?
end
def connection
diff --git a/app/controllers/api/v1/financekit/connections_controller.rb b/app/controllers/api/v1/financekit/connections_controller.rb
index 9770cf5f08..c6923f0513 100644
--- a/app/controllers/api/v1/financekit/connections_controller.rb
+++ b/app/controllers/api/v1/financekit/connections_controller.rb
@@ -1,11 +1,14 @@
class Api::V1::Financekit::ConnectionsController < Api::V1::Financekit::BaseController
def capabilities
- available = Financekit.enabled?(current_resource_owner.family)
- render_json({ available: available, protocol_versions: [ Financekit::VERSION ],
+ # Kept in the response because the client reads it, but it no longer answers
+ # "has an operator switched this family on" -- there is no such switch. It
+ # says this build speaks the publisher protocol, which it does by existing.
+ render_json({ available: true, protocol_versions: [ Financekit::VERSION ],
delivery: "background_publisher", max_payload_bytes: Financekit::MAX_BYTES,
max_records: Financekit::MAX_RECORDS, max_accounts: Financekit::MAX_ACCOUNTS,
max_queued_batches: Financekit::MAX_QUEUED, transaction_statuses: Financekit::Payload::STATUSES,
- amount_precision: 19, amount_scale: 4 })
+ amount_precision: 19, amount_scale: 4,
+ connection_dispositions: FinancekitItem.supported_dispositions })
end
def create
@@ -44,19 +47,34 @@ class Api::V1::Financekit::ConnectionsController < Api::V1::Financekit::BaseCont
end
def destroy
- connection.disconnect!
- head :no_content
+ # Retain keeps the response it has always had, so a client that sends no
+ # disposition sees no change. Discard is accepted rather than completed: the
+ # deletion runs in the background, and the connection payload lets the client
+ # show what it is waiting on.
+ connection.disconnect!(disposition: disposition)
+ return head :no_content unless disposition == ProviderDisconnectable::DISCARD
+
+ render_json(connection_data(connection).merge(disposition: disposition), status: :accepted)
end
private
+ def disposition
+ @disposition ||= begin
+ value = params[:disposition].presence&.to_s || ProviderDisconnectable::DEFAULT_DISPOSITION
+ Financekit.require!(connection.disposition_supported?(value), "invalid_disposition")
+ value
+ end
+ end
+
def connection_data(item)
{ id: item.id, connection_id: item.id, publisher_id: item.publisher_id, status: item.status,
generation: item.generation, stream_id: item.stream_id, next_sequence: item.next_sequence,
repair_reason: item.repair_reason, last_device_contact_at: item.last_device_contact_at,
last_accepted_at: item.last_accepted_at, last_imported_at: item.last_imported_at,
last_downstream_at: item.last_downstream_at, last_captured_at: item.last_captured_at,
- open_conflicts: item.financekit_conflicts.open.count }
+ open_conflicts: item.financekit_conflicts.open.count,
+ purge_requested_at: item.purge_requested_at, purge_completed_at: item.purge_completed_at }
end
def mapping_data(mapping)
diff --git a/app/jobs/financekit_inbox_job.rb b/app/jobs/financekit_inbox_job.rb
index ca6fd6f859..b4cbae3765 100644
--- a/app/jobs/financekit_inbox_job.rb
+++ b/app/jobs/financekit_inbox_job.rb
@@ -4,18 +4,60 @@ class FinancekitInboxJob < ApplicationJob
def perform(item_id = nil)
items = item_id ? FinancekitItem.where(id: item_id) : FinancekitItem.where(status: "active")
items.find_each do |item|
- next unless Financekit.enabled?(item.family)
-
+ # Ids only: a drained capture still holds its payload bytes. Every part of
+ # a multi-chunk capture is collected, so none is left for the sweep below
+ # to fan out a second time in this same run.
+ applied_ids = []
Financekit::MAX_QUEUED.times do
- break unless Financekit::Processor.new(item).apply_next!
- end
- end
- FinancekitBatch.where(status: "applied", downstream_completed_at: nil).find_each do |batch|
- next unless Financekit.enabled?(batch.financekit_item.family)
+ parts = Financekit::Processor.new(item).apply_next!
+ break if parts.blank?
- Financekit::Downstream.new(batch).perform!
+ applied_ids.concat(parts.map(&:id))
+ end
+ Financekit::Downstream.new(item, FinancekitBatch.where(id: applied_ids)).perform!
end
+ recover_lost_downstream_work!
+ recover_lost_purges!
FinancekitBatch.where(status: %w[applied failed revoked]).where("updated_at < ?", 7.days.ago)
.where.not(payload: nil).update_all(payload: nil, updated_at: Time.current)
end
+
+ private
+
+ # A discard the family asked for outlives the job that was meant to carry it
+ # out: the request is recorded on the connection, so an enqueue that never
+ # landed or a job that died partway is finished here. Financekit::Purge is
+ # resumable -- it skips lineages it has already discarded -- so repeating it
+ # costs nothing but is never skipped.
+ def recover_lost_purges!
+ # Materialized rather than find_each: that would discard the order and the
+ # bound, and the oldest request is the one that has been waiting.
+ FinancekitItem.where.not(purge_requested_at: nil).where(purge_completed_at: nil)
+ .order(:purge_requested_at).limit(Financekit::MAX_QUEUED).to_a.each do |item|
+ Financekit::Purge.new(item).perform!
+ rescue StandardError
+ # Purge already recorded the failure and left the request standing for the
+ # next sweep. One publisher's failure must not strand the others.
+ next
+ end
+ end
+
+ # A lost job leaves applied batches with no downstream work. Bounded per
+ # pass and per publisher: the fan-out costs the same for one batch or many,
+ # so a larger backlog simply clears over the following sweeps.
+ def recover_lost_downstream_work!
+ pending = FinancekitBatch.where(status: "applied", downstream_completed_at: nil)
+ pending.distinct.pluck(:financekit_item_id).each do |financekit_item_id|
+ item = FinancekitItem.find_by(id: financekit_item_id)
+ next unless item
+
+ # Ordered because the limit makes the choice matter: without it Postgres
+ # may return any MAX_QUEUED of the backlog, so the same rows can lose
+ # every sweep while newer ones complete. Stream order is the publisher's
+ # own order and matches the financekit_stream_sequence index.
+ scope = pending.where(financekit_item_id: financekit_item_id)
+ .order(:generation, :stream_id, :sequence).limit(Financekit::MAX_QUEUED)
+ Financekit::Downstream.new(item, scope).perform!
+ end
+ end
end
diff --git a/app/jobs/financekit_purge_job.rb b/app/jobs/financekit_purge_job.rb
new file mode 100644
index 0000000000..9036a8473e
--- /dev/null
+++ b/app/jobs/financekit_purge_job.rb
@@ -0,0 +1,11 @@
+class FinancekitPurgeJob < ApplicationJob
+ # Deleting a year of card history is bulk work, not something a family is
+ # waiting on a spinner for. Low priority so it never delays an import.
+ queue_as :low_priority
+
+ def perform(item)
+ return unless item.purge_pending?
+
+ Financekit::Purge.new(item).perform!
+ end
+end
diff --git a/app/models/concerns/provider_disconnectable.rb b/app/models/concerns/provider_disconnectable.rb
new file mode 100644
index 0000000000..bd431a675d
--- /dev/null
+++ b/app/models/concerns/provider_disconnectable.rb
@@ -0,0 +1,70 @@
+# What happens to imported financial data when a provider connection goes away.
+#
+# Disconnecting has always meant one thing in this app: revoke the credential,
+# drop the AccountProvider links, and leave every account, balance and
+# transaction where it is. That is the right default -- the data describes the
+# family's money, not the connection that fetched it, and a reconnect should
+# find its history intact. But it is not the only thing a family may want. A
+# person who connects a wallet, sees a year of card spending appear, and decides
+# against it is asking for the import to be undone, not parked.
+#
+# So a disconnect carries a disposition:
+#
+# retain -- revoke the connection, keep the imported data. Every provider
+# supports this, and it stays the default: a caller that says
+# nothing gets the behaviour it has always got.
+# discard -- revoke the connection and remove what it imported. Destructive
+# and irreversible, so a provider has to implement it deliberately
+# and declare that it has.
+#
+# Providers opt in with `self.supports_discard = true`. The default is false, so
+# an unconverted provider reports only `retain` and rejects `discard` instead of
+# silently accepting it and keeping the data -- the failure mode that would
+# matter here is a family being told their data was deleted when it was not.
+#
+# The vocabulary lives here rather than in any one provider because it is a
+# contract with API clients: FinanceKit's capabilities response advertises the
+# dispositions this build supports, and a client feature-detects rather than
+# hardcoding. Adding a second provider should not change the wire format.
+module ProviderDisconnectable
+ extend ActiveSupport::Concern
+
+ RETAIN = "retain"
+ DISCARD = "discard"
+ DISPOSITIONS = [ RETAIN, DISCARD ].freeze
+ DEFAULT_DISPOSITION = RETAIN
+
+ included do
+ class_attribute :supports_discard, instance_writer: false, default: false
+ end
+
+ class_methods do
+ def supported_dispositions
+ supports_discard ? DISPOSITIONS : [ DEFAULT_DISPOSITION ]
+ end
+ end
+
+ def supported_dispositions
+ self.class.supported_dispositions
+ end
+
+ def disposition_supported?(disposition)
+ supported_dispositions.include?(disposition.to_s)
+ end
+
+ # Normalizes a caller-supplied disposition, or raises. Callers that answer to
+ # an API translate this into their own typed error: the concern has no opinion
+ # about status codes.
+ def disposition!(disposition)
+ value = disposition.presence&.to_s || DEFAULT_DISPOSITION
+ unless disposition_supported?(value)
+ raise ArgumentError, "unsupported disconnect disposition: #{value.inspect}"
+ end
+
+ value
+ end
+
+ def discarding?(disposition)
+ disposition!(disposition) == DISCARD
+ end
+end
diff --git a/app/models/financekit.rb b/app/models/financekit.rb
index 5ee69c9b8a..346b728193 100644
--- a/app/models/financekit.rb
+++ b/app/models/financekit.rb
@@ -21,11 +21,6 @@ module Financekit
raise Error.new(code, status) unless condition
end
- def self.enabled?(family)
- ENV["FINANCEKIT_ENABLED"] == "true" &&
- ENV.fetch("FINANCEKIT_FAMILY_IDS", "").split(",").map(&:strip).include?(family.id)
- end
-
def self.issue_credential
SecureRandom.urlsafe_base64(TOKEN_BYTES, false)
end
diff --git a/app/models/financekit/account_mapping.rb b/app/models/financekit/account_mapping.rb
index a05be2f451..0b6d8fd72d 100644
--- a/app/models/financekit/account_mapping.rb
+++ b/app/models/financekit/account_mapping.rb
@@ -78,7 +78,10 @@ class Financekit::AccountMapping
account = @item.family.accounts.create!(owner: @item.user, name: @input["name"], currency: @input["currency"],
balance: Financekit::Mapping.balance(@input["booked_balance"], @input["accountable_type"]),
accountable: type.new(subtype: @input["subtype"]), status: "active")
- [ account, @item.family.financekit_account_lineages.create!(account: account) ]
+ # FinanceKit brought this account into existence, so a discard may take it
+ # away again. Recorded on the lineage rather than the mapping because the
+ # lineage owns the canonical account across device replacement.
+ [ account, @item.family.financekit_account_lineages.create!(account: account, account_origin: "created") ]
end
def link_account_and_lineage!
@@ -90,7 +93,9 @@ class Financekit::AccountMapping
@item.family.financekit_account_lineages.find_by(account: account)
end
Financekit.require!(!lineage || lineage.account_id == account.id, "lineage_account_conflict", 409)
- lineage ||= @item.family.financekit_account_lineages.create!(account: account)
+ # The family owned this account before FinanceKit reached it, so a discard
+ # empties it and leaves it standing.
+ lineage ||= @item.family.financekit_account_lineages.create!(account: account, account_origin: "linked")
[ account, lineage ]
end
diff --git a/app/models/financekit/downstream.rb b/app/models/financekit/downstream.rb
index f1c2f6edc9..cdcb3402a9 100644
--- a/app/models/financekit/downstream.rb
+++ b/app/models/financekit/downstream.rb
@@ -1,28 +1,100 @@
class Financekit::Downstream
- def initialize(batch)
- @batch = batch
+ ADVISORY_LOCK_SCOPE = "financekit_downstream".freeze
+
+ # Takes a scope rather than loaded records and keeps only the ids. A pending
+ # batch carries its payload — up to Financekit::MAX_BYTES, retained for seven
+ # days — and an applied batch no longer counts against the inbox cap, so a
+ # backlog awaiting downstream work has no ceiling of its own.
+ def initialize(item, scope)
+ @item = item
+ @batch_ids = scope.where(downstream_completed_at: nil).pluck(:id)
end
def perform!
- return if @batch.downstream_completed_at?
+ return if @batch_ids.empty?
- item = @batch.financekit_item
+ # A drain covers a whole backlog, so diagnostics name the newest batch in it
+ # and count the rest: that keeps a capture traceable from upload through
+ # import to its downstream work without loading the payload bytes of every
+ # batch to describe them. Plucked up front so the failure path below needs
+ # no query of its own.
+ @identity = FinancekitBatch.where(id: @batch_ids)
+ .order(sequence: :desc, chunk_index: :desc).pick(:batch_id, :capture_id, :sequence)
account_provider = nil
- item.selected_accounts.includes(financekit_account_lineage: [ :account, :account_provider ]).find_each do |mapping|
- account_provider = mapping.financekit_account_lineage.account_provider
- mapping.account&.sync_later
+
+ with_publisher_claim do
+ # Re-read inside the claim. Two workers can snapshot the same ids before
+ # either runs — a per-upload job and the periodic sweep overlap this way —
+ # and without this the second one repeats the whole family fan-out.
+ pending = FinancekitBatch.where(id: @batch_ids, downstream_completed_at: nil).pluck(:id)
+ next if pending.empty?
+
+ # Scheduling and both completion writes in one transaction. Committing the
+ # two writes separately left batches complete alongside stale publisher
+ # health, which the recovery sweep then skipped because it only looks for
+ # incomplete batches. Scheduling outside it was no better: a failed health
+ # write rolled the batch back after the jobs were already queued, so
+ # recovery ran the same rules again and RuleJob records a RuleRun per run.
+ # Enqueueing from inside is safe here because ApplicationJob sets
+ # enqueue_after_transaction_commit, so SyncJob and RuleJob are deferred to
+ # the commit and dropped outright if it rolls back.
+ #
+ # The fan-out itself costs the same whether one capture or fifty just
+ # landed, so a drain pays for it once rather than once per capture.
+ completed_at = Time.current
+ FinancekitBatch.transaction do
+ @item.selected_accounts.includes(financekit_account_lineage: [ :account, :account_provider ]).find_each do |mapping|
+ account_provider = mapping.financekit_account_lineage.account_provider
+ mapping.account&.sync_later
+ end
+ # Only the per-account fan-out above belongs to one account provider.
+ # Anything failing after it is the publisher's, so drop the attribution.
+ account_provider = nil
+ @item.family.auto_match_transfers!
+ @item.family.rules.where(active: true).find_each(&:apply_later)
+
+ FinancekitBatch.where(id: pending)
+ .update_all(downstream_completed_at: completed_at, updated_at: completed_at)
+ @item.update!(last_downstream_at: completed_at)
+ end
+ Financekit::Diagnostics.capture(item: @item, source: self.class.name,
+ message: "FinanceKit downstream scheduling completed", event: "downstream_completed",
+ **identity_details(pending.size))
end
- account_provider = nil
- item.family.auto_match_transfers!
- item.family.rules.where(active: true).find_each(&:apply_later)
- completed_at = Time.current
- @batch.update!(downstream_completed_at: completed_at)
- item.update!(last_downstream_at: completed_at)
- Financekit::Diagnostics.capture(item: item, batch: @batch, source: self.class.name,
- message: "FinanceKit downstream scheduling completed", event: "downstream_completed")
rescue StandardError => error
- Financekit::Diagnostics.capture(item: @batch.financekit_item, batch: @batch, source: self.class.name,
- level: "error", message: "FinanceKit downstream scheduling failed", event: "downstream_failed",
- account_provider: account_provider, error_class: error.class.name)
+ Financekit::Diagnostics.capture(item: @item, source: self.class.name, level: "error",
+ message: "FinanceKit downstream scheduling failed", event: "downstream_failed",
+ account_provider: account_provider, error_class: error.class.name,
+ **identity_details(@batch_ids.size))
end
+
+ private
+ # Same metadata keys Financekit::Diagnostics derives from a single batch, so
+ # downstream events stay searchable alongside the rest of the capture.
+ def identity_details(batches)
+ batch_id, capture_id, sequence = @identity
+ { batches: batches, batch_id: batch_id, capture_id: capture_id, sequence: sequence }
+ end
+
+ def with_publisher_claim
+ acquired = ActiveRecord::Base.connection.select_value(
+ ActiveRecord::Base.sanitize_sql_array([ "SELECT pg_try_advisory_lock(?)", advisory_lock_key ])
+ )
+ # Another worker holds this publisher's downstream work. It completes the
+ # batches it claimed, and the sweep picks up anything left behind.
+ return unless acquired
+
+ begin
+ yield
+ ensure
+ ActiveRecord::Base.connection.execute(
+ ActiveRecord::Base.sanitize_sql_array([ "SELECT pg_advisory_unlock(?)", advisory_lock_key ])
+ )
+ end
+ end
+
+ def advisory_lock_key
+ # Matches the keying used by the other advisory-locked jobs in this app.
+ @advisory_lock_key ||= Digest::MD5.hexdigest("#{ADVISORY_LOCK_SCOPE}:#{@item.id}").to_i(16) % (2**62)
+ end
end
diff --git a/app/models/financekit/payload.rb b/app/models/financekit/payload.rb
index 99cb892bb5..d03727ebd6 100644
--- a/app/models/financekit/payload.rb
+++ b/app/models/financekit/payload.rb
@@ -1,7 +1,11 @@
class Financekit::Payload
STATUSES = %w[authorized pending booked rejected memo unknown].freeze
EVENT_KINDS = %w[account_upsert account_unavailable balance_upsert transaction_upsert transaction_tombstone].freeze
- UUID = /\A[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/i
+ # Source identifiers come from FinanceKit, so accept any RFC 4122 layout
+ # rather than pinning the version and variant nibbles: a UUIDv7 or a nil UUID
+ # is still a valid opaque identifier, and rejecting one wedges the stream on a
+ # record Sure does not mint. Matches lib/uuid_format.rb, used everywhere else.
+ UUID = UuidFormat::PATTERN
DIGEST = /\A[0-9a-f]{64}\z/
DECIMAL = /\A(?:0|[1-9][0-9]{0,14})(?:\.[0-9]{1,4})?\z/
EXCHANGE_RATE = /\A(?:0|[1-9][0-9]{0,17})(?:\.[0-9]{1,18})?\z/
diff --git a/app/models/financekit/processor.rb b/app/models/financekit/processor.rb
index 3acc784cca..d4773760a2 100644
--- a/app/models/financekit/processor.rb
+++ b/app/models/financekit/processor.rb
@@ -3,8 +3,12 @@ class Financekit::Processor
@item = item
end
+ # Returns every part of the capture it applied, so the caller can complete
+ # them together. Returning only the last chunk left the earlier ones without
+ # downstream work, and the recovery sweep then repeated the fan-out for them.
def apply_next!
batch = nil
+ applied = nil
@item.with_lock do
@item.require_publisher!
batch = @item.financekit_batches.find_by(generation: @item.generation,
@@ -39,11 +43,14 @@ class Financekit::Processor
@item.update!(next_sequence: last.sequence + 1, predecessor_digest: last.payload_digest,
last_imported_at: applied_at, last_captured_at: last.captured_at)
batch = last
+ applied = capture
end
Financekit::Diagnostics.capture(item: @item, batch: batch, source: self.class.name,
message: "FinanceKit capture imported", event: "capture_imported", counts: batch.counts, sync_id: batch.sync_id)
- Financekit::Downstream.new(batch).perform!
- true
+ # Downstream work belongs to the caller: it completes every part of the
+ # capture together, and a drain pays for the family fan-out once rather
+ # than once per capture.
+ applied
rescue ActiveRecord::RecordInvalid => error
# Retryable. RecordInvalid covers ordinary races — a concurrent balance
# observation or conflict insert, an entry validation a later attempt
@@ -98,16 +105,25 @@ class Financekit::Processor
def import_balance!(mapping, record, counts)
observed_at = Financekit::Payload.timestamp!(record["observed_at"])
money = record.fetch("money")
+ amount = Financekit::Payload.money!(money)
observation = mapping.financekit_balance_observations.find_or_create_by!(source_id: record["source_id"],
kind: record["kind"], observed_at: observed_at) do |balance|
balance.financekit_account = mapping
- balance.amount = Financekit::Payload.money!(money)
+ balance.amount = amount
balance.currency = money["currency"]
balance.direction = money["direction"]
end
- Financekit.require!(observation.amount == Financekit::Payload.money!(money) &&
- observation.currency == money["currency"] && observation.direction == money["direction"],
- "balance_observation_conflict", 409)
+ # A stored observation is immutable, so the retained value and the
+ # canonical balance both stay as they are. Detecting the disagreement is
+ # right; ending ingestion over it is not. Fencing here would clear the
+ # upload credential, and only a foreground OAuth repair can reissue one —
+ # the same reason import validation retries rather than fences. Raise it
+ # for the family and carry on with the rest of the capture.
+ if observation.amount != amount || observation.currency != money["currency"] ||
+ observation.direction != money["direction"]
+ counts[create_observation_conflict!(mapping, record, observed_at) ? "review_required" : "settled"] += 1
+ return
+ end
counts["balances"] += 1 if observation.previously_new_record?
return unless record["kind"] == "booked"
@@ -133,8 +149,7 @@ class Financekit::Processor
# capture that covers it, so without this the resolved conflict reopens
# on the next batch and the family is asked the same question forever.
if settled_by_family?(identity)
- identity.review_required = false
- identity.save!
+ identity.refresh_review_required!
counts["settled"] += 1
return
end
@@ -204,7 +219,9 @@ class Financekit::Processor
# The family already chose to keep Sure's entry for this identity. The
# tombstone is still recorded so the source cannot resurrect it, but the
# protected entry stays and the answered conflict is not reopened.
- identity.review_required = false
+ # Review state follows the same rule as resolution and upserts: it is
+ # open while any conflict about this record still is.
+ identity.review_required = identity.review_required_from_conflicts
counts["settled"] += 1
elsif entry
Entry.transaction do
@@ -273,10 +290,13 @@ class Financekit::Processor
end
end
+ # Ordered cheapest first: every check below the columns loads an
+ # association, and transfer/split membership each cost a query.
def protected_entry?(entry)
- entry.protected_from_sync? || entry.transaction.transfer.present? || entry.transaction.transfer_id.present? || entry.reconciled_at.present? ||
- entry.split_parent? || entry.split_child? || entry.locked_attributes.present? ||
- entry.transaction.locked_attributes.present?
+ entry.protected_from_sync? || entry.reconciled_at.present? || entry.split_child? ||
+ entry.locked_attributes.present? || entry.transaction.locked_attributes.present? ||
+ entry.transaction.transfer_id.present? || entry.transaction.transfer.present? ||
+ entry.split_parent?
end
# Preserve the shared importer's pending-to-booked exception for user edits,
@@ -289,12 +309,59 @@ class Financekit::Processor
return unless entry.user_modified? && !entry.excluded? && !entry.import_locked?
transaction = entry.transaction
- if transaction.extra.dig("financekit", "pending")
+ if transaction.extra&.dig("financekit", "pending")
transaction.update!(extra: transaction.extra.deep_merge("financekit" => { "pending" => false }))
end
end
end
+ # Balance observations have no source transaction, so the conflict hangs off
+ # the lineage and carries the observation identity in its details. Returns
+ # whether the record still needs review.
+ #
+ # Matching on that identity rather than the lineage alone is what makes
+ # "keep Sure" durable here, the same way it is for a source transaction: the
+ # publisher re-sends the same disagreement on every capture that covers it,
+ # so keying the lookup on open rows made the decision last one capture. A
+ # different observation still opens its own conflict.
+ def create_observation_conflict!(mapping, record, observed_at)
+ # Canonical UTC, not the wire string: the observation itself is keyed on
+ # the parsed instant, so two payloads spelling the same moment differently
+ # hit one observation and must consult one decision.
+ details = { "source_id" => record["source_id"], "kind" => record["kind"],
+ "observed_at" => observed_at.utc.iso8601(6) }
+ # Searched across the family rather than this connection, the same way a
+ # source transaction's decision is, because the observation lives on the
+ # lineage and outlives the publisher that sent it. A replacement device
+ # must not reopen a question the family already answered. The new row
+ # still belongs to the connection that raised it.
+ history = FinancekitConflict.where(family_id: @item.family_id)
+ .where(kind: "balance_observation_conflict",
+ financekit_account_lineage_id: mapping.financekit_account_lineage_id)
+ .where("details @> ?::jsonb", details.to_json)
+ return false if history.exists?(resolution: "keep_sure")
+ return true if history.open.exists?
+
+ # The check above cannot settle it alone: two publishers can share one
+ # lineage — a replacement device keeps the lineage of the device it
+ # replaces — so both can find no open row and then both insert. The
+ # financekit_conflicts_open_observation index decides which one wins. In a
+ # savepoint because a unique violation aborts the surrounding transaction,
+ # and this import has the rest of the capture still to apply.
+ begin
+ FinancekitConflict.transaction(requires_new: true) do
+ @item.financekit_conflicts.create!(family: @item.family,
+ financekit_account_lineage: mapping.financekit_account_lineage,
+ kind: "balance_observation_conflict", status: "open", details: details)
+ end
+ rescue ActiveRecord::RecordNotUnique
+ # The other publisher asked first. The question is open either way, and
+ # the row belongs to whichever connection got there first.
+ nil
+ end
+ true
+ end
+
def create_conflict!(mapping, identity, kind)
@item.financekit_conflicts.find_or_create_by!(financekit_transaction: identity, kind: kind, status: "open") do |conflict|
conflict.family = @item.family
diff --git a/app/models/financekit/purge.rb b/app/models/financekit/purge.rb
new file mode 100644
index 0000000000..d4ff75c9c1
--- /dev/null
+++ b/app/models/financekit/purge.rb
@@ -0,0 +1,103 @@
+# Removes what a FinanceKit connection imported, for a family that disconnected
+# with disposition "discard".
+#
+# Irreversible, and deliberately thorough: everything the publisher put into the
+# ledger goes, including entries the family later reconciled, excluded or edited.
+# A partial deletion would be worse than none, because the family was told their
+# data was removed.
+#
+# Two things survive, and both are deliberate. The connection row itself stays as
+# a revoked receipt -- it holds no financial values, and the batch receipts beside
+# it already had their payloads dropped at revocation. And a lineage another
+# active connection still publishes into is left entirely alone: during a device
+# replacement window two items reference one lineage, and one of them disconnecting
+# must not delete the other's live accounts.
+class Financekit::Purge
+ COUNT_KEYS = %w[accounts_destroyed accounts_emptied entries identities observations conflicts
+ lineages_skipped].freeze
+
+ def initialize(item)
+ @item = item
+ end
+
+ def perform!
+ counts = COUNT_KEYS.index_with(0)
+ @item.financekit_account_lineages.distinct.find_each do |lineage|
+ next counts["lineages_skipped"] += 1 if lineage.other_active_writer_than?(@item)
+ next if lineage.discarded?
+
+ purge_lineage!(lineage, counts)
+ end
+ @item.update!(purge_completed_at: Time.current)
+ Financekit::Diagnostics.capture(item: @item, source: self.class.name,
+ message: "FinanceKit imported data discarded", event: "purge_completed", counts: counts)
+ counts
+ rescue StandardError => error
+ # purge_completed_at stays nil, so the sweep in FinancekitInboxJob tries
+ # again. Re-raised so the job's own retry sees it too: a deletion the family
+ # asked for should not be dropped on the floor quietly.
+ Financekit::Diagnostics.capture(item: @item, source: self.class.name, level: "error",
+ message: "FinanceKit discard failed", event: "purge_failed", error_class: error.class.name)
+ raise
+ end
+
+ private
+
+ def purge_lineage!(lineage, counts)
+ account = lineage.account
+ # One transaction per lineage rather than one for the whole connection: a
+ # family with several wallet accounts should not lose a completed account's
+ # deletion because a later one failed, and the sweep resumes from whatever
+ # is left.
+ FinancekitAccountLineage.transaction do
+ empty_or_destroy_account!(account, lineage, counts) if account
+ counts["conflicts"] += FinancekitConflict.where(financekit_account_lineage_id: lineage.id).destroy_all.size
+ counts["identities"] += lineage.financekit_transactions.destroy_all.size
+ counts["observations"] += lineage.financekit_balance_observations.destroy_all.size
+ # account is nulled so a later enrollment cannot resurrect the link to an
+ # account this lineage no longer describes, and the row stays as the
+ # record that this source was discarded rather than merely unlinked.
+ lineage.update!(status: FinancekitAccountLineage::DISCARDED, account: nil)
+ end
+ end
+
+ def empty_or_destroy_account!(account, lineage, counts)
+ unless lineage.account_created_by_provider?
+ counts["entries"] += destroy_imported_entries!(account)
+ counts["accounts_emptied"] += 1
+ # The canonical balance came from a booked observation that no longer
+ # exists. Sync recomputes it from the entries that remain, which for a
+ # linked account is the history the family had before FinanceKit arrived.
+ account.sync_later
+ return
+ end
+
+ counts["entries"] += account.entries.count
+ account.destroy!
+ counts["accounts_destroyed"] += 1
+ end
+
+ # Entries carry source "financekit" whether the publisher created them or
+ # claimed a manual entry that matched. Both are removed: the family asked for
+ # the import to be undone, and a claimed entry's amount and date came from
+ # the publisher even when the row did not.
+ #
+ # Destroyed one at a time rather than deleted in bulk because an entry's
+ # entryable is reachable only through Active Record: nothing in the database
+ # points from a transactions row back to its entry. A bulk delete leaves the
+ # Transaction standing, and with it any Transfer the entry was part of and
+ # that transfer's fee transactions. Destroying the entry takes the whole chain
+ # and leaves the counterpart entry in place, unlinked -- which is the
+ # behaviour the disconnect tests pin.
+ #
+ # Split children are the exception that needs no help here: entries.parent_entry_id
+ # cascades in the database, so they would go either way.
+ def destroy_imported_entries!(account)
+ destroyed = 0
+ account.entries.where(source: "financekit").find_each do |entry|
+ entry.destroy!
+ destroyed += 1
+ end
+ destroyed
+ end
+end
diff --git a/app/models/financekit_account_lineage.rb b/app/models/financekit_account_lineage.rb
index cde903e68d..ca4fa8a4f6 100644
--- a/app/models/financekit_account_lineage.rb
+++ b/app/models/financekit_account_lineage.rb
@@ -1,4 +1,7 @@
class FinancekitAccountLineage < ApplicationRecord
+ ACCOUNT_ORIGINS = %w[created linked].freeze
+ DISCARDED = "discarded".freeze
+
belongs_to :family
belongs_to :account, optional: true
has_many :financekit_accounts, dependent: :restrict_with_error
@@ -6,8 +9,38 @@ class FinancekitAccountLineage < ApplicationRecord
has_many :financekit_balance_observations, dependent: :destroy
has_one :account_provider, as: :provider, dependent: :destroy
+ scope :discarded, -> { where(status: DISCARDED) }
+
+ # Only an account FinanceKit brought into existence is FinanceKit's to destroy.
+ # A NULL origin predates the column and cannot be reclassified after the fact,
+ # so it reads as linked: emptying an account the family created themselves is
+ # recoverable, destroying it is not.
+ def account_created_by_provider?
+ account_origin == "created"
+ end
+
+ def discarded?
+ status == DISCARDED
+ end
+
+ # A lineage outlives the connection that mapped it, so more than one item can
+ # reference it -- a replacement device and the device it replaces, during the
+ # window before the old one is revoked. Releasing links or purging data for one
+ # of them must not touch a lineage another connection is still publishing into.
+ def other_active_writer_than?(item)
+ FinancekitAccount.joins(:financekit_item)
+ .where(financekit_account_lineage_id: id, financekit_items: { status: "active" })
+ .where.not(financekit_item_id: item.id).exists?
+ end
+
# A publisher credential covers every account in its connection. Fence its
# queued uploads before releasing links, retaining identities for re-enrollment.
+ #
+ # Retain-only on purpose. This is the path the web unlink flow takes, where
+ # unlinking an account has always meant keeping its history -- and where the
+ # person is acting on one account, not consenting to delete everything the
+ # connection imported into the others it covers. A discard comes from the
+ # connection itself, through FinancekitItem#disconnect!.
def disconnect!
family.with_lock do
family.financekit_items.where(id: financekit_accounts.select(:financekit_item_id))
diff --git a/app/models/financekit_conflict.rb b/app/models/financekit_conflict.rb
index d50f879fdb..a9a08b93f8 100644
--- a/app/models/financekit_conflict.rb
+++ b/app/models/financekit_conflict.rb
@@ -13,15 +13,30 @@ class FinancekitConflict < ApplicationRecord
lock!
Financekit.require!(status == "open", "conflict_already_resolved", 409)
update!(status: "resolved", resolution: resolution, resolved_by: user, resolved_at: Time.current)
- case resolution
- when "keep_sure"
- financekit_transaction&.update!(review_required: false)
- when "retry_after_repair"
+ if resolution == "retry_after_repair"
+ release_conflicting_observation!
financekit_item.mark_repair!("conflict_retry_requested")
- if financekit_transaction
- financekit_transaction.update!(review_required: financekit_transaction.financekit_conflicts.open.exists?)
- end
end
+ # Both resolutions land on the same rule: a record is under review while
+ # it still has an open conflict, whichever resolution closed this one.
+ financekit_transaction&.refresh_review_required!
end
end
+
+ private
+
+ # Asking the publisher to retry only means something if the stored
+ # observation stops blocking the replay. Observations are immutable, so the
+ # same money would disagree again after the repair and the conflict would
+ # simply reopen. Dropping the one the family declined lets the new
+ # generation supply the value they chose to accept; every other observation
+ # on the lineage is untouched, and the canonical balance still only moves
+ # when a newer booked value lands.
+ def release_conflicting_observation!
+ return unless kind == "balance_observation_conflict" && financekit_account_lineage
+
+ financekit_account_lineage.financekit_balance_observations
+ .where(source_id: details["source_id"], kind: details["kind"],
+ observed_at: details["observed_at"]).delete_all
+ end
end
diff --git a/app/models/financekit_item.rb b/app/models/financekit_item.rb
index b681a0a7a6..63f2782b5b 100644
--- a/app/models/financekit_item.rb
+++ b/app/models/financekit_item.rb
@@ -1,5 +1,9 @@
class FinancekitItem < ApplicationRecord
include Syncable
+ include ProviderDisconnectable
+
+ # FinanceKit implements discard: see Financekit::Purge.
+ self.supports_discard = true
before_destroy :release_orphaned_lineage_links
@@ -41,12 +45,19 @@ class FinancekitItem < ApplicationRecord
ActiveSupport::SecurityUtils.secure_compare(credential_digest, candidate)
end
+ # Re-checked on every upload rather than trusted from enrollment: a credential
+ # outlives the state that issued it, and the enroller can be deactivated, moved
+ # to another family or demoted between captures.
+ #
+ # No feature flag and no preview opt-in. Admin is the one standing requirement,
+ # because a publisher writes into accounts the whole family reads; the
+ # writable-accounts check below is what confines it to accounts this user may
+ # actually touch.
def require_publisher!
error = status == "repair_required" ? "repair_required" : "connection_revoked"
Financekit.require!(status == "active", error, 403)
- Financekit.require!(Financekit.enabled?(family), "unavailable", 503)
user.reload
- Financekit.require!(user.active? && user.family_id == family_id && user.admin? && user.preview_features_enabled?,
+ Financekit.require!(user.active? && user.family_id == family_id && user.admin?,
"publisher_forbidden", 403)
Financekit.require!(!pending_account_setup?, "account_setup_required", 409)
permitted_ids = family.accounts.writable_by(user).pluck(:id)
@@ -112,8 +123,24 @@ class FinancekitItem < ApplicationRecord
end
end
- def disconnect!
- family.with_lock { revoke!(release_lineages_except: []) }
+ # A retain disconnect is the long-standing behaviour: revoke the credential and
+ # the links, leave every account and transaction standing. A discard adds the
+ # removal of what this connection imported, which runs in the background
+ # because a year of card history is not a request-sized amount of deleting.
+ def disconnect!(disposition: ProviderDisconnectable::DEFAULT_DISPOSITION)
+ discard = discarding?(disposition)
+ family.with_lock do
+ revoke!(release_lineages_except: [])
+ # Recorded inside the revoke so the intent is durable before any job
+ # exists. A deletion the family asked for must not be lost to a queue that
+ # happened to be unreachable a moment later.
+ update!(purge_requested_at: Time.current) if discard
+ end
+ request_purge! if discard
+ end
+
+ def purge_pending?
+ purge_requested_at.present? && purge_completed_at.nil?
end
def revoke!(release_lineages_except: [])
@@ -138,6 +165,19 @@ class FinancekitItem < ApplicationRecord
private
+ # Enqueued outside the revoke transaction so an enqueue failure is visible
+ # here rather than deferred to commit. The marker stays set either way: the
+ # sweep in FinancekitInboxJob finishes a purge whose job never ran, and
+ # rolling the request back would leave the family believing their data was
+ # deleted when it was not.
+ def request_purge!
+ FinancekitPurgeJob.perform_later(self)
+ rescue StandardError => error
+ Financekit::Diagnostics.capture(item: self, source: self.class.name, level: "warn",
+ message: "FinanceKit purge enqueue failed", event: "purge_enqueue_failed",
+ error_class: error.class.name)
+ end
+
def competing_active_writer?(mappings, excluding:)
FinancekitAccount.joins(:financekit_item)
.where(financekit_account_lineage_id: mappings.map(&:financekit_account_lineage_id),
@@ -155,9 +195,6 @@ class FinancekitItem < ApplicationRecord
end
def release_lineage_link!(lineage)
- other_active_writer = FinancekitAccount.joins(:financekit_item)
- .where(financekit_account_lineage_id: lineage.id, financekit_items: { status: "active" })
- .where.not(financekit_item_id: id).exists?
- lineage.account_provider&.destroy! unless other_active_writer
+ lineage.account_provider&.destroy! unless lineage.other_active_writer_than?(self)
end
end
diff --git a/app/models/financekit_transaction.rb b/app/models/financekit_transaction.rb
index 34871d51c9..5b1e4d9c57 100644
--- a/app/models/financekit_transaction.rb
+++ b/app/models/financekit_transaction.rb
@@ -3,4 +3,20 @@ class FinancekitTransaction < ApplicationRecord
belongs_to :financekit_account, optional: true
belongs_to :entry, optional: true
has_many :financekit_conflicts, dependent: :nullify
+
+ # One definition of the rule every caller shares: a record is under review
+ # while any conflict about it is still open, whatever created or closed the
+ # last one. Not memoized per pass — an importer creates conflicts for the same
+ # identity while it works, and a cached answer would clear a review that had
+ # just been raised. The financekit_transaction_id index makes each check an
+ # index-only existence probe.
+ def review_required_from_conflicts
+ financekit_conflicts.open.exists?
+ end
+
+ # For callers that are done writing. Mid-write callers assign
+ # review_required_from_conflicts and save it with the rest of the record.
+ def refresh_review_required!
+ update!(review_required: review_required_from_conflicts)
+ end
end
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
index 29abe5efb1..413aa659ce 100644
--- a/config/initializers/filter_parameter_logging.rb
+++ b/config/initializers/filter_parameter_logging.rb
@@ -11,6 +11,8 @@ Rails.application.config.filter_parameters += [
# A device code redeems into tokens on its own, so it is a bearer credential in
# transit; verification_uri_complete embeds the user code, hence all three.
:device_code, :user_code, :verification_uri_complete,
- :bank_username, :bank_password, :security_answers, :captcha_input, :credential,
- :events, :consent, :booked_balance
+ :bank_username, :bank_password, :security_answers, :captcha_input,
+ # FinanceKit publisher bodies. Anchored: an unanchored :credential also hides
+ # credential_id and has_*_credentials, and :events any key containing "events".
+ /\A(publisher_)?credential\z/i, /\Aevents\z/i, /\Aconsent\z/i, /\Abooked_balance\z/i
]
diff --git a/db/migrate/20260924120000_add_open_observation_conflict_index_to_financekit_conflicts.rb b/db/migrate/20260924120000_add_open_observation_conflict_index_to_financekit_conflicts.rb
new file mode 100644
index 0000000000..d610c805b8
--- /dev/null
+++ b/db/migrate/20260924120000_add_open_observation_conflict_index_to_financekit_conflicts.rb
@@ -0,0 +1,32 @@
+class AddOpenObservationConflictIndexToFinancekitConflicts < ActiveRecord::Migration[8.1]
+ INDEX_NAME = "financekit_conflicts_open_observation".freeze
+
+ def up
+ # Two publishers can share one account lineage — a replacement device keeps
+ # the lineage of the device it replaces — so both could raise the same
+ # balance disagreement before either saw the other's row. Keep the first
+ # question and drop its copies before the index makes them impossible.
+ execute <<~SQL
+ DELETE FROM financekit_conflicts AS victim
+ USING financekit_conflicts AS keeper
+ WHERE victim.status = 'open'
+ AND keeper.status = 'open'
+ AND victim.kind = 'balance_observation_conflict'
+ AND keeper.kind = 'balance_observation_conflict'
+ AND victim.financekit_account_lineage_id = keeper.financekit_account_lineage_id
+ AND victim.details = keeper.details
+ AND (keeper.created_at, keeper.id) < (victim.created_at, victim.id)
+ SQL
+
+ # details carries the observation the conflict is about — source id, kind and
+ # the canonical observed_at — and jsonb equality normalizes key order, so one
+ # open question per lineage and observation.
+ add_index :financekit_conflicts, [ :financekit_account_lineage_id, :details ],
+ unique: true, name: INDEX_NAME,
+ where: "status = 'open' AND kind = 'balance_observation_conflict'"
+ end
+
+ def down
+ remove_index :financekit_conflicts, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20260924140000_add_disconnect_disposition_to_financekit.rb b/db/migrate/20260924140000_add_disconnect_disposition_to_financekit.rb
new file mode 100644
index 0000000000..9b13fabc7e
--- /dev/null
+++ b/db/migrate/20260924140000_add_disconnect_disposition_to_financekit.rb
@@ -0,0 +1,21 @@
+class AddDisconnectDispositionToFinancekit < ActiveRecord::Migration[8.1]
+ def change
+ # Whether FinanceKit created this canonical account or was linked to one the
+ # family already had. A discard may destroy the first but only empties the
+ # second, which carries history FinanceKit never supplied. Nullable because
+ # lineages mapped before this column cannot be classified after the fact;
+ # NULL reads as "linked", the choice that cannot delete a user's own account.
+ add_column :financekit_account_lineages, :account_origin, :string
+ add_check_constraint :financekit_account_lineages,
+ "account_origin IS NULL OR account_origin IN ('created', 'linked')",
+ name: "financekit_lineage_account_origin"
+
+ # A discard is accepted synchronously and carried out in the background, so
+ # the intent has to outlive the request and the job. The sweep in
+ # FinancekitInboxJob finishes any purge whose job was lost.
+ add_column :financekit_items, :purge_requested_at, :datetime
+ add_column :financekit_items, :purge_completed_at, :datetime
+ add_index :financekit_items, :purge_requested_at,
+ where: "purge_completed_at IS NULL", name: "financekit_items_pending_purge"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 21f0919ad8..972a883b43 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
+ActiveRecord::Schema[8.1].define(version: 2026_09_24_140000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
@@ -910,6 +910,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
create_table "financekit_account_lineages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "account_id"
+ t.string "account_origin"
t.datetime "created_at", null: false
t.uuid "family_id", null: false
t.string "status", default: "active", null: false
@@ -917,6 +918,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
t.index ["account_id"], name: "index_financekit_account_lineages_on_account_id"
t.index ["family_id", "account_id"], name: "financekit_lineage_canonical_account", unique: true, where: "(account_id IS NOT NULL)"
t.index ["family_id"], name: "index_financekit_account_lineages_on_family_id"
+ t.check_constraint "account_origin IS NULL OR (account_origin::text = ANY (ARRAY['created'::character varying, 'linked'::character varying]::text[]))", name: "financekit_lineage_account_origin"
end
create_table "financekit_accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@@ -1004,6 +1006,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
t.string "status", default: "open", null: false
t.datetime "updated_at", null: false
t.index ["family_id"], name: "index_financekit_conflicts_on_family_id"
+ t.index ["financekit_account_lineage_id", "details"], name: "financekit_conflicts_open_observation", unique: true, where: "(((status)::text = 'open'::text) AND ((kind)::text = 'balance_observation_conflict'::text))"
t.index ["financekit_account_lineage_id"], name: "index_financekit_conflicts_on_lineage_id"
t.index ["financekit_item_id", "status", "created_at"], name: "financekit_conflicts_status_created"
t.index ["financekit_item_id"], name: "index_financekit_conflicts_on_financekit_item_id"
@@ -1027,6 +1030,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
t.bigint "next_sequence", default: 1, null: false
t.string "predecessor_digest"
t.uuid "publisher_id", null: false
+ t.datetime "purge_completed_at"
+ t.datetime "purge_requested_at"
t.string "repair_reason"
t.uuid "replaces_financekit_item_id"
t.string "status", default: "pending_mapping", null: false
@@ -1036,6 +1041,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_09_22_230000) do
t.index ["family_id", "enrollment_id"], name: "index_financekit_items_on_family_id_and_enrollment_id", unique: true
t.index ["family_id"], name: "index_financekit_items_on_family_id"
t.index ["publisher_id"], name: "index_financekit_items_on_publisher_id", unique: true
+ t.index ["purge_requested_at"], name: "financekit_items_pending_purge", where: "(purge_completed_at IS NULL)"
t.index ["replaces_financekit_item_id"], name: "index_financekit_items_on_replaces_financekit_item_id"
t.index ["user_id"], name: "index_financekit_items_on_user_id"
t.check_constraint "generation > 0 AND next_sequence > 0", name: "financekit_items_positive_stream"
diff --git a/docs/api/financekit/schemas.json b/docs/api/financekit/schemas.json
index 96e842e9a1..ea5ac6192d 100644
--- a/docs/api/financekit/schemas.json
+++ b/docs/api/financekit/schemas.json
@@ -55,7 +55,7 @@
"items": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
},
"upload_authorized": {
@@ -96,12 +96,12 @@
"enrollment_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"replaces_connection_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"consent": {
"$ref": "#/components/schemas/FinancekitConsent"
@@ -160,12 +160,12 @@
"account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"booked_balance": {
"$ref": "#/components/schemas/FinancekitMoney"
@@ -196,12 +196,12 @@
"source_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -231,7 +231,7 @@
{
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
],
"nullable": true
@@ -250,12 +250,12 @@
"source_account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -278,17 +278,17 @@
"id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"connection_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"publisher_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"status": {
"type": "string",
@@ -308,7 +308,7 @@
{
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
],
"nullable": true
@@ -378,6 +378,31 @@
},
"pagination": {
"$ref": "#/components/schemas/Pagination"
+ },
+ "purge_requested_at": {
+ "allOf": [
+ {
+ "type": "string",
+ "format": "date-time"
+ }
+ ],
+ "nullable": true
+ },
+ "purge_completed_at": {
+ "allOf": [
+ {
+ "type": "string",
+ "format": "date-time"
+ }
+ ],
+ "nullable": true
+ },
+ "disposition": {
+ "type": "string",
+ "enum": [
+ "retain",
+ "discard"
+ ]
}
}
},
@@ -454,12 +479,12 @@
"source_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -509,17 +534,17 @@
"source_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"source_account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -560,17 +585,17 @@
"source_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"source_account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -640,17 +665,17 @@
"source_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"source_account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -698,12 +723,12 @@
"source_account_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"lineage_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"mapping_version": {
"type": "integer",
@@ -800,12 +825,12 @@
"connection_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"publisher_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"generation": {
"type": "integer",
@@ -814,12 +839,12 @@
"stream_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"batch_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"sequence": {
"type": "integer",
@@ -832,7 +857,7 @@
"capture_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"chunk_index": {
"type": "integer",
@@ -865,7 +890,7 @@
"items": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
},
"events": {
@@ -898,12 +923,12 @@
"connection_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"publisher_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"generation": {
"type": "integer"
@@ -911,12 +936,12 @@
"stream_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"batch_id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"sequence": {
"type": "integer"
@@ -963,7 +988,7 @@
"id": {
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
},
"kind": {
"type": "string"
@@ -1000,7 +1025,7 @@
{
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
],
"nullable": true
@@ -1010,7 +1035,7 @@
{
"type": "string",
"format": "uuid",
- "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ "pattern": "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
}
],
"nullable": true
@@ -1047,7 +1072,8 @@
"max_queued_batches",
"transaction_statuses",
"amount_precision",
- "amount_scale"
+ "amount_scale",
+ "connection_dispositions"
],
"properties": {
"available": {
@@ -1091,6 +1117,16 @@
},
"amount_scale": {
"type": "integer"
+ },
+ "connection_dispositions": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "retain",
+ "discard"
+ ]
+ }
}
}
},
diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml
index df3bf8cc5e..c4ed338e81 100644
--- a/docs/api/openapi.yaml
+++ b/docs/api/openapi.yaml
@@ -3685,7 +3685,7 @@ components:
items:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
upload_authorized:
type: boolean
enum:
@@ -3713,11 +3713,11 @@ components:
enrollment_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
replaces_connection_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
consent:
"$ref": "#/components/schemas/FinancekitConsent"
FinancekitMappingRequest:
@@ -3761,11 +3761,11 @@ components:
account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
booked_balance:
"$ref": "#/components/schemas/FinancekitMoney"
observed_at:
@@ -3791,11 +3791,11 @@ components:
source_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -3816,7 +3816,7 @@ components:
allOf:
- type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
nullable: true
FinancekitAccountBinding:
type: object
@@ -3829,11 +3829,11 @@ components:
source_account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -3851,15 +3851,15 @@ components:
id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
connection_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
publisher_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
status:
type: string
enum:
@@ -3874,7 +3874,7 @@ components:
allOf:
- type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
nullable: true
next_sequence:
type: integer
@@ -3916,6 +3916,21 @@ components:
"$ref": "#/components/schemas/FinancekitAccountMapping"
pagination:
"$ref": "#/components/schemas/Pagination"
+ purge_requested_at:
+ allOf:
+ - type: string
+ format: date-time
+ nullable: true
+ purge_completed_at:
+ allOf:
+ - type: string
+ format: date-time
+ nullable: true
+ disposition:
+ type: string
+ enum:
+ - retain
+ - discard
FinancekitPublisherConfiguration:
allOf:
- "$ref": "#/components/schemas/FinancekitConnection"
@@ -3970,11 +3985,11 @@ components:
source_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -4012,15 +4027,15 @@ components:
source_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
source_account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -4052,15 +4067,15 @@ components:
source_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
source_account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -4113,15 +4128,15 @@ components:
source_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
source_account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -4154,11 +4169,11 @@ components:
source_account_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
lineage_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
mapping_version:
type: integer
minimum: 1
@@ -4225,22 +4240,22 @@ components:
connection_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
publisher_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
generation:
type: integer
minimum: 1
stream_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
batch_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
sequence:
type: integer
minimum: 1
@@ -4250,7 +4265,7 @@ components:
capture_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
chunk_index:
type: integer
minimum: 0
@@ -4276,7 +4291,7 @@ components:
items:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
events:
type: array
maxItems: 500
@@ -4304,21 +4319,21 @@ components:
connection_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
publisher_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
generation:
type: integer
stream_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
batch_id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
sequence:
type: integer
payload_digest:
@@ -4354,7 +4369,7 @@ components:
id:
type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
kind:
type: string
status:
@@ -4379,13 +4394,13 @@ components:
allOf:
- type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
nullable: true
financekit_transaction_id:
allOf:
- type: string
format: uuid
- pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
+ pattern: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
nullable: true
FinancekitConflictResolution:
type: object
@@ -4416,6 +4431,7 @@ components:
- transaction_statuses
- amount_precision
- amount_scale
+ - connection_dispositions
properties:
available:
type: boolean
@@ -4445,6 +4461,13 @@ components:
type: integer
amount_scale:
type: integer
+ connection_dispositions:
+ type: array
+ items:
+ type: string
+ enum:
+ - retain
+ - discard
FinancekitError:
type: object
additionalProperties: false
@@ -6084,16 +6107,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/connections":
post:
summary: Enroll a FinanceKit device publisher
@@ -6163,16 +6176,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
requestBody:
content:
application/json:
@@ -6263,27 +6266,39 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
delete:
- summary: Revoke a publisher and retain imported financial history
+ summary: Revoke a publisher, retaining or discarding imported financial history
tags:
- FinanceKit
security:
- apiKeyAuth: []
- oauth2:
- read_write
+ parameters:
+ - name: disposition
+ in: query
+ required: false
+ schema:
+ type: string
+ enum:
+ - retain
+ - discard
+ description: 'What happens to the data this connection imported. retain (the
+ default) keeps every account, balance and transaction. discard removes them:
+ accounts FinanceKit created are destroyed, accounts it was linked to are
+ emptied of FinanceKit-sourced entries and rebalanced, and source identities,
+ balance observations and conflicts are deleted. Irreversible, and it removes
+ imported entries the family later reconciled, excluded or edited. Supported
+ dispositions are advertised by GET /api/v1/financekit/capabilities.'
responses:
'204':
- description: Publisher revoked
+ description: Publisher revoked, imported history retained
+ '202':
+ description: Publisher revoked, discard of imported history accepted
+ content:
+ application/json:
+ schema:
+ "$ref": "#/components/schemas/FinancekitConnection"
'400':
description: Malformed or unsupported protocol
content:
@@ -6336,16 +6351,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/connections/{connection_id}/account_mappings/{source_id}":
parameters:
- name: connection_id
@@ -6428,16 +6433,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
requestBody:
content:
application/json:
@@ -6519,16 +6514,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/connections/{connection_id}/credential":
parameters:
- name: connection_id
@@ -6604,16 +6589,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/connections/{connection_id}/repair":
parameters:
- name: connection_id
@@ -6689,16 +6664,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/publishers/{publisher_id}/batches":
parameters:
- name: publisher_id
@@ -6917,16 +6882,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
"/api/v1/financekit/connections/{connection_id}/conflicts/{id}":
parameters:
- name: connection_id
@@ -7009,16 +6964,6 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/FinancekitError"
- '503':
- description: Feature unavailable
- headers:
- Retry-After:
- schema:
- type: integer
- content:
- application/json:
- schema:
- "$ref": "#/components/schemas/FinancekitError"
requestBody:
content:
application/json:
diff --git a/docs/hosting/financekit.md b/docs/hosting/financekit.md
index fe6bcb9232..6ebae66e34 100644
--- a/docs/hosting/financekit.md
+++ b/docs/hosting/financekit.md
@@ -4,24 +4,32 @@ This guide covers Sure's server-side ingestion of FinanceKit uploads. It applies
Sure's server-side worker and scheduled inbox sweep are required for either delivery mode. They apply accepted batches, retry processing, complete downstream account updates, and remove expired payload bytes. These server jobs are separate from the iOS app's ability to run in the background.
-FinanceKit is default-off and requires:
+FinanceKit needs no server-side configuration to switch on. There is no feature
+flag and no family allowlist: any deployment running this code serves the
+publisher endpoints. Whether a build offers Wallet sync at all is decided in the
+iOS client through StoreKit, which the server cannot observe and does not try to.
-- `FINANCEKIT_ENABLED=true`;
-- `FINANCEKIT_FAMILY_IDS`, a comma-separated exact family UUID allowlist;
-- an active enrolling family administrator with preview features enabled; and
+What it does require:
+
+- an active family administrator to enroll, because a publisher writes into
+ accounts the whole family reads. Every upload re-checks this, so a
+ deactivated, demoted or reassigned enroller stops publishing; and
- the scheduled `FinancekitInboxJob` sweep in addition to jobs enqueued when a batch arrives.
+Nothing beyond admin gates it. The mapped accounts are further confined to those
+the enrolling user may write, so an admin cannot publish into an account they
+have no access to.
+
No Apple Wallet entitlement, private key, or FinanceKit framework is installed on the server. Sure never receives the user's Apple credentials. The iOS app obtains Wallet authorization directly from Apple and uploads only the accounts the user selected and consented to share.
## Deployment
-Deploy the migration, application, worker, and scheduler with the feature flag disabled. The migration introduces publisher connections, stable account lineages, immutable batch receipts, source transaction identities, balance observations, and conflicts.
+Deploy the migration, application, worker, and scheduler. The migration introduces publisher connections, stable account lineages, immutable batch receipts, source transaction identities, balance observations, and conflicts. The endpoints are live as soon as the application is, so treat the deploy itself as the enablement step and run the checks below before announcing it.
After deploy:
1. Confirm the high-priority job queue and recurring scheduler are healthy.
-2. Enable only a disposable test family.
-3. Enroll and activate a synthetic publisher over HTTPS.
+2. Enroll and activate a synthetic publisher over HTTPS, using a disposable test family.
4. Upload sequences 2 then 1 and confirm the inbox applies them in order.
5. Retry identical bytes and confirm the receipt is stable and no ledger row duplicates.
6. Rotate the credential and confirm the prior credential cannot upload or call normal APIs.
@@ -53,6 +61,48 @@ iOS client can start a new enrollment with a new enrollment ID and map its Apple
source account IDs again; existing accounts and imported transactions are reused
without requiring the old connection or stream state.
+### Disconnect dispositions
+
+`DELETE /api/v1/financekit/connections/{id}` takes an optional `disposition`
+query parameter saying what happens to the data the connection imported. The
+dispositions a build supports are advertised as `connection_dispositions` in the
+capabilities response, so a client feature-detects rather than hardcoding.
+
+`retain` is the default and the behaviour above: the connection is revoked and
+every account, balance and transaction stays. The response is `204 No Content`,
+unchanged for clients that send no disposition. The web unlink flow always
+retains — a person unlinking one account has not consented to delete the data in
+the others the connection covered.
+
+`discard` revokes the connection and then removes what it imported. It answers
+`202 Accepted` with the connection payload: a year of card history is not deleted
+inside a request, so the work runs in the background and the client polls the
+connection until `purge_completed_at` is set. Per Wallet account:
+
+- An account FinanceKit created is destroyed, with everything on it.
+- An account FinanceKit was linked to is emptied of entries sourced from
+ FinanceKit and handed back to sync, which recomputes its balance from the
+ history the family had before FinanceKit arrived. The account itself stays.
+- Source identities, balance observations and conflicts for that lineage are
+ deleted, and the lineage is marked discarded so a later enrollment starts clean
+ rather than reusing it.
+
+Two consequences worth stating plainly. A discard removes imported entries even
+where the family later reconciled, excluded, split or edited them — a partial
+deletion would be worse than none, having told them the data was gone. And where
+an imported transaction had been matched into a transfer, the transfer record and
+its fees go with it; the transaction on the other account survives, unpaired.
+
+An account lineage that another live connection still publishes into is left
+entirely alone, which is what happens during a device replacement window when two
+connections reference one lineage. The connection row itself survives as a
+revoked receipt; it holds no financial values, and its batch payloads were
+dropped at revocation.
+
+Discard is irreversible, and the request outlives the job that carries it out:
+the intent is recorded on the connection, and the FinanceKit inbox sweep finishes
+any purge whose job was lost.
+
## Debugging uploads
Super admins can open `/settings/debug?provider_key=financekit` and filter further
@@ -107,11 +157,11 @@ Apple Cash top-ups come from the demo owner's manual Chase Premier Checking
account; if absent, a funded Wallet Demo Checking account is created. Subsequent
reruns preserve category edits and do not duplicate either transfer leg.
Wallet demo data is included in every environment by both the full generator
-and sample-data reset flow. It does not enable FinanceKit feature flags or change
-user permissions. These records simulate imported data; no iOS device is required.
+and sample-data reset flow. It does not change user permissions. These records
+simulate imported data; no iOS device is required.
## Capacity and retention
Protocol 2 limits each publisher to 20 selected accounts, 500 events per batch, 1 MiB of JSON, and 100 accepted/processing batches. Each capture is limited to 100 chunks so the complete capture fits in the inbox. A client can upload larger histories using multiple consecutive captures.
-Exact payload bytes are retained for seven days after apply, permanent failure, or revocation for response-loss recovery and operational investigation. Canonical financial data and source identity records follow Sure's normal family retention and deletion behavior. Family financial-data reset removes FinanceKit connections, lineages, observations, identities, conflicts, and batch receipts for that family.
+Exact payload bytes are retained for seven days after apply, permanent failure, or revocation for response-loss recovery and operational investigation. Canonical financial data and source identity records follow Sure's normal family retention and deletion behavior, except where a client disconnects with `disposition=discard` (see [Disconnect dispositions](#disconnect-dispositions)), which removes them for that connection. Family financial-data reset removes FinanceKit connections, lineages, observations, identities, conflicts, and batch receipts for that family.
diff --git a/lib/generators/provider/family/templates/item_model.rb.tt b/lib/generators/provider/family/templates/item_model.rb.tt
index dcc3b4d8cf..44f6ab2ec3 100644
--- a/lib/generators/provider/family/templates/item_model.rb.tt
+++ b/lib/generators/provider/family/templates/item_model.rb.tt
@@ -1,7 +1,14 @@
# frozen_string_literal: true
class <%= class_name %>Item < ApplicationRecord
- include Syncable, Provided, Unlinking, DestroyableLater
+ include Syncable, Provided, Unlinking, DestroyableLater, ProviderDisconnectable
+
+ # Set to true once this provider implements removal of the data it imported, so
+ # a client may disconnect with disposition "discard". Left false until then:
+ # the capability is advertised to API clients, and claiming it without the
+ # implementation would tell a family their data was deleted when it was not.
+ # See Unlinking#unlink_all! and Financekit::Purge for the worked example.
+ self.supports_discard = false
enum :status, { good: "good", requires_update: "requires_update" }, default: :good
diff --git a/lib/generators/provider/family/templates/unlinking_concern.rb.tt b/lib/generators/provider/family/templates/unlinking_concern.rb.tt
index d2c3bb1c73..9c127627ed 100644
--- a/lib/generators/provider/family/templates/unlinking_concern.rb.tt
+++ b/lib/generators/provider/family/templates/unlinking_concern.rb.tt
@@ -8,7 +8,32 @@ module <%= class_name %>Item::Unlinking
# - Detaches any AccountProvider links for each <%= class_name %>Account
# - Detaches Holdings that point at the AccountProvider links
# Returns a per-account result payload for observability
- def unlink_all!(dry_run: false)
+ #
+ # `disposition` says what happens to the data this provider imported. The
+ # vocabulary lives in ProviderDisconnectable:
+ #
+ # retain -- keep every account, balance and transaction. The default, and
+ # what unlinking has always meant: the data describes the family's
+ # money, not the connection that fetched it.
+ # discard -- also remove what this provider imported. Destructive and
+ # irreversible, so it is only accepted from a provider that has
+ # declared `self.supports_discard = true` on its item model and
+ # implemented the removal.
+ #
+ # This scaffold implements retain only. To add discard, declare the capability
+ # on <%= class_name %>Item, implement the removal, and call it from the branch
+ # below. Financekit::Purge is the worked example: it decides per account whether
+ # the provider created it (destroy it) or was linked to one the family already
+ # had (empty it and let sync recompute the balance), skips accounts another live
+ # connection still writes, and runs in a background job because deleting a
+ # year of history is not request-sized work.
+ def unlink_all!(dry_run: false, disposition: ProviderDisconnectable::DEFAULT_DISPOSITION)
+ # Rejected rather than ignored: silently retaining data after being asked to
+ # delete it is the one failure here that would matter to a family.
+ unless disposition.to_s == ProviderDisconnectable::RETAIN
+ raise ArgumentError, "<%= class_name %>Item does not implement the #{disposition} disposition"
+ end
+
results = []
<%= file_name %>_accounts.find_each do |provider_account|
diff --git a/spec/requests/api/v1/financekit_spec.rb b/spec/requests/api/v1/financekit_spec.rb
index bd8ffaadad..5cc810bce8 100644
--- a/spec/requests/api/v1/financekit_spec.rb
+++ b/spec/requests/api/v1/financekit_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe "Api::V1::Financekit", type: :request do
end
let(:user) do
family.users.create!(email: "financekit-api-#{SecureRandom.hex(8)}@example.com", password: "password123",
- password_confirmation: "password123", role: "admin", preferences: { "preview_features_enabled" => true })
+ password_confirmation: "password123", role: "admin")
end
let(:api_key) do
key = ApiKey.generate_secure_key
@@ -77,11 +77,6 @@ RSpec.describe "Api::V1::Financekit", type: :request do
header "Retry-After", schema: { type: :integer }
run_test! skip: "Documentation only; behavior covered by Minitest"
end
- response "503", "Feature unavailable" do
- schema "$ref" => "#/components/schemas/FinancekitError"
- header "Retry-After", schema: { type: :integer }
- run_test! skip: "Documentation only; behavior covered by Minitest"
- end
end
path "/api/v1/financekit/capabilities" do
@@ -127,13 +122,29 @@ RSpec.describe "Api::V1::Financekit", type: :request do
end
include_examples "financekit normal API errors"
end
- delete "Revoke a publisher and retain imported financial history" do
+ delete "Revoke a publisher, retaining or discarding imported financial history" do
tags "FinanceKit"
produces "application/json"
security FINANCEKIT_WRITE_SECURITY
- response "204", "Publisher revoked" do
+ parameter name: :disposition, in: :query, required: false,
+ schema: { type: :string, enum: %w[retain discard] },
+ description: "What happens to the data this connection imported. " \
+ "retain (the default) keeps every account, balance and transaction. " \
+ "discard removes them: accounts FinanceKit created are destroyed, accounts it was " \
+ "linked to are emptied of FinanceKit-sourced entries and rebalanced, and source " \
+ "identities, balance observations and conflicts are deleted. Irreversible, and it " \
+ "removes imported entries the family later reconciled, excluded or edited. " \
+ "Supported dispositions are advertised by GET /api/v1/financekit/capabilities."
+ response "204", "Publisher revoked, imported history retained" do
run_test!
end
+ response "202", "Publisher revoked, discard of imported history accepted" do
+ let(:disposition) { "discard" }
+ schema "$ref" => "#/components/schemas/FinancekitConnection"
+ # Accepted, not completed: the deletion runs in the background. Poll the
+ # connection and wait for purge_completed_at.
+ run_test! skip: "Documentation only; behavior covered by Minitest"
+ end
include_examples "financekit normal API errors"
end
end
diff --git a/test/controllers/api/v1/financekit/connections_controller_test.rb b/test/controllers/api/v1/financekit/connections_controller_test.rb
index a7e05376b1..8a26089766 100644
--- a/test/controllers/api/v1/financekit/connections_controller_test.rb
+++ b/test/controllers/api/v1/financekit/connections_controller_test.rb
@@ -197,8 +197,9 @@ class Api::V1::Financekit::ConnectionsControllerTest < ActionDispatch::Integrati
end
test "non-admin and foreign-family access is rejected" do
+ # Admin is the only thing standing between a family member and the publisher
+ # endpoints now, so this is the whole access check rather than one of three.
member = users(:family_member)
- member.update!(preferences: member.preferences.merge("preview_features_enabled" => true))
key = ApiKey.create!(user: member, name: "FinanceKit member test", scopes: [ "read_write" ],
display_key: "test_#{SecureRandom.hex(16)}", source: "web")
@@ -206,11 +207,88 @@ class Api::V1::Financekit::ConnectionsControllerTest < ActionDispatch::Integrati
assert_response :forbidden
assert_equal "publisher_forbidden", response.parsed_body.fetch("error")
+ # Another family's admin clears the access check, since admin is all it asks,
+ # and is stopped by tenancy instead: the connection scope is the caller's own
+ # family and own user, so the row is simply not there. That is 404 rather
+ # than the 403 the preview gate used to produce, which is the better answer —
+ # it does not confirm to an outsider that the id exists.
other = users(:empty)
+ assert other.admin?
+ assert_not_equal @family.id, other.family_id
other_key = ApiKey.create!(user: other, name: "FinanceKit other test", scopes: [ "read" ],
display_key: "test_#{SecureRandom.hex(16)}", source: "web")
get "/api/v1/financekit/connections/#{@item.id}", headers: { "X-Api-Key" => other_key.display_key }
- assert_response :forbidden
+ assert_response :not_found
+ end
+
+ test "disconnecting retains imported history unless the client asks otherwise" do
+ accept_and_apply
+ account = @source.account
+
+ delete "/api/v1/financekit/connections/#{@item.id}", headers: @headers
+ assert_response :no_content
+
+ # The response a client already gets, and the behaviour the published spec
+ # promises: the connection goes, the money stays.
+ assert_equal "revoked", @item.reload.status
+ assert_nil @item.purge_requested_at
+ assert_equal 1, account.entries.where(source: "financekit").count
+ assert_empty enqueued_jobs.select { |job| job[:job] == FinancekitPurgeJob }
+ end
+
+ test "disconnecting with discard is accepted and hands the deletion to a job" do
+ accept_and_apply
+
+ # Query string, which is what the published spec documents: a DELETE body is
+ # not carried reliably by every HTTP client.
+ delete "/api/v1/financekit/connections/#{@item.id}?disposition=discard", headers: @headers
+
+ # Accepted rather than completed: a year of history is not deleted inside a
+ # request, so the client polls the connection for purge_completed_at.
+ assert_response :accepted
+ assert_equal "discard", response.parsed_body.fetch("disposition")
+ assert_equal "revoked", response.parsed_body.fetch("status")
+ assert_not_nil response.parsed_body.fetch("purge_requested_at")
+ assert_nil response.parsed_body.fetch("purge_completed_at")
+ assert_equal 1, enqueued_jobs.count { |job| job[:job] == FinancekitPurgeJob }
+ end
+
+ test "an unknown disposition is refused without revoking the connection" do
+ delete "/api/v1/financekit/connections/#{@item.id}?disposition=shred", headers: @headers
+
+ assert_response :unprocessable_entity
+ assert_equal "invalid_disposition", response.parsed_body.fetch("error")
+ assert_equal "active", @item.reload.status
+ end
+
+ test "an admin needs no server configuration or preview opt-in to publish" do
+ # There is no FINANCEKIT_ENABLED flag, no family allowlist and no preview
+ # toggle any more: whether a build offers Wallet sync is decided in the iOS
+ # client through StoreKit, which the server cannot see. The test helper grants
+ # neither, so the rest of this suite exercises the same thing implicitly.
+ assert_not @user.preview_features_enabled?
+ assert @user.admin?
+
+ get "/api/v1/financekit/capabilities", headers: @headers
+ assert_response :success
+ assert_equal true, response.parsed_body.fetch("available")
+
+ post "/api/v1/financekit/connections", params: @enrollment, headers: @headers, as: :json
+ assert_response :success
+
+ # And the publisher credential still works, so require_publisher! is not
+ # gating on anything either.
+ batch, = accept_batch
+ assert_equal "accepted", batch.status
+ end
+
+ test "capabilities advertise the dispositions this build supports" do
+ get "/api/v1/financekit/capabilities", headers: @headers
+
+ assert_response :success
+ # Feature-detected rather than hardcoded, so a client keeps working when a
+ # provider gains discard or a build withholds it.
+ assert_equal %w[retain discard], response.parsed_body.fetch("connection_dispositions")
end
private
diff --git a/test/controllers/financekit_accounts_test.rb b/test/controllers/financekit_accounts_test.rb
index ca7b008fa0..ed06c3d678 100644
--- a/test/controllers/financekit_accounts_test.rb
+++ b/test/controllers/financekit_accounts_test.rb
@@ -103,13 +103,12 @@ class FinancekitAccountsTest < ActionDispatch::IntegrationTest
assert account.entries.exists?(name: "New purchase after reconnect")
end
- test "unlink disconnects all accounts sharing the publisher even when FinanceKit is unavailable" do
+ test "unlink disconnects all accounts sharing the publisher even when it needs repair" do
second_source = SecureRandom.uuid
@item.update!(status: "repair_required", consent: @item.consent.merge(
"selected_source_account_ids" => [ @source_id, second_source ]))
second_mapping = FinancekitAccount.map!(@item, second_source, @mapping_input.merge("name" => "Apple Cash"))
@item.activate!
- Financekit.stubs(:enabled?).returns(false)
@item.mark_repair!("test_failure")
delete unlink_account_url(@source.account)
diff --git a/test/lib/generators/provider/family_generator_test.rb b/test/lib/generators/provider/family_generator_test.rb
index 0619bf15da..4abd5227f8 100644
--- a/test/lib/generators/provider/family_generator_test.rb
+++ b/test/lib/generators/provider/family_generator_test.rb
@@ -16,6 +16,18 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCase
flunk "generated invalid Ruby: #{e.message}\n\n#{source}"
end
+ test "the unlinking scaffold renders to valid Ruby and carries the disposition seam" do
+ template = Rails.root.join("lib/generators/provider/family/templates/unlinking_concern.rb.tt").read
+ context = Struct.new(:class_name, :file_name).new("Gocardless", "gocardless")
+ rendered = ERB.new(template, trim_mode: "-").result(context.instance_eval { binding })
+
+ assert_parses rendered
+ # A generated provider retains by default and refuses a discard it has not
+ # implemented, rather than accepting one and keeping the data.
+ assert_includes rendered, "disposition: ProviderDisconnectable::DEFAULT_DISPOSITION"
+ assert_includes rendered, "does not implement the #{'#{disposition}'} disposition"
+ end
+
test "appends to a single-line enum" do
result = append(<<~RUBY)
class ProviderMerchant < Merchant
diff --git a/test/models/demo/financekit_generator_test.rb b/test/models/demo/financekit_generator_test.rb
index 3eadc9fd44..2989f2f877 100644
--- a/test/models/demo/financekit_generator_test.rb
+++ b/test/models/demo/financekit_generator_test.rb
@@ -33,14 +33,12 @@ class Demo::FinancekitGeneratorTest < ActiveSupport::TestCase
test "seeds linked Apple Card and Apple Cash with source identities and realistic activity" do
family = families(:dylan_family)
- flags_before = ENV.values_at("FINANCEKIT_ENABLED", "FINANCEKIT_FAMILY_IDS")
item = Demo::FinancekitGenerator.new(family).generate!
assert_equal "active", item.status
assert_equal 3, item.accounts.count
assert item.last_accepted_at
assert item.last_imported_at
- assert_equal flags_before, ENV.values_at("FINANCEKIT_ENABLED", "FINANCEKIT_FAMILY_IDS")
card = item.accounts.find_by!(name: "Apple Card")
cash = item.accounts.find_by!(name: "Apple Cash")
diff --git a/test/models/financekit/diagnostics_test.rb b/test/models/financekit/diagnostics_test.rb
index efed582712..94656fef09 100644
--- a/test/models/financekit/diagnostics_test.rb
+++ b/test/models/financekit/diagnostics_test.rb
@@ -15,11 +15,18 @@ class Financekit::DiagnosticsTest < ActiveSupport::TestCase
assert_equal @item.id, accepted.metadata["connection_id"]
assert_equal 3, accepted.metadata["event_count"]
- assert Financekit::Processor.new(@item).apply_next!
+ applied = Financekit::Processor.new(@item).apply_next!
+ assert applied
imported = log_for("capture_imported")
assert_equal batch.batch_id, imported.metadata["batch_id"]
assert_equal 1, imported.metadata.dig("counts", "upserted")
- assert log_for("downstream_completed")
+
+ # Downstream work is the drain's, not the processor's, so it completes the
+ # whole applied capture in one pass.
+ Financekit::Downstream.new(@item, FinancekitBatch.where(id: applied.map(&:id))).perform!
+ completed = log_for("downstream_completed")
+ assert_equal applied.size, completed.metadata["batches"]
+ assert_equal batch.batch_id, completed.metadata["batch_id"]
assert_private_fields_absent
end
@@ -69,7 +76,7 @@ class Financekit::DiagnosticsTest < ActiveSupport::TestCase
batch, = accept_batch
Account.any_instance.stubs(:sync_later).raises(RuntimeError, "private-financial-details")
- Financekit::Downstream.new(batch).perform!
+ Financekit::Downstream.new(@item, FinancekitBatch.where(id: batch.id)).perform!
log = log_for("downstream_failed")
assert_equal @source.financekit_account_lineage.account_provider, log.account_provider
diff --git a/test/models/financekit/disconnect_test.rb b/test/models/financekit/disconnect_test.rb
new file mode 100644
index 0000000000..2363aedb52
--- /dev/null
+++ b/test/models/financekit/disconnect_test.rb
@@ -0,0 +1,201 @@
+require "test_helper"
+require_relative "../../support/financekit_test_helper"
+
+class Financekit::DisconnectTest < ActiveSupport::TestCase
+ include FinancekitTestHelper
+ include ActiveJob::TestHelper
+
+ setup { financekit_setup }
+
+ test "a retain disconnect revokes the connection and keeps everything it imported" do
+ accept_and_apply
+ account = @source.account
+
+ @item.disconnect!
+
+ assert_equal "revoked", @item.reload.status
+ assert_nil @item.purge_requested_at
+ assert Account.exists?(account.id)
+ assert_equal 1, account.entries.where(source: "financekit").count
+ assert_equal 1, @source.financekit_transactions.count
+ assert_equal 1, @source.financekit_balance_observations.count
+ assert_not @source.financekit_account_lineage.reload.discarded?
+ end
+
+ test "a discard records the request and hands the deletion to a job" do
+ accept_and_apply
+
+ assert_enqueued_with(job: FinancekitPurgeJob) { @item.disconnect!(disposition: "discard") }
+
+ # Accepted, not done: the marker is what makes the request survive a lost job.
+ assert_not_nil @item.reload.purge_requested_at
+ assert_nil @item.purge_completed_at
+ assert @item.purge_pending?
+ end
+
+ test "a discard destroys an account FinanceKit created" do
+ accept_and_apply
+ account = @source.account
+ lineage = @source.financekit_account_lineage
+ assert_equal "created", lineage.account_origin
+
+ discard!
+
+ assert_not Account.exists?(account.id)
+ # A destroyed account has no balance to recompute.
+ assert_empty FinancekitTransaction.where(financekit_account_lineage: lineage)
+ assert_empty FinancekitBalanceObservation.where(financekit_account_lineage: lineage)
+ assert lineage.reload.discarded?
+ # Nulled so a later enrollment cannot resurrect a link to an account this
+ # lineage no longer describes.
+ assert_nil lineage.account_id
+ assert_not_nil @item.reload.purge_completed_at
+ end
+
+ test "a discard empties an account the family already had and leaves it standing" do
+ accept_and_apply
+ account = @source.account
+ manual = account.entries.create!(name: "Rent", amount: "1200.00", currency: "USD",
+ date: Date.new(2026, 9, 1), entryable: Transaction.new)
+ link_lineage!
+
+ discard!
+
+ assert Account.exists?(account.id)
+ assert_equal [ manual.id ], account.entries.reload.pluck(:id)
+ assert @source.financekit_account_lineage.reload.discarded?
+ end
+
+ test "a discard hands an emptied account back to sync so its balance matches what remains" do
+ accept_and_apply
+ link_lineage!
+ # Asserted on the call rather than on an enqueue: sync_later reuses a visible
+ # sync, and the import that just ran already created one.
+ Account.any_instance.expects(:sync_later).at_least_once
+
+ discard!
+ end
+
+ test "a discard removes imported entries the family reconciled or edited" do
+ accept_and_apply
+ entry = @source.account.entries.sole
+ entry.mark_reconciled!
+ entry.mark_user_modified!
+ link_lineage!
+
+ discard!
+
+ # The import is being undone at the family's request, so the rules that stop
+ # a *sync* from overwriting their work do not apply here.
+ assert_not Entry.exists?(entry.id)
+ end
+
+ test "a discard takes a split parent's children with it" do
+ accept_and_apply
+ entry = @source.account.entries.sole
+ children = entry.split!([ { name: "Half", amount: entry.amount / 2 },
+ { name: "Other half", amount: entry.amount / 2 } ])
+ link_lineage!
+
+ discard!
+
+ assert_not Entry.exists?(entry.id)
+ # Entry refuses to destroy a child on its own, so the children can only go
+ # with the parent -- through the association or the parent_entry_id cascade.
+ # Pinned because a purge that spared the parent would strand them.
+ assert_empty Entry.where(id: children.map(&:id))
+ end
+
+ test "a discard unlinks a transfer but keeps the account on the other side" do
+ accept_and_apply
+ entry = @source.account.entries.sole
+ other_account = @family.accounts.create!(name: "Transfer destination", balance: 0, currency: "USD",
+ accountable: Depository.new(subtype: "checking"))
+ other = other_account.entries.create!(name: "Transfer in", amount: -entry.amount, currency: entry.currency,
+ date: entry.date, entryable: Transaction.new)
+ transfer = Transfer.create!(inflow_transaction: other.transaction, outflow_transaction: entry.transaction)
+ link_lineage!
+
+ discard!
+
+ assert_not Transfer.exists?(transfer.id)
+ # The counterpart is the other account's own entry. It loses the pairing, not
+ # its existence.
+ assert Entry.exists?(other.id)
+ assert_nil other.transaction.reload.transfer
+ end
+
+ test "a discard leaves a lineage another live connection still publishes into" do
+ accept_and_apply
+ account = @source.account
+ lineage = @source.financekit_account_lineage
+ replacement = replacement_connection!
+
+ @item.disconnect!(disposition: "discard")
+ counts = Financekit::Purge.new(@item).perform!
+
+ # A replacement device shares the lineage for as long as both connections
+ # exist. Discarding the old one must not delete the new one's live account.
+ assert_equal "active", replacement.reload.status
+ assert Account.exists?(account.id)
+ assert_equal 1, account.entries.where(source: "financekit").count
+ assert_not lineage.reload.discarded?
+ assert_equal 1, counts["lineages_skipped"]
+ end
+
+ test "the sweep finishes a discard whose job never ran" do
+ accept_and_apply
+ account = @source.account
+ @item.disconnect!(disposition: "discard")
+ assert @item.reload.purge_pending?
+
+ # Stands in for an enqueue that failed or a worker that died holding the job.
+ FinancekitInboxJob.perform_now
+
+ assert_not Account.exists?(account.id)
+ assert_not_nil @item.reload.purge_completed_at
+ end
+
+ test "a provider that has not declared discard offers only retain" do
+ unconverted = Class.new { include ProviderDisconnectable }
+
+ assert_equal %w[retain discard], FinancekitItem.supported_dispositions
+ assert_equal %w[retain], unconverted.supported_dispositions
+ # Rejected rather than quietly downgraded to retain: telling a family their
+ # data was deleted when it was not is the failure that matters here.
+ assert_raises(ArgumentError) { unconverted.new.disposition!("discard") }
+ assert_equal "retain", unconverted.new.disposition!(nil)
+ end
+
+ test "an unknown disposition is refused" do
+ assert_raises(ArgumentError) { @item.disconnect!(disposition: "shred") }
+ # Refused before anything is revoked, so a typo cannot cost a connection.
+ assert_equal "active", @item.reload.status
+ end
+
+ private
+
+ def discard!(item = @item)
+ item.disconnect!(disposition: "discard")
+ Financekit::Purge.new(item).perform!
+ end
+
+ # The helper's mapping uses action "create". Flipping the origin is how these
+ # tests cover the linked case without rebuilding the whole enrollment: what
+ # the mapping writes is covered in mapping_test.
+ def link_lineage!
+ @source.financekit_account_lineage.update!(account_origin: "linked")
+ end
+
+ def replacement_connection!
+ enrollment = @enrollment.deep_dup
+ enrollment["enrollment_id"] = SecureRandom.uuid
+ enrollment["replaces_connection_id"] = @item.id
+ replacement = Financekit::Enrollment.create!(@user, enrollment).item
+ FinancekitAccount.map!(replacement, @source_id,
+ @mapping_input.except("booked_balance", "observed_at").merge("action" => "link",
+ "account_id" => @source.account.id, "lineage_id" => @source.financekit_account_lineage_id))
+ replacement.activate!
+ replacement
+ end
+end
diff --git a/test/models/financekit/inbox_test.rb b/test/models/financekit/inbox_test.rb
index e25c1e892d..2b5077e0cc 100644
--- a/test/models/financekit/inbox_test.rb
+++ b/test/models/financekit/inbox_test.rb
@@ -189,6 +189,124 @@ class Financekit::InboxTest < ActiveSupport::TestCase
assert_nil @item.credential_digest
end
+ test "draining a backlog fans downstream work out once, not once per capture" do
+ first, first_raw = accept_batch
+ second, = accept_batch(financekit_payload(sequence: 2,
+ predecessor_digest: Digest::SHA256.hexdigest(first_raw), events: []))
+
+ # Two captures, one fan-out: transfer matching scans the whole family and
+ # costs the same whether one capture or fifty just landed.
+ Family.any_instance.expects(:auto_match_transfers!).once.returns(nil)
+
+ FinancekitInboxJob.perform_now(@item.id)
+
+ assert_equal "applied", first.reload.status
+ assert_equal "applied", second.reload.status
+ assert_not_nil first.downstream_completed_at
+ assert_not_nil second.downstream_completed_at
+ assert_not_nil @item.reload.last_downstream_at
+ end
+
+ test "a multi-chunk capture fans downstream work out once, not once per chunk" do
+ capture_id = SecureRandom.uuid
+ first_payload = financekit_payload(events: [])
+ first_payload.merge!("capture_id" => capture_id, "chunk_index" => 0, "chunk_count" => 2)
+ first, first_raw = accept_batch(first_payload)
+ second_payload = financekit_payload(sequence: 2, predecessor_digest: Digest::SHA256.hexdigest(first_raw),
+ events: [])
+ second_payload.merge!("capture_id" => capture_id, "chunk_index" => 1, "chunk_count" => 2)
+ second, = accept_batch(second_payload)
+
+ # Completing only the last chunk left the earlier ones for the recovery
+ # sweep, which then repeated the whole fan-out inside the same job run.
+ Family.any_instance.expects(:auto_match_transfers!).once.returns(nil)
+
+ FinancekitInboxJob.perform_now(@item.id)
+
+ assert_not_nil first.reload.downstream_completed_at
+ assert_not_nil second.reload.downstream_completed_at
+ end
+
+ test "overlapping downstream workers fan out once" do
+ batch, = accept_batch
+ assert Financekit::Processor.new(@item).apply_next!.present?
+ # Both snapshot the same incomplete ids before either performs, which is how
+ # a per-upload job and the periodic sweep overlap in production.
+ first = Financekit::Downstream.new(@item, FinancekitBatch.where(id: batch.id))
+ second = Financekit::Downstream.new(@item, FinancekitBatch.where(id: batch.id))
+ Family.any_instance.expects(:auto_match_transfers!).once.returns(nil)
+
+ first.perform!
+ second.perform!
+
+ assert_not_nil batch.reload.downstream_completed_at
+ end
+
+ test "a failure writing publisher health leaves the batches for recovery" do
+ batch, = accept_batch
+ assert Financekit::Processor.new(@item).apply_next!.present?
+ FinancekitItem.any_instance.stubs(:update!).raises(ActiveRecord::StatementInvalid.new("health write failed"))
+
+ enqueued_before = enqueued_jobs.size
+ Financekit::Downstream.new(@item, FinancekitBatch.where(id: batch.id)).perform!
+
+ # Completing the batch without the health write would hide it from the
+ # recovery sweep, which only looks for incomplete batches. Rolling it back
+ # has to take the scheduling with it, or recovery redoes work already
+ # queued and RuleJob records a second RuleRun for the same capture.
+ assert_nil batch.reload.downstream_completed_at
+ assert_nil FinancekitItem.find(@item.id).last_downstream_at
+ assert_equal enqueued_before, enqueued_jobs.size,
+ "rolled-back downstream work must not leave jobs queued"
+ end
+
+ test "the sweep recovers a backlog without materializing batch rows" do
+ first = accept_and_apply
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: []))
+ FinancekitBatch.where(id: [ first.id, second.id ]).update_all(downstream_completed_at: nil)
+
+ # A pending batch still carries its payload bytes, so the recovery sweep
+ # must work from ids: loading the rows puts the whole backlog in memory.
+ loaded = 0
+ counter = ->(_name, _start, _finish, _id, payload) do
+ loaded += payload[:record_count].to_i if payload[:class_name] == "FinancekitBatch"
+ end
+ ActiveSupport::Notifications.subscribed(counter, "instantiation.active_record") do
+ FinancekitInboxJob.perform_now
+ end
+
+ assert_equal 0, loaded, "recovery sweep materialized #{loaded} FinancekitBatch rows"
+ assert_not_nil first.reload.downstream_completed_at
+ assert_not_nil second.reload.downstream_completed_at
+ end
+
+ test "the sweep recovers a bounded backlog in the publisher's own order" do
+ first = accept_and_apply
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: []))
+ FinancekitBatch.where(id: [ first.id, second.id ]).update_all(downstream_completed_at: nil)
+
+ # One batch per pass, so the pass has to choose. Without an order Postgres
+ # may return either, and the choice decides which capture waits for the
+ # next sweep.
+ stub_const(Financekit, :MAX_QUEUED, 1) { FinancekitInboxJob.perform_now }
+
+ assert_not_nil first.reload.downstream_completed_at
+ assert_nil second.reload.downstream_completed_at
+ end
+
+ test "the sweep recovers applied batches whose downstream work was lost" do
+ batch = accept_and_apply
+ batch.update_columns(downstream_completed_at: nil)
+ @item.update_columns(last_downstream_at: nil)
+
+ FinancekitInboxJob.perform_now
+
+ assert_not_nil batch.reload.downstream_completed_at
+ assert_not_nil @item.reload.last_downstream_at
+ end
+
test "payload bytes are removed after the bounded replay window" do
batch = accept_and_apply
batch.update_columns(updated_at: 8.days.ago)
diff --git a/test/models/financekit/lifecycle_test.rb b/test/models/financekit/lifecycle_test.rb
index 2b9a09e76c..cdc86c0e43 100644
--- a/test/models/financekit/lifecycle_test.rb
+++ b/test/models/financekit/lifecycle_test.rb
@@ -36,7 +36,6 @@ class Financekit::LifecycleTest < ActiveSupport::TestCase
test "family reset removes publisher source records without touching another family" do
Provider::Plaid.any_instance.stubs(:remove_item)
other = users(:empty)
- other.update!(preferences: other.preferences.merge("preview_features_enabled" => true))
source_id = SecureRandom.uuid
enrollment = @enrollment.deep_dup
enrollment["enrollment_id"] = SecureRandom.uuid
diff --git a/test/models/financekit/mapping_test.rb b/test/models/financekit/mapping_test.rb
index 962c138b52..e800bc46c4 100644
--- a/test/models/financekit/mapping_test.rb
+++ b/test/models/financekit/mapping_test.rb
@@ -222,14 +222,240 @@ class Financekit::MappingTest < ActiveSupport::TestCase
first = accept_and_apply
event = financekit_events.find { |record| record["kind"] == "balance_upsert" }
event["balance"]["money"] = money("999.00", "credit")
- second, = accept_batch(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest, events: [ event ]))
- assert_not Financekit::Processor.new(@item).apply_next!
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ event ]))
- assert_equal "balance_observation_conflict", second.reload.error_code
- assert_equal "failed", second.status
+ # The stored observation is immutable and the canonical balance is untouched,
+ # but the disagreement is a conflict for the family, not a protocol failure:
+ # fencing here would clear a credential only a foreground repair can reissue.
+ assert_equal "applied", second.status
+ assert_equal 1, second.counts.fetch("review_required")
assert_equal BigDecimal("112.66"), @source.account.reload.balance
assert_equal BigDecimal("112.66"), @source.financekit_balance_observations.sole.amount
+ conflict = @item.financekit_conflicts.sole
+ assert_equal "balance_observation_conflict", conflict.kind
+ assert_equal @balance_id, conflict.details.fetch("source_id")
+ assert_equal "active", @item.reload.status
+ assert @item.authenticate_credential?(@credential)
+ end
+
+ test "a repeated balance disagreement does not pile up open conflicts" do
+ first = accept_and_apply
+ event = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ event["balance"]["money"] = money("999.00", "credit")
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ event ]))
+ accept_and_apply(financekit_payload(sequence: 3, predecessor_digest: second.payload_digest,
+ events: [ event ]))
+
+ assert_equal 1, @item.financekit_conflicts.open.count
+ assert_equal "active", @item.reload.status
+ end
+
+ test "a balance decision the family keeps is not reopened by an identical replay" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+ @item.financekit_conflicts.open.sole.resolve!(user: @user, resolution: "keep_sure")
+
+ third = accept_and_apply(financekit_payload(sequence: 3, predecessor_digest: second.payload_digest,
+ events: [ disagreement ]))
+
+ assert_empty @item.financekit_conflicts.open
+ assert_equal 1, @item.financekit_conflicts.count
+ assert_equal 1, third.counts.fetch("settled")
+ assert_equal BigDecimal("112.66"), @source.account.reload.balance
+ end
+
+ test "a balance decision survives replacing the publishing device" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+ @item.financekit_conflicts.open.sole.resolve!(user: @user, resolution: "keep_sure")
+ account = @source.account
+ lineage = @source.financekit_account_lineage
+
+ enrollment = @enrollment.deep_dup
+ enrollment["enrollment_id"] = SecureRandom.uuid
+ enrollment["replaces_connection_id"] = @item.id
+ replacement = Financekit::Enrollment.create!(@user, enrollment).item
+ @source = FinancekitAccount.map!(replacement, @source_id,
+ @mapping_input.except("booked_balance", "observed_at").merge(
+ "action" => "link", "account_id" => account.id, "lineage_id" => lineage.id))
+ replacement.activate!
+
+ # Rebuilt so it carries the replacement's mapping_version; the observation
+ # identity is unchanged because the clock is frozen. The observation lives
+ # on the lineage and outlives the publisher, so the decision must too.
+ replayed = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ replayed["balance"]["money"] = money("999.00", "credit")
+ batch = accept_and_apply(financekit_payload(item: replacement, events: [ replayed ]),
+ item: replacement)
+
+ assert_empty FinancekitConflict.where(family: @family).open
+ assert_equal 1, batch.counts.fetch("settled")
+ end
+
+ test "the lineage records whether FinanceKit created the canonical account" do
+ assert_equal "created", @source.financekit_account_lineage.account_origin
+
+ account = @family.accounts.create!(name: "Everyday", balance: 0, currency: "USD",
+ accountable: Depository.new(subtype: "checking"))
+ enrollment = @enrollment.deep_dup
+ enrollment["enrollment_id"] = SecureRandom.uuid
+ other_source_id = SecureRandom.uuid
+ enrollment["consent"]["selected_source_account_ids"] = [ other_source_id ]
+ other_item = Financekit::Enrollment.create!(@user, enrollment).item
+ linked = FinancekitAccount.map!(other_item, other_source_id,
+ @mapping_input.except("booked_balance", "observed_at").merge("action" => "link",
+ "account_id" => account.id))
+
+ # Only an account FinanceKit brought into existence is FinanceKit's to destroy
+ # when a family disconnects and asks for the import to be undone.
+ assert_equal "linked", linked.financekit_account_lineage.account_origin
+ end
+
+ test "one lineage keeps one open balance question when two publishers race" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+ raised = @item.financekit_conflicts.open.sole
+
+ # A replacement device keeps the lineage of the device it replaces, so both
+ # connections can look for an open question, find none, and then both
+ # insert. Checking first cannot settle that; the index has to.
+ enrollment = @enrollment.deep_dup
+ enrollment["enrollment_id"] = SecureRandom.uuid
+ enrollment["replaces_connection_id"] = @item.id
+ replacement = Financekit::Enrollment.create!(@user, enrollment).item
+
+ assert_raises(ActiveRecord::RecordNotUnique) do
+ replacement.financekit_conflicts.create!(family: @family,
+ financekit_account_lineage: raised.financekit_account_lineage,
+ kind: "balance_observation_conflict", status: "open", details: raised.details)
+ end
+ assert_equal 1, FinancekitConflict.where(family: @family).open.count
+ end
+
+ test "losing the race for a balance question still applies the rest of the capture" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ # Stands in for the other publisher inserting between the check and this
+ # insert: the question is open either way, so the import carries on rather
+ # than failing the batch and spending an attempt.
+ FinancekitConflict.any_instance.stubs(:save!).raises(ActiveRecord::RecordNotUnique.new("duplicate key"))
+
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+
+ assert_equal "applied", second.status
+ assert_equal 1, second.counts.fetch("review_required")
+ assert_equal "active", @item.reload.status
+ assert_equal BigDecimal("112.66"), @source.account.reload.balance
+ end
+
+ test "a balance decision matches an equivalent timestamp in another format" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ disagreement["balance"]["observed_at"] = "2026-09-10T12:00:00Z"
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+ @item.financekit_conflicts.open.sole.resolve!(user: @user, resolution: "keep_sure")
+
+ # Same instant, different spelling: it resolves to one stored observation,
+ # so it has to resolve to one decision.
+ reformatted = disagreement.deep_dup
+ reformatted["balance"]["observed_at"] = "2026-09-10T12:00:00.000Z"
+ accept_and_apply(financekit_payload(sequence: 3, predecessor_digest: second.payload_digest,
+ events: [ reformatted ]))
+
+ assert_empty @item.financekit_conflicts.open
+ assert_equal 1, @item.financekit_conflicts.count
+ end
+
+ test "a settled balance decision does not suppress a different disagreement" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ second = accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+ @item.financekit_conflicts.open.sole.resolve!(user: @user, resolution: "keep_sure")
+
+ other = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ other["balance"]["observed_at"] = 1.minute.from_now.iso8601
+ other["balance"]["money"] = money("222.00", "credit")
+ accept_and_apply(financekit_payload(sequence: 3, predecessor_digest: second.payload_digest,
+ events: [ other ], captured_at: 1.minute.from_now.iso8601))
+ accept_and_apply(financekit_payload(sequence: 4, predecessor_digest: FinancekitBatch.order(:sequence).last.payload_digest,
+ events: [ other.deep_dup.tap { |event| event["balance"]["money"] = money("333.00", "credit") } ],
+ captured_at: 1.minute.from_now.iso8601))
+
+ assert_equal 1, @item.financekit_conflicts.open.count
+ end
+
+ test "retry after repair releases the observation blocking the replay" do
+ first = accept_and_apply
+ disagreement = financekit_events.find { |record| record["kind"] == "balance_upsert" }
+ disagreement["balance"]["money"] = money("999.00", "credit")
+ accept_and_apply(financekit_payload(sequence: 2, predecessor_digest: first.payload_digest,
+ events: [ disagreement ]))
+
+ # An immutable observation would disagree again after the repair, so the
+ # retry only means something once the declined one is out of the way.
+ @item.financekit_conflicts.open.sole.resolve!(user: @user, resolution: "retry_after_repair")
+
+ assert_equal "repair_required", @item.reload.status
+ assert_empty @source.financekit_balance_observations.where(source_id: @balance_id, kind: "booked")
+ end
+
+ test "a tombstone leaves review open while another conflict is unresolved" do
+ accept_and_apply
+ entry = @source.account.entries.sole
+ entry.update!(locked_attributes: { "name" => Time.current.iso8601 })
+ identity = @source.financekit_transactions.sole
+ tombstone = {
+ "kind" => "transaction_tombstone",
+ "tombstone" => {
+ "source_id" => @transaction_id,
+ "source_account_id" => @source_id,
+ "lineage_id" => @source.financekit_account_lineage_id,
+ "mapping_version" => @source.mapping_version
+ }
+ }
+ upsert = accept_and_apply(financekit_payload(sequence: 2,
+ predecessor_digest: FinancekitBatch.order(:sequence).last.payload_digest,
+ events: [ financekit_events.last ]))
+ retraction = accept_and_apply(financekit_payload(sequence: 3, predecessor_digest: upsert.payload_digest,
+ events: [ tombstone ]))
+ identity.financekit_conflicts.open.find_by!(kind: "protected_entry")
+ .resolve!(user: @user, resolution: "keep_sure")
+
+ accept_and_apply(financekit_payload(sequence: 4, predecessor_digest: retraction.payload_digest,
+ events: [ tombstone ]))
+
+ assert_equal [ "protected_tombstone" ], identity.financekit_conflicts.open.pluck(:kind)
+ assert identity.reload.review_required, "review must stay open while a conflict about the record is"
+ assert_equal 1, @source.account.entries.reload.count
+ end
+
+ test "a source identifier outside the v1-v5 range is accepted" do
+ uuidv7 = "01890a5d-ac96-774b-bcce-b302099a8057"
+ event = financekit_events.last
+ event.fetch("transaction")["source_id"] = uuidv7
+
+ batch = accept_and_apply(financekit_payload(events: [ event ]))
+
+ assert_equal "applied", batch.status
+ assert_equal uuidv7, @source.financekit_transactions.sole.source_id
end
test "a second wallet account cannot map onto an already mapped canonical account" do
diff --git a/test/support/financekit_test_helper.rb b/test/support/financekit_test_helper.rb
index e2ecc43c33..673548a9cd 100644
--- a/test/support/financekit_test_helper.rb
+++ b/test/support/financekit_test_helper.rb
@@ -2,9 +2,7 @@ module FinancekitTestHelper
def financekit_setup(user: users(:family_admin))
travel_to Time.utc(2026, 9, 10, 12)
@user = user
- @user.update!(preferences: @user.preferences.merge("preview_features_enabled" => true))
@family = @user.family
- Financekit.stubs(:enabled?).returns(true)
@source_id = "11111111-1111-4111-8111-111111111111"
@balance_id = "22222222-2222-4222-8222-222222222222"
@transaction_id = "33333333-3333-4333-8333-333333333333"
@@ -120,7 +118,10 @@ module FinancekitTestHelper
def accept_and_apply(payload = financekit_payload, item: @item)
batch, = accept_batch(payload, item: item)
- assert Financekit::Processor.new(item).apply_next!
+ applied = Financekit::Processor.new(item).apply_next!
+ assert applied.present?
+ # apply_next! no longer fans out on its own; the job batches a whole drain.
+ Financekit::Downstream.new(item, FinancekitBatch.where(id: applied.map(&:id))).perform!
batch.reload
end
end