mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 11:04:14 +00:00
* Move provider config to family * Update schema.rb * Add provier generator * Add table creation also * FIX generator namespace * Add support for global providers also * Remove over-engineered stuff * FIX parser * FIX linter * Some generator fixes * Update generator with fixes * Update item_model.rb.tt * Add missing linkable concern * Add missing routes * Update adapter.rb.tt * Update connectable_concern.rb.tt * Update unlinking_concern.rb.tt * Update family_generator.rb * Update family_generator.rb * Delete .claude/settings.local.json Signed-off-by: soky srm <sokysrm@gmail.com> * Move docs under API related folder * Rename Rails generator doc * Light edits to LLM generated doc * Small Lunch Flow config panel regressions. --------- Signed-off-by: soky srm <sokysrm@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
115 lines
3.5 KiB
Plaintext
115 lines
3.5 KiB
Plaintext
class Provider::<%= class_name %>Adapter < Provider::Base
|
|
include Provider::Syncable
|
|
include Provider::InstitutionMetadata
|
|
|
|
# Register this adapter with the factory
|
|
Provider::Factory.register("<%= class_name %>Account", self)
|
|
|
|
# Define which account types this provider supports
|
|
def self.supported_account_types
|
|
%w[Depository CreditCard Loan]
|
|
end
|
|
|
|
# Returns connection configurations for this provider
|
|
def self.connection_configs(family:)
|
|
return [] unless family.can_connect_<%= file_name %>?
|
|
|
|
[ {
|
|
key: "<%= file_name %>",
|
|
name: "<%= class_name.titleize %>",
|
|
description: "Connect to your bank via <%= class_name.titleize %>",
|
|
can_connect: true,
|
|
new_account_path: ->(accountable_type, return_to) {
|
|
Rails.application.routes.url_helpers.select_accounts_<%= file_name %>_items_path(
|
|
accountable_type: accountable_type,
|
|
return_to: return_to
|
|
)
|
|
},
|
|
existing_account_path: ->(account_id) {
|
|
Rails.application.routes.url_helpers.select_existing_account_<%= file_name %>_items_path(
|
|
account_id: account_id
|
|
)
|
|
}
|
|
} ]
|
|
end
|
|
|
|
def provider_name
|
|
"<%= file_name %>"
|
|
end
|
|
|
|
# Build a <%= class_name %> provider instance with family-specific credentials
|
|
# @param family [Family] The family to get credentials for (required)
|
|
# @return [Provider::<%= class_name %>, nil] Returns nil if credentials are not configured
|
|
def self.build_provider(family: nil)
|
|
return nil unless family.present?
|
|
|
|
# Get family-specific credentials
|
|
<% first_secret_field = parsed_fields.find { |f| f[:secret] }&.dig(:name) -%>
|
|
<% if first_secret_field -%>
|
|
<%= file_name %>_item = family.<%= file_name %>_items.where.not(<%= first_secret_field %>: nil).first
|
|
<% else -%>
|
|
<%= file_name %>_item = family.<%= file_name %>_items.first
|
|
<% end -%>
|
|
return nil unless <%= file_name %>_item&.credentials_configured?
|
|
|
|
# TODO: Implement provider initialization
|
|
<% if first_secret_field -%>
|
|
# Provider::<%= class_name %>.new(
|
|
# <%= file_name %>_item.<%= first_secret_field %><%= parsed_fields.select { |f| f[:default] }.any? ? ",\n # " + parsed_fields.select { |f| f[:default] }.map { |f| "#{f[:name]}: #{file_name}_item.effective_#{f[:name]}" }.join(",\n # ") : "" %>
|
|
# )
|
|
<% else -%>
|
|
# Provider::<%= class_name %>.new(<%= file_name %>_item)
|
|
<% end -%>
|
|
raise NotImplementedError, "Implement Provider::<%= class_name %>.new in #{__FILE__}"
|
|
end
|
|
|
|
def sync_path
|
|
Rails.application.routes.url_helpers.sync_<%= file_name %>_item_path(item)
|
|
end
|
|
|
|
def item
|
|
provider_account.<%= file_name %>_item
|
|
end
|
|
|
|
def can_delete_holdings?
|
|
false
|
|
end
|
|
|
|
def institution_domain
|
|
metadata = provider_account.institution_metadata
|
|
return nil unless metadata.present?
|
|
|
|
domain = metadata["domain"]
|
|
url = metadata["url"]
|
|
|
|
# Derive domain from URL if missing
|
|
if domain.blank? && url.present?
|
|
begin
|
|
domain = URI.parse(url).host&.gsub(/^www\./, "")
|
|
rescue URI::InvalidURIError
|
|
Rails.logger.warn("Invalid institution URL for <%= class_name %> account #{provider_account.id}: #{url}")
|
|
end
|
|
end
|
|
|
|
domain
|
|
end
|
|
|
|
def institution_name
|
|
metadata = provider_account.institution_metadata
|
|
return nil unless metadata.present?
|
|
|
|
metadata["name"] || item&.institution_name
|
|
end
|
|
|
|
def institution_url
|
|
metadata = provider_account.institution_metadata
|
|
return nil unless metadata.present?
|
|
|
|
metadata["url"] || item&.institution_url
|
|
end
|
|
|
|
def institution_color
|
|
item&.institution_color
|
|
end
|
|
end
|