mirror of
https://github.com/we-promise/sure.git
synced 2026-08-05 08:32:15 +00:00
* add redbark provider integration - per family api key provider, built like the lunchflow integration - syncs accounts, balances and transactions from api.redbark.com - account setup flow, settings panel, locales and routes - tests and fixtures * harden redbark integration based on prior provider pr feedback - use DebugLogEntry.capture for sync/import/unlink failures - retry 429s and 5xxs with backoff, raise on page cap instead of truncating - keep raw response bodies out of logs and errors - not null constraints on account columns, migration base 7.2 - persist ignored flag for skipped accounts so they stop nagging setup - validate api key on every save, re-arm status on key rotation - destroy aborts if unlink fails, atomic account create and link - require_admin on mutating actions, see_other on error redirects - single grouped query for item account counts - i18n default connection name, blank password field value - controller and provider tests * fix issues found in second review sweep - add missing syncable scope, without it every family sync raises - kick off a sync on connection create and on key rotation - setup dialog fetches accounts inline for fresh connections and shows api errors - skip balance write when no balance has been fetched yet, never anchor a false zero - exclude stale and non banking accounts from the batched balances call, per account fallback if the batch is rejected - detect the server row ceiling and empty pages instead of silently truncating history - user sync start date only governs the initial backfill, incremental after that - fetch connections before the per account loop so auth errors propagate once - drop untemplated index/show/new/edit routes and dead preload/link_accounts actions - stable dom id on the settings panel so repeat turbo replaces keep working * skip brokerage connections, found in live testing - the transactions endpoint 400s for brokerage connections, they belong to /v1/trades - only import accounts from banking and documents connections - guard transaction fetches for any legacy linked non banking account * address review feedback - treat the truncation header as a pagination signal: split the date window and refetch instead of failing the account - prune stale pending rows from the snapshot so settled pendings cant come back as duplicates - block linking a sure account that already has another provider feed - count setup failures separately from skips and surface an error instead of "all skipped" - add not nulls on redbark_items name and api key - enqueue the destroy job after the flag commits, not inside the transaction - swap bg-gray-400 for bg-surface-inset, drop amounts from info logs, remove i18n default fallbacks - tests for window splitting, pending pruning and encrypted payload round trip * fix issues from convention review - benign skips (unlinked account, blank id, unparseable rows) no longer count as failures, tracked separately so a clean batch reports success - currency parsing goes through extract_currency so hash shaped payloads resolve instead of falling to the default - merchant ids use truncated sha256 instead of md5 - debug log entries for import failures and account sync scheduling failures * bound the raw transactions snapshot to the fetch window - trim raw_transactions_payload to the current fetch window on merge, same as brex - keep rows without a parseable date, drop settled pendings as before - surface skipped rows in the aggregate debug log entry with imported/skipped counts
77 lines
2.0 KiB
Ruby
77 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module RedbarkAccount::DataHelpers
|
|
extend ActiveSupport::Concern
|
|
|
|
private
|
|
|
|
# Convert SDK objects to hashes via JSON round-trip
|
|
# Many SDKs return objects that don't have proper #to_h methods
|
|
def sdk_object_to_hash(obj)
|
|
return obj if obj.is_a?(Hash)
|
|
|
|
if obj.respond_to?(:to_json)
|
|
JSON.parse(obj.to_json)
|
|
elsif obj.respond_to?(:to_h)
|
|
obj.to_h
|
|
else
|
|
obj
|
|
end
|
|
rescue JSON::ParserError, TypeError
|
|
obj.respond_to?(:to_h) ? obj.to_h : {}
|
|
end
|
|
|
|
def parse_decimal(value)
|
|
return nil if value.nil?
|
|
|
|
case value
|
|
when BigDecimal
|
|
value
|
|
when String
|
|
BigDecimal(value)
|
|
when Numeric
|
|
BigDecimal(value.to_s)
|
|
else
|
|
nil
|
|
end
|
|
rescue ArgumentError => e
|
|
Rails.logger.error("RedbarkAccount::DataHelpers - Failed to parse decimal value: #{value.inspect} - #{e.message}")
|
|
nil
|
|
end
|
|
|
|
def parse_date(date_value)
|
|
return nil if date_value.nil?
|
|
|
|
case date_value
|
|
when Date
|
|
date_value
|
|
when String
|
|
# Use Time.zone.parse for external timestamps (Rails timezone guidelines)
|
|
Time.zone.parse(date_value)&.to_date
|
|
when Time, DateTime, ActiveSupport::TimeWithZone
|
|
date_value.to_date
|
|
else
|
|
nil
|
|
end
|
|
rescue ArgumentError, TypeError => e
|
|
Rails.logger.error("RedbarkAccount::DataHelpers - Failed to parse date: #{date_value.inspect} - #{e.message}")
|
|
nil
|
|
end
|
|
|
|
# Handle currency as string or object (API inconsistency)
|
|
def extract_currency(data, fallback: nil)
|
|
data = data.with_indifferent_access if data.respond_to?(:with_indifferent_access)
|
|
|
|
currency_data = data[:currency]
|
|
return fallback if currency_data.blank?
|
|
|
|
if currency_data.is_a?(Hash)
|
|
currency_data.with_indifferent_access[:code] || fallback
|
|
elsif currency_data.is_a?(String)
|
|
currency_data.upcase
|
|
else
|
|
fallback
|
|
end
|
|
end
|
|
end
|