This commit is contained in:
2026-05-29 17:32:33 -07:00
6 changed files with 209 additions and 182 deletions

File diff suppressed because one or more lines are too long

View File

@@ -66,9 +66,9 @@
]) ])
(defn not-found [_] (defn not-found [_]
{:status 404 {:status 404
:headers {} :headers {}
:body ""}) :body ""})
(defn home-handler [{:keys [identity]}] (defn home-handler [{:keys [identity]}]
(if identity (if identity
@@ -125,13 +125,13 @@
(defn wrap-logging [handler] (defn wrap-logging [handler]
(fn [request] (fn [request]
(mu/with-context (cond-> {:uri (:uri request) (mu/with-context (cond-> {:uri (:uri request)
:route (:handler (bidi.bidi/match-route all-routes :route (:handler (bidi.bidi/match-route all-routes
(:uri request) (:uri request)
:request-method (:request-method request))) :request-method (:request-method request)))
:client-selection (:client-selection request) :client-selection (:client-selection request)
:source "request" :source "request"
:query (:uri request) :query (:uri request)
:request-method (:request-method request) :request-method (:request-method request)
:user (dissoc (:identity request) :user (dissoc (:identity request)
@@ -157,15 +157,15 @@
(defn wrap-idle-session-timeout (defn wrap-idle-session-timeout
[handler] [handler]
(fn [request] (fn [request]
(let [session (:session request {:version session-version/current-session-version}) (let [session (:session request {:version session-version/current-session-version})
end-time (coerce/to-date-time (::idle-timeout session))] end-time (coerce/to-date-time (::idle-timeout session))]
(if (and end-time (time/before? end-time (time/now))) (if (and end-time (time/before? end-time (time/now)))
(if (get (:headers request) "hx-request") (if (get (:headers request) "hx-request")
{:session nil {:session nil
:status 200 :status 200
:headers {"hx-redirect" "/login"}} :headers {"hx-redirect" "/login"}}
{:session nil {:session nil
:status 302 :status 302
:headers {"Location" "/login"}}) :headers {"Location" "/login"}})
(when-let [response (handler request)] (when-let [response (handler request)]
(let [session (:session response session)] (let [session (:session response session)]
@@ -231,7 +231,7 @@
seq seq
(pull-many (dc/db conn) (pull-many (dc/db conn)
'[:db/id :client/name :client/code :client/locations '[:db/id :client/name :client/code :client/locations
:client/matches :client/feature-flags :client/matches :client/feature-flags
{:client/bank-accounts [:db/id {:client/bank-accounts [:db/id
{:bank-account/type [:db/ident]} {:bank-account/type [:db/ident]}
:bank-account/number :bank-account/number
@@ -298,7 +298,7 @@
{:status 200 {:status 200
:headers {"hx-trigger" (cheshire/generate-string :headers {"hx-trigger" (cheshire/generate-string
{"notification" (str (hiccup/html [:div (.getMessage e)]))}) {"notification" (str (hiccup/html [:div (.getMessage e)]))})
"hx-reswap" "none"}} ;; TODO make a warning box so you don't have to reuse the notifaction box, or make it reuse the same box but theme differently "hx-reswap" "none"}} ;; TODO make a warning box so you don't have to reuse the notifaction box, or make it reuse the same box but theme differently
:else :else
{:status 500 {:status 500
:body (pr-str e)}))))) :body (pr-str e)})))))
@@ -315,32 +315,48 @@
:valid-trimmed-client-ids trimmed-clients :valid-trimmed-client-ids trimmed-clients
:first-client-id (first valid-clients) :first-client-id (first valid-clients)
:clients-trimmed? (not= (count trimmed-clients) (count valid-clients))))))) :clients-trimmed? (not= (count trimmed-clients) (count valid-clients)))))))
(defn wrap-dev-login [handler]
(fn [request]
(if (and (= "/dev-login" (:uri request))
(some-> env :base-url (.contains "localhost")))
(let [identity {:user "Dev User"
:user/name "Dev User"
:user/role "admin"
:db/id 0}]
{:status 200
:headers {"Content-Type" "text/html"}
:body "<p>Logged in as Dev User!</p><a href='/dashboard'>Continue to dashboard</a>"
:session {:identity identity
:version session-version/current-session-version}})
(handler request))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defonce app (defonce app
(-> route-handler (-> route-handler
(wrap-hx-current-url-params) (wrap-hx-current-url-params)
(wrap-guess-route) (wrap-guess-route)
(wrap-logging) (wrap-logging)
(wrap-trim-clients) (wrap-trim-clients)
(wrap-hydrate-clients) (wrap-hydrate-clients)
(wrap-store-client-in-session) (wrap-store-client-in-session)
(wrap-gunzip-jwt) (wrap-gunzip-jwt)
(wrap-authorization auth-backend) (wrap-dev-login)
(wrap-authentication auth-backend (wrap-authorization auth-backend)
(session-backend {:authfn (fn [auth] (wrap-authentication auth-backend
(dissoc auth :exp))})) (session-backend {:authfn (fn [auth]
(dissoc auth :exp))}))
#_(wrap-pprint-session) #_(wrap-pprint-session)
(session-version/wrap-session-version) (session-version/wrap-session-version)
(wrap-idle-session-timeout) (wrap-idle-session-timeout)
(wrap-session {:store (cookie-store (wrap-session {:store (cookie-store
{:key {:key
(byte-array (byte-array
[42, 52, -31, 101, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])})}) [42, 52, -31, 101, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])})})
#_(wrap-reload) #_(wrap-reload)
(wrap-params) (wrap-params)
(mp/wrap-multipart-params) (mp/wrap-multipart-params)
(wrap-edn-params) (wrap-edn-params)
(wrap-error))) (wrap-error)))

View File

@@ -1,12 +1,11 @@
(ns auto-ap.ssr.auth (ns auto-ap.ssr.auth
(:require (:require
[auto-ap.session-version :as session-version] [auto-ap.session-version :as session-version]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.hx :as hx] [auto-ap.ssr.hx :as hx]
[auto-ap.ssr.svg :as svg] [auto-ap.ssr.svg :as svg]
[auto-ap.ssr.ui :refer [base-page]]
[buddy.sign.jwt :as jwt] [buddy.sign.jwt :as jwt]
[config.core :refer [env]] [config.core :refer [env]]
[hiccup2.core :as hiccup]
[hiccup.util :as hu])) [hiccup.util :as hu]))
(defn logout [request] (defn logout [request]
@@ -37,69 +36,73 @@
"scope" "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"} "scope" "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"}
next (assoc "state" (hu/url-encode next)))))))) next (assoc "state" (hu/url-encode next))))))))
(defn- login-page [contents]
{:status 200
:headers {"Content-Type" "text/html"}
:body (str "<!DOCTYPE html>"
(hiccup/html
[:html
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
[:title "Integreat · Sign In"]
[:link {:rel "icon" :type "image/png" :href "/favicon.png"}]
[:link {:rel "stylesheet" :href "/output.css"}]
[:script {:defer true :src "https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"}]
[:style
"body{background:linear-gradient(160deg,#79b52e 0%,#009cea 100%);min-height:100vh}"]]
[:body contents]]))})
(defn- page-contents [request] (defn- page-contents [request]
[:div#app {"@notification.document" "notificationDetails=event.detail.value; showNotification=true" [:div
{:x-data (hx/json {:showError false
:errorDetails ""})
"@htmx:response-error.camel" "errorDetails = $event.detail.xhr.response; showError=true;"}
:x-data (hx/json {:showError false [:div.fixed.top-0.left-0.right-0.z-50.mx-auto.max-w-md.w-full.px-4.pt-6
:errorDetails "" {:x-show "showError"
:showNotification false "x-transition:enter" "transition duration-200 ease-out"
:notificationDetails ""}) "x-transition:enter-start" "opacity-0 -translate-y-3"
"@htmx:response-error.camel" "errorDetails = $event.detail.xhr.response; showError=true;"} "x-transition:enter-end" "opacity-100 translate-y-0"}
[:div#app-contents.flex.overflow-hidden [:div.relative.bg-white.rounded-xl.shadow-xl.border.border-red-200.p-4
[:div#main-content {:class "relative w-full h-full overflow-y-auto px-4 bg-gray-100 dark:bg-gray-900 min-h-content "} [:button.absolute.right-3.top-3.p-1.text-red-400.hover:text-red-600
[:div#notification-holder {"@click" "showError=false"}
[:div.fixed.top-0.right-0.left-0.z-30.mx-auto.max-w-screen-lg.w-screen-lg.my-0.pt-8.rounded-lg {:x-show "showNotification"} svg/filled-x]
[:div.relative [:div.flex.items-start.gap-3
[:button.absolute.right-2.top-2.w-6.h-6.z-50.text-blue-400 [:div.flex-shrink-0.w-5.h-5.text-red-500 svg/alert]
{"@click" "showNotification=false"} [:div.flex-1.min-w-0
svg/filled-x]] [:p.text-sm.font-medium.text-gray-900 "Something went wrong"]
[:p.text-xs.text-gray-500.mt-0.5
"Our team has been notified. Please try again."
[:span {:x-data (hx/json {"e" false})}
" "
[:a.text-xs.underline.cursor-pointer.text-gray-500.hover:text-gray-700
{"@click" "e=true"}
"Details"]
[:pre.text-xs.mt-1.font-mono.text-red-600.bg-red-50.p-2.rounded {:x-show "e" :x-text "errorDetails"}]]]]]]]
[:div.m-4.overflow-auto.z-30.flex.center-items.justify-center.text-blue-800.bg-blue-50.dark:bg-gray-800.dark:text-blue-400.border-blue-300.rounded-lg.border.max-h-96 [:div.flex.items-center.justify-center.min-h-screen.px-4
{:x-show "showNotification" [:div.w-full.max-w-lg
"x-transition:enter" "transition duration-300 transform ease-in-out" [:div.flex.flex-col.items-center.mb-10
"x-transition:enter-start" "opacity-0 translate-y-full" [:img {:src "/img/logo-big.png" :alt "Integreat" :class "h-16 brightness-0 invert"}]]
"x-transition:enter-end" "opacity-100 translate-y-0"
"x-transition:leave" "transition duration-300 transform ease-in-out"
"x-transition:leave-start" "opacity-100 translate-y-0"
"x-transition:leave-end" "opacity-0 translate-y-full"}
[:div {:class "p-4 text-lg w-full" :role "alert"} [:div.bg-white.rounded-2xl.shadow-2xl.p-10
[:div.text-sm {:style "animation: slideUp 0.4s ease-out forwards; opacity: 0;"}
[:pre#notification-details.text-xs {:x-html "notificationDetails"}]]]]]] [:div.flex.flex-col.items-center.gap-8
[:div {:x-show "showError" [:div.text-center
:x-init ""} [:h1.text-2xl.font-bold.text-gray-900 "Sign in to Integreat"]
[:div.fixed.top-0.right-0.left-0.z-30.mx-auto.max-w-screen-lg.w-screen-lg.my-0.pt-8.rounded-lg [:p.mt-2.text-base.text-gray-500 "Use your Google account to continue"]]
[:div.relative
[:button.absolute.right-2.top-2.w-6.h-6.z-50.text-red-600
{"@click" "showError=false"}
svg/filled-x]]
[:div.m-4.overflow-auto.z-30.flex.center-items.justify-center.text-red-800.bg-red-50.dark:bg-gray-800.dark:text-red-400.border-red-300.rounded-lg.border.max-h-96 [:a {:href (login-url (get (:query-params request) "redirect-to"))
{:x-show "showError" :class "w-full max-w-xs flex items-center justify-center gap-3 px-6 py-3.5 text-base font-semibold rounded-xl border-2 border-gray-200 text-gray-700 bg-white hover:bg-gray-50 hover:border-gray-300 shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-400 transition-all duration-150"}
"x-transition:enter" "transition duration-300" svg/google
"x-transition:enter-start" "opacity-0" "Sign in with Google"]]
"x-transition:enter-end" "opacity-100"}
[:div {:class "p-4 mb-4 text-lg w-full" :role "alert"} [:p.mt-2.text-center.text-xs.text-gray-400
[:div.inline-block.w-8.h-8.mr-2 svg/alert] "By signing in, you agree to our "
[:span.font-medium "Oh, drat! An unexpected error has occurred."] [:a.underline.hover:text-gray-600 {:href "/terms"} "Terms of Service"]
[:div.text-sm {:x-data (hx/json {"expandError" false})} " and "
[:p "Integreat staff have been notified and are looking into it. "] [:a.underline.hover:text-gray-600 {:href "/privacy"} "Privacy Policy"]]]]]])
[:p "To see error details, " [:a.underline.cursor-pointer {"@click" "expandError=true"} "click here"] "."]
[:pre#error-details.text-xs {:x-show "expandError" :x-text "errorDetails"}]]]]]]
[:div.p-4.flex.flex-row.justify-center.items-center.h-screen
(com/card {:class "animate-slideUp w-full max-w-md"}
[:div.p-8
[:div.flex.justify-center.mb-6
[:img {:src "/img/logo-big.png" :class "max-w-[200px]"}]]
[:div
[:a {:href (login-url (get (:query-params request) "redirect-to"))
:class "inline-flex items-center justify-center w-full px-8 py-3 text-base font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"}
"Login with Google"]]])]]]])
(defn login [request] (defn login [request]
(base-page (login-page (page-contents request)))
request
(page-contents request)
"Dashboard"))

View File

@@ -83,11 +83,11 @@
[:line {:stroke "currentColor", :fill "none", :stroke-linejoin "round", :y1 "16.22", :stroke-linecap "round", :stroke-width "1.5px", :x1 "16.221", :y2 "23.25", :x2 "23.25"}]]) [:line {:stroke "currentColor", :fill "none", :stroke-linejoin "round", :y1 "16.22", :stroke-linecap "round", :stroke-width "1.5px", :x1 "16.221", :y2 "23.25", :x2 "23.25"}]])
(def moon (def moon
[:svg {:id "theme-toggle-dark-icon", :fill "currentColor", :viewbox "0 0 20 20", :xmlns "http://www.w3.org/2000/svg"} [:svg {:id "theme-toggle-dark-icon", :fill "currentColor", :viewbox "0 0 20 20", :xmlns "http://www.w3.org/2000/svg"}
[:path {:d "M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"}]]) [:path {:d "M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"}]])
(def sun (def sun
[:svg {:id "theme-toggle-light-icon", :fill "currentColor", :viewbox "0 0 20 20", :xmlns "http://www.w3.org/2000/svg"} [:svg {:id "theme-toggle-light-icon", :fill "currentColor", :viewbox "0 0 20 20", :xmlns "http://www.w3.org/2000/svg"}
[:path {:d "M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z", :fill-rule "evenodd", :clip-rule "evenodd"}]]) [:path {:d "M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z", :fill-rule "evenodd", :clip-rule "evenodd"}]])
(def home (def home
@@ -157,23 +157,23 @@
[:defs] [:defs]
[:title "navigation-next"] [:title "navigation-next"]
[:path [:path
{:d "M23,9.5H12.387a4,4,0,0,0-4,4v2", {:d "M23,9.5H12.387a4,4,0,0,0-4,4v2",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}] :stroke-linejoin "round"}]
[:polyline [:polyline
{:points "19 13.498 23 9.498 19 5.498", {:points "19 13.498 23 9.498 19 5.498",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}] :stroke-linejoin "round"}]
[:path [:path
{:d {:d
"M14.387,13v5.5a1,1,0,0,1-1,1h-12a1,1,0,0,1-1-1V6.5a1,1,0,0,1,1-1h12a1,1,0,0,1,1,1V7", "M14.387,13v5.5a1,1,0,0,1-1,1h-12a1,1,0,0,1-1-1V6.5a1,1,0,0,1,1-1h12a1,1,0,0,1,1,1V7",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}]]) :stroke-linejoin "round"}]])
(def play (def play
[:svg {:xmlns "http://www.w3.org/2000/svg", :viewbox "-0.5 -0.5 24 24"} [:svg {:xmlns "http://www.w3.org/2000/svg", :viewbox "-0.5 -0.5 24 24"}
@@ -187,26 +187,26 @@
[:defs] [:defs]
[:title "pencil"] [:title "pencil"]
[:rect [:rect
{:y "1.09", {:y "1.09",
:stroke "currentColor", :stroke "currentColor",
:transform "translate(11.889 -5.238) rotate(45)", :transform "translate(11.889 -5.238) rotate(45)",
:fill "none", :fill "none",
:stroke-linejoin "round", :stroke-linejoin "round",
:width "6", :width "6",
:stroke-linecap "round", :stroke-linecap "round",
:x "9.268", :x "9.268",
:height "21.284"}] :height "21.284"}]
[:polygon [:polygon
{:points "2.621 17.136 0.5 23.5 6.864 21.379 2.621 17.136", {:points "2.621 17.136 0.5 23.5 6.864 21.379 2.621 17.136",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}] :stroke-linejoin "round"}]
[:path [:path
{:d "M21.914,6.328,17.672,2.086l.707-.707a3,3,0,0,1,4.242,4.242Z", {:d "M21.914,6.328,17.672,2.086l.707-.707a3,3,0,0,1,4.242,4.242Z",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}]]) :stroke-linejoin "round"}]])
(def dollar-tag (def dollar-tag
@@ -231,15 +231,15 @@
[:path [:path
{:d {:d
"M5.5,11.5c-.275,0-.341.159-.146.354l6.292,6.293a.5.5,0,0,0,.709,0l6.311-6.275c.2-.193.13-.353-.145-.355L15.5,11.5V1.5a1,1,0,0,0-1-1h-5a1,1,0,0,0-1,1V11a.5.5,0,0,1-.5.5Z", "M5.5,11.5c-.275,0-.341.159-.146.354l6.292,6.293a.5.5,0,0,0,.709,0l6.311-6.275c.2-.193.13-.353-.145-.355L15.5,11.5V1.5a1,1,0,0,0-1-1h-5a1,1,0,0,0-1,1V11a.5.5,0,0,1-.5.5Z",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}] :stroke-linejoin "round"}]
[:path [:path
{:d "M23.5,18.5v4a1,1,0,0,1-1,1H1.5a1,1,0,0,1-1-1v-4", {:d "M23.5,18.5v4a1,1,0,0,1-1,1H1.5a1,1,0,0,1-1-1v-4",
:fill "none", :fill "none",
:stroke "currentColor", :stroke "currentColor",
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round"}]]) :stroke-linejoin "round"}]])
(def trash (def trash
@@ -522,3 +522,10 @@
[:path {:d "m12 16 0 3", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}] [:path {:d "m12 16 0 3", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]
[:path {:d "M4.5 9.5h15s1 0 1 1v12s0 1 -1 1h-15s-1 0 -1 -1v-12s0 -1 1 -1", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}] [:path {:d "M4.5 9.5h15s1 0 1 1v12s0 1 -1 1h-15s-1 0 -1 -1v-12s0 -1 1 -1", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]
[:path {:d "M6.5 6a5.5 5.5 0 0 1 11 0v3.5h-11Z", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]]) [:path {:d "M6.5 6a5.5 5.5 0 0 1 11 0v3.5h-11Z", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]])
(def google
[:svg {:viewbox "0 0 24 24", :width "20", :height "20", :xmlns "http://www.w3.org/2000/svg"}
[:path {:fill "#4285F4" :d "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}]
[:path {:fill "#34A853" :d "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}]
[:path {:fill "#FBBC05" :d "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}]
[:path {:fill "#EA4335" :d "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"}]])

View File

@@ -22,7 +22,7 @@
(println (format "HTTP port: %d (.http-port)" http-port)) (println (format "HTTP port: %d (.http-port)" http-port))
(nrepl/start-server :port nrepl-port) (nrepl/start-server :port nrepl-port)
(require 'user) (require 'user)
(user/start-dev http-port) ((resolve 'user/start-dev) http-port)
(println "Ready.") (println "Ready.")
@(promise))) @(promise)))

View File

@@ -84,24 +84,24 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn load-accounts [conn] (defn load-accounts [conn]
(let [[header & rows] (-> "master-account-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv) (let [[header & rows] (-> "master-account-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
:db/id])] :db/id])]
:in ['$] :in ['$]
:where ['[?e :account/name]]} :where ['[?e :account/name]]}
(dc/db conn)))) (dc/db conn))))
also-merge-txes (fn [also-merge old-account-id] also-merge-txes (fn [also-merge old-account-id]
(if old-account-id (if old-account-id
(let [[sunset-account] (let [[sunset-account]
(first (dc/q {:find ['?a] (first (dc/q {:find ['?a]
:in ['$ '?ac] :in ['$ '?ac]
:where ['[?a :account/numeric-code ?ac]]} :where ['[?a :account/numeric-code ?ac]]}
(dc/db conn) also-merge))] (dc/db conn) also-merge))]
(into (mapv (into (mapv
(fn [[entity id _]] (fn [[entity id _]]
[:db/add entity id old-account-id]) [:db/add entity id old-account-id])
(dc/q {:find ['?e '?id '?a] (dc/q {:find ['?e '?id '?a]
:in ['$ '?ac] :in ['$ '?ac]
:where ['[?a :account/numeric-code ?ac] :where ['[?a :account/numeric-code ?ac]
'[?e ?at ?a] '[?e ?at ?a]
'[?at :db/ident ?id]]} '[?at :db/ident ?id]]}
@@ -112,7 +112,7 @@
txes (transduce txes (transduce
(comp (comp
(map (fn ->map [r] (map (fn ->map [r]
(into {} (map vector header r)))) (into {} (map vector header r))))
(map (fn parse-map [r] (map (fn parse-map [r]
{:old-account-id (:db/id (code->existing-account {:old-account-id (:db/id (code->existing-account
@@ -160,8 +160,8 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn find-bad-accounts [] (defn find-bad-accounts []
(set (map second (dc/q {:find ['(pull ?x [*]) '?z] (set (map second (dc/q {:find ['(pull ?x [*]) '?z]
:in ['$] :in ['$]
:where ['[?e :account/numeric-code ?z] :where ['[?e :account/numeric-code ?z]
'[(<= ?z 9999)] '[(<= ?z 9999)]
'[?x ?a ?e]]} '[?x ?a ?e]]}
@@ -177,8 +177,8 @@
[:db/retractEntity old-account-id]))) [:db/retractEntity old-account-id])))
conj conj
[] []
(dc/q {:find ['?e] (dc/q {:find ['?e]
:in ['$] :in ['$]
:where ['[?e :account/numeric-code ?z] :where ['[?e :account/numeric-code ?z]
'[(<= ?z 9999)]]} '[(<= ?z 9999)]]}
(dc/db conn))))) (dc/db conn)))))
@@ -192,27 +192,27 @@
(fn [acc [e z]] (fn [acc [e z]]
(update acc z conj e)) (update acc z conj e))
{} {}
(dc/q {:find ['?e '?z] (dc/q {:find ['?e '?z]
:in ['$] :in ['$]
:where ['[?e :account/numeric-code ?z]]} :where ['[?e :account/numeric-code ?z]]}
(dc/db conn))))) (dc/db conn)))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn customize-accounts [customer filename] (defn customize-accounts [customer filename]
(let [[_ & rows] (-> filename (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv) (let [[_ & rows] (-> filename (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
[client-id] (first (dc/q (-> {:find ['?e] [client-id] (first (dc/q (-> {:find ['?e]
:in ['$ '?z] :in ['$ '?z]
:where [['?e :client/code '?z]]} :where [['?e :client/code '?z]]}
(dc/db conn) customer))) (dc/db conn) customer)))
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
{:account/applicability [:db/ident]} {:account/applicability [:db/ident]}
:db/id])] :db/id])]
:in ['$] :in ['$]
:where ['[?e :account/name]]} :where ['[?e :account/name]]}
(dc/db conn)))) (dc/db conn))))
existing-account-overrides (dc/q {:find ['?e] existing-account-overrides (dc/q {:find ['?e]
:in ['$ '?client-id] :in ['$ '?client-id]
:where [['?e :account-client-override/client '?client-id]]} :where [['?e :account-client-override/client '?client-id]]}
(dc/db conn) client-id) (dc/db conn) client-id)
@@ -276,8 +276,8 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fix-transactions-without-locations [client-code location] (defn fix-transactions-without-locations [client-code location]
(->> (->>
(dc/q {:find ['(pull ?e [*])] (dc/q {:find ['(pull ?e [*])]
:in ['$ '?client-code] :in ['$ '?client-code]
:where ['[?e :transaction/accounts ?ta] :where ['[?e :transaction/accounts ?ta]
'[?e :transaction/matched-rule] '[?e :transaction/matched-rule]
'[?e :transaction/approval-status :transaction-approval-status/approved] '[?e :transaction/approval-status :transaction-approval-status/approved]
@@ -297,8 +297,8 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn entity-history [i] (defn entity-history [i]
(vec (sort-by first (dc/q (vec (sort-by first (dc/q
{:find ['?tx '?z '?v] {:find ['?tx '?z '?v]
:in ['?i '$] :in ['?i '$]
:where ['[?i ?a ?v ?tx ?ad] :where ['[?i ?a ?v ?tx ?ad]
'[?a :db/ident ?z] '[?a :db/ident ?z]
'[(= ?ad true)]]} '[(= ?ad true)]]}
@@ -307,8 +307,8 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn entity-history-with-revert [i] (defn entity-history-with-revert [i]
(vec (sort-by first (dc/q (vec (sort-by first (dc/q
{:find ['?tx '?z '?v '?ad] {:find ['?tx '?z '?v '?ad]
:in ['?i '$] :in ['?i '$]
:where ['[?i ?a ?v ?tx ?ad] :where ['[?i ?a ?v ?tx ?ad]
'[?a :db/ident ?z]]} '[?a :db/ident ?z]]}
i (dc/history (dc/db conn)))))) i (dc/history (dc/db conn))))))
@@ -354,8 +354,9 @@
(defn start-dev [& [http-port]] (defn start-dev [& [http-port]]
(set-refresh-dirs "src") (set-refresh-dirs "src")
#_(clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.server)) (clojure.tools.namespace.repl/disable-reload! (find-ns 'dev-mcp))
#_(clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.time)) #_(clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.server))
#_(clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.time))
(start-db) (start-db)
(start-http http-port) (start-http http-port)
(auto-reset)) (auto-reset))
@@ -378,18 +379,18 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn find-queries [words] (defn find-queries [words]
(let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env) (let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env)
:prefix (str "queries/")) :prefix (str "queries/"))
concurrent 30 concurrent 30
output-chan (async/chan)] output-chan (async/chan)]
(async/pipeline-blocking concurrent (async/pipeline-blocking concurrent
output-chan output-chan
(comp (comp
(map #(do (map #(do
[(:key %) [(:key %)
(str (slurp (:object-content (s3/get-object (str (slurp (:object-content (s3/get-object
:bucket-name (:data-bucket env) :bucket-name (:data-bucket env)
:key (:key %)))))])) :key (:key %)))))]))
(filter #(->> words (filter #(->> words
(every? (fn [w] (str/includes? (second %) w))))) (every? (fn [w] (str/includes? (second %) w)))))
@@ -403,9 +404,9 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn upsert-invoice-amounts [tsv] (defn upsert-invoice-amounts [tsv]
(let [data (with-open [reader (io/reader (char-array tsv))] (let [data (with-open [reader (io/reader (char-array tsv))]
(doall (csv/read-csv reader :separator \tab))) (doall (csv/read-csv reader :separator \tab)))
db (dc/db conn) db (dc/db conn)
i->invoice-id (fn [i] i->invoice-id (fn [i]
(try (Long/parseLong i) (try (Long/parseLong i)
(catch Exception e (catch Exception e
@@ -458,7 +459,7 @@
:when current-total] :when current-total]
[(when (not (auto-ap.utils/dollars= current-total target-total)) [(when (not (auto-ap.utils/dollars= current-total target-total))
{:db/id invoice-id {:db/id invoice-id
:invoice/total target-total}) :invoice/total target-total})
(when new-account? (when new-account?
@@ -523,7 +524,7 @@
(let [client-location (ffirst (d/q '[:find ?l :in $ ?c :where [?c :client/locations ?l]] (dc/db conn) [:client/code client-code]))] (let [client-location (ffirst (d/q '[:find ?l :in $ ?c :where [?c :client/locations ?l]] (dc/db conn) [:client/code client-code]))]
(clojure.data.csv/write-csv (clojure.data.csv/write-csv
*out* *out*
(for [n (range n) (for [n (range n)
:let [v (rand-nth (map first (d/q '[:find ?vn :where [_ :vendor/name ?vn]] (dc/db conn)))) :let [v (rand-nth (map first (d/q '[:find ?vn :where [_ :vendor/name ?vn]] (dc/db conn))))
[{a-1 :account/numeric-code a-1-location :account/location} [{a-1 :account/numeric-code a-1-location :account/location}
{a-2 :account/numeric-code a-2-location :account/location}] (->> (d/q '[:find (pull ?a [:account/numeric-code :account/location]) :where [?a :account/numeric-code]] {a-2 :account/numeric-code a-2-location :account/location}] (->> (d/q '[:find (pull ?a [:account/numeric-code :account/location]) :where [?a :account/numeric-code]]
@@ -536,8 +537,8 @@
(t/minus (t/days (rand-int 60))) (t/minus (t/days (rand-int 60)))
(atime/unparse atime/normal-date)) (atime/unparse atime/normal-date))
id (rand-int 100000)] id (rand-int 100000)]
a [[(str id) client-code "synthetic" v d a-1 (or a-1-location client-location) 0 amount] a [[(str id) client-code "synthetic" v d a-1 (or a-1-location client-location) 0 amount]
[(str id) client-code "synthetic" v d a-2 (or a-2-location client-location) amount 0]]] [(str id) client-code "synthetic" v d a-2 (or a-2-location client-location) amount 0]]]
a) a)
:separator \tab)))) :separator \tab))))
@@ -549,7 +550,7 @@
(let [bank-accounts (map first (d/q '[:find ?bac :in $ ?c :where [?c :client/bank-accounts ?b] [?b :bank-account/code ?bac]] (dc/db conn) [:client/code client-code]))] (let [bank-accounts (map first (d/q '[:find ?bac :in $ ?c :where [?c :client/bank-accounts ?b] [?b :bank-account/code ?bac]] (dc/db conn) [:client/code client-code]))]
(clojure.data.csv/write-csv (clojure.data.csv/write-csv
*out* *out*
(for [n (range n) (for [n (range n)
:let [amount (rand-int 2000) :let [amount (rand-int 2000)
d (-> (t/now) d (-> (t/now)
(t/minus (t/days (rand-int 60))) (t/minus (t/days (rand-int 60)))
@@ -565,7 +566,7 @@
:in $ :in $
:where [?i :invoice/invoice-number] :where [?i :invoice/invoice-number]
(not [?i :invoice/status :invoice-status/voided])] (not [?i :invoice/status :invoice-status/voided])]
:args [(dc/db conn)]}) :args [(dc/db conn)]})
(map first) (map first)
(partition-all 500))] (partition-all 500))]
(print ".") (print ".")
@@ -578,7 +579,7 @@
:in $ :in $
:where [?i :payment/date] :where [?i :payment/date]
(not [?i :payment/status :payment-status/voided])] (not [?i :payment/status :payment-status/voided])]
:args [(dc/db conn)]}) :args [(dc/db conn)]})
(map first) (map first)
(partition-all 500))] (partition-all 500))]
(print ".") (print ".")
@@ -591,7 +592,7 @@
:in $ :in $
:where [?i :transaction/description-original] :where [?i :transaction/description-original]
(not [?i :transaction/approval-status :transaction-approval-status/suppressed])] (not [?i :transaction/approval-status :transaction-approval-status/suppressed])]
:args [(dc/db conn)]}) :args [(dc/db conn)]})
(map first) (map first)
(partition-all 500))] (partition-all 500))]
(print ".") (print ".")
@@ -602,7 +603,7 @@
(doseq [batch (->> (dc/qseq {:query '[:find ?i (doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $ :in $
:where [?i :journal-entry/date]] :where [?i :journal-entry/date]]
:args [(dc/db conn)]}) :args [(dc/db conn)]})
(map first) (map first)
(partition-all 500))] (partition-all 500))]
(print ".") (print ".")