Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -57,107 +57,99 @@
|
||||
|
||||
(defn login-cobrand []
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee2-base-url env) "/auth/token")
|
||||
(client/post (merge {:headers (assoc base-headers
|
||||
"loginName" (:yodlee2-admin-user env)
|
||||
"Content-Type" "application/x-www-form-urlencoded")
|
||||
:body (str "clientId=" (:yodlee2-client-id env) "&secret=" (:yodlee2-client-secret env))
|
||||
:as :json}
|
||||
other-config)
|
||||
)
|
||||
:body
|
||||
:token
|
||||
:accessToken))))
|
||||
(fn []
|
||||
(-> (str (:yodlee2-base-url env) "/auth/token")
|
||||
(client/post (merge {:headers (assoc base-headers
|
||||
"loginName" (:yodlee2-admin-user env)
|
||||
"Content-Type" "application/x-www-form-urlencoded")
|
||||
:body (str "clientId=" (:yodlee2-client-id env) "&secret=" (:yodlee2-client-secret env))
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:token
|
||||
:accessToken))))
|
||||
|
||||
(defn login-user [client-code]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(alog/info ::logging-in :client client-code)
|
||||
(-> (str (:yodlee2-base-url env) "/auth/token")
|
||||
(client/post (merge {:headers (assoc base-headers
|
||||
"loginName" (if (:yodlee2-test-user env)
|
||||
(:yodlee2-test-user env)
|
||||
(if (<= (count client-code) 3)
|
||||
(str client-code client-code)
|
||||
client-code))
|
||||
"Content-Type" "application/x-www-form-urlencoded")
|
||||
:body (str "clientId=" (:yodlee2-client-id env) "&secret=" (:yodlee2-client-secret env))
|
||||
:as :json}
|
||||
other-config)
|
||||
)
|
||||
:body
|
||||
:token
|
||||
:accessToken))))
|
||||
(fn []
|
||||
(alog/info ::logging-in :client client-code)
|
||||
(-> (str (:yodlee2-base-url env) "/auth/token")
|
||||
(client/post (merge {:headers (assoc base-headers
|
||||
"loginName" (if (:yodlee2-test-user env)
|
||||
(:yodlee2-test-user env)
|
||||
(if (<= (count client-code) 3)
|
||||
(str client-code client-code)
|
||||
client-code))
|
||||
"Content-Type" "application/x-www-form-urlencoded")
|
||||
:body (str "clientId=" (:yodlee2-client-id env) "&secret=" (:yodlee2-client-secret env))
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:token
|
||||
:accessToken))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-accounts [client-code ]
|
||||
(defn get-accounts [client-code]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
(-> (str (:yodlee2-base-url env) "/accounts")
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (str "Bearer " cob-session)})
|
||||
(-> (str (:yodlee2-base-url env) "/accounts")
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (str "Bearer " cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-accounts-for-provider-account [client-code provider-account-id]
|
||||
(try
|
||||
(try
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
(-> (str (:yodlee2-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(-> (str (:yodlee2-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))
|
||||
(catch Exception e
|
||||
(alog/error ::error
|
||||
(alog/error ::error
|
||||
:error e)
|
||||
[])))
|
||||
|
||||
(defn get-provider-accounts [client-code ]
|
||||
(defn get-provider-accounts [client-code]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(alog/info ::logging-in :client client-code)
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts")
|
||||
(-> (client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session )})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))))
|
||||
|
||||
|
||||
(fn []
|
||||
(alog/info ::logging-in :client client-code)
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts")
|
||||
(-> (client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-transactions [client-code]
|
||||
(let [cob-session (login-user (client-code->login client-code))
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee2-base-url env) "/transactions?top=" batch-size "&skip=" skip)
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/transactions?top=" batch-size "&skip=" skip)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
:transaction))]
|
||||
|
||||
(loop [transactions []
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
|
||||
(defn get-provider-account [client-code id]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id)
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
@@ -167,9 +159,9 @@
|
||||
(defn get-provider-account-detail [client-code id]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id )
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:query-params {"include" "credentials,preferences"}
|
||||
:as :json}
|
||||
other-config))
|
||||
@@ -181,41 +173,34 @@
|
||||
(defn update-provider-account [client-code pa]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}"
|
||||
:as :json}
|
||||
other-config)))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn get-specific-transactions [client-code account]
|
||||
(let [cob-session (login-user (client-code->login client-code))
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee2-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account)
|
||||
(-> (str (:yodlee2-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
:transaction))]
|
||||
|
||||
(loop [transactions []
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
(defn get-access-token [client-code]
|
||||
(try
|
||||
(try
|
||||
(alog/info ::getting-access-token :client client-code)
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
(alog/info ::got-cob-session :cob-ession cob-session)
|
||||
@@ -227,10 +212,9 @@
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn create-user [client-code]
|
||||
(let [cob-session (login-cobrand)]
|
||||
(-> (str (:yodlee2-base-url env) "/user/register")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body (json/write-str {"user" {
|
||||
"loginName" client-code
|
||||
(-> (str (:yodlee2-base-url env) "/user/register")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body (json/write-str {"user" {"loginName" client-code
|
||||
"email" "bryce@integreatconsult.com"
|
||||
"name" {"first" client-code
|
||||
"last" client-code}
|
||||
@@ -247,10 +231,7 @@
|
||||
other-config))
|
||||
:body)))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn get-provider-accounts-with-details [client-code ]
|
||||
(defn get-provider-accounts-with-details [client-code]
|
||||
(let [provider-accounts (get-provider-accounts client-code)
|
||||
concurrent 20
|
||||
output-chan (async/chan)]
|
||||
@@ -270,12 +251,11 @@
|
||||
(get-accounts-for-provider-account client-code provider-account-id)]))
|
||||
provider-account-ids)))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-provider-accounts-with-accounts [client-code]
|
||||
(let [provider-accounts (by :id (get-provider-accounts-with-details client-code))
|
||||
accounts (get-accounts-for-providers client-code (keys provider-accounts))]
|
||||
(->> accounts
|
||||
(->> accounts
|
||||
(reduce
|
||||
(fn [provider-accounts [which accounts]]
|
||||
(assoc-in provider-accounts [which :accounts] accounts))
|
||||
@@ -285,9 +265,9 @@
|
||||
(defn delete-provider-account [client-code id]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id )
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id)
|
||||
|
||||
(client/delete (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(client/delete (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
@@ -301,23 +281,23 @@
|
||||
([client-code provider-accounts]
|
||||
(let [accounts (get-accounts-for-providers client-code (map :id provider-accounts))]
|
||||
(map (fn [pa]
|
||||
(cond->
|
||||
{:yodlee-provider-account/id (:id pa)
|
||||
:yodlee-provider-account/status (:status pa)
|
||||
:yodlee-provider-account/detailed-status (or (-> pa :dataset first :additionalStatus) "unknown")
|
||||
:yodlee-provider-account/client [:client/code client-code]
|
||||
|
||||
:yodlee-provider-account/accounts (mapv
|
||||
(fn [a]
|
||||
{:yodlee-account/id (:id a)
|
||||
:yodlee-account/name (str (:providerName a) " (" (:accountName a) ")")
|
||||
:yodlee-account/number (or (:accountNumber a) "Unknown")
|
||||
:yodlee-account/status (or (-> a :dataset first :additionalStatus) "unknown")
|
||||
:yodlee-account/available-balance (or (-> a :currentBalance :amount)
|
||||
0.0)})
|
||||
(get accounts (:id pa)))}
|
||||
(cond->
|
||||
{:yodlee-provider-account/id (:id pa)
|
||||
:yodlee-provider-account/status (:status pa)
|
||||
:yodlee-provider-account/detailed-status (or (-> pa :dataset first :additionalStatus) "unknown")
|
||||
:yodlee-provider-account/client [:client/code client-code]
|
||||
|
||||
(-> pa :dataset first :lastUpdated) (assoc :yodlee-provider-account/last-updated (-> pa :dataset first :lastUpdated coerce/to-date)) ))
|
||||
:yodlee-provider-account/accounts (mapv
|
||||
(fn [a]
|
||||
{:yodlee-account/id (:id a)
|
||||
:yodlee-account/name (str (:providerName a) " (" (:accountName a) ")")
|
||||
:yodlee-account/number (or (:accountNumber a) "Unknown")
|
||||
:yodlee-account/status (or (-> a :dataset first :additionalStatus) "unknown")
|
||||
:yodlee-account/available-balance (or (-> a :currentBalance :amount)
|
||||
0.0)})
|
||||
(get accounts (:id pa)))}
|
||||
|
||||
(-> pa :dataset first :lastUpdated) (assoc :yodlee-provider-account/last-updated (-> pa :dataset first :lastUpdated coerce/to-date))))
|
||||
provider-accounts))))
|
||||
|
||||
(defn refresh-provider-account [client-code id]
|
||||
@@ -325,7 +305,7 @@
|
||||
:client client-code
|
||||
:provider-acconut-id id)
|
||||
@(dc/transact conn (upsert-accounts-tx client-code
|
||||
[(get-provider-account client-code id)])))
|
||||
[(get-provider-account client-code id)])))
|
||||
|
||||
(defn upsert-accounts []
|
||||
(let [concurrent 20
|
||||
@@ -335,29 +315,26 @@
|
||||
(mapcat (fn [client]
|
||||
(alog/info ::upserting-accounts
|
||||
:client (:client/code client))
|
||||
(mu/with-context {:client-code (:client/code client)}
|
||||
(try
|
||||
(upsert-accounts-tx (:client/code client))
|
||||
(catch Exception e
|
||||
(alog/error ::error :error e :client (:client/code client)))))))
|
||||
(mu/with-context {:client-code (:client/code client)}
|
||||
(try
|
||||
(upsert-accounts-tx (:client/code client))
|
||||
(catch Exception e
|
||||
(alog/error ::error :error e :client (:client/code client)))))))
|
||||
(async/to-chan! (d-clients/get-all)))
|
||||
(let [result (async/<!! (async/into [] output-chan))]
|
||||
(alog/info ::state :state result)
|
||||
@(dc/transact conn result))))
|
||||
|
||||
|
||||
|
||||
|
||||
(defn reauthenticate [client-code pa data]
|
||||
(try
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header (login-user (client-code->login client-code)))})
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header (login-user (client-code->login client-code)))})
|
||||
:body (json/write-str data)
|
||||
:as :json}
|
||||
other-config)))
|
||||
(catch Exception e
|
||||
(alog/error ::error :error e))) )
|
||||
(alog/error ::error :error e))))
|
||||
|
||||
(defn reauthenticate-and-recache [client-code pa data]
|
||||
(reauthenticate client-code pa data)
|
||||
|
||||
Reference in New Issue
Block a user