Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: 2019 10 18 hellosign callback #53

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ repl-public
repl-node
test
.env
app
nodejs.js
21 changes: 20 additions & 1 deletion build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
:resource-paths #{"src"})

(require
'[degree9.boot-semver :refer :all])
'[degree9.boot-semver :refer :all]
'[meta.boot :as m])

(task-options!
pom {:project 'degree9/enterprise
Expand All @@ -33,3 +34,21 @@
:pre-release 'snapshot)
(watch)
(build-jar)))

(m/initialize)

(deftask build
"Start production build."
[]
(comp
(m/info)
(m/standup)
(m/client :develop true)
(m/server :develop true)
(m/teardown)
(m/package)))

(deftask m-develop
"Start local development."
[]
(m/develop))
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ with nix-shell.pkgs;

SUPPRESS_NO_CONFIG_WARNING = "true";
ENV_TEST_VAR = "foo";
APP_PORT = "5678";
DEBUG = "degree9:*";

shellHook = nix-shell.pkgs.lib.concatStrings [
# extra shellHook commands here
Expand All @@ -24,6 +26,9 @@ with nix-shell.pkgs;


buildInputs = [
nix-shell.pkgs.ngrok
nix-shell.pkgs.boot

(nix-shell.pkgs.writeShellScriptBin "flush"
''
rm -rf ./node_modules
Expand Down Expand Up @@ -52,6 +57,11 @@ with nix-shell.pkgs;
node-test
browser-test
'')

(nix-shell.pkgs.writeShellScriptBin "expose-local"
''
ngrok http $APP_PORT
'')
]
++ nix-shell.shell.buildInputs
;
Expand Down
115 changes: 108 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"hellosign-sdk": "^1.3.1",
"jquery": "^3.4.1",
"mongoose": "^5.7.1",
"multer": "^1.4.2",
"node-fetch": "^2.6.0",
"request": "^2.88.0",
"request-compose": "=1.2.0",
Expand Down
24 changes: 19 additions & 5 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
[funcool/cuerdas "2.1.0"]
[degree9/meta "0.5.0-SNAPSHOT"]
[degree9/uikit-hl "3.0.0-SNAPSHOT"]
[degree9/boot-shadow "2.8.14-0"]
[thheller/shadow-cljs "2.8.31"]

; testing
[degree9/boot-semver "1.8.0" :scope "test"]
Expand All @@ -39,8 +41,8 @@
:asset-path "/js"
:compiler-options
{:reader-features #{:node}}
:closure-defines
{degree9.twilio.fax.fixture/-test-fax-number #shadow/env "TWILIO_TEST_FAX_NUMBER"}
; :closure-defines
; {degree9.twilio.fax.fixture/-test-fax-number #shadow/env "TWILIO_TEST_FAX_NUMBER"}

:modules
{:main
Expand All @@ -50,6 +52,18 @@
{:http-root "repl-public"
:http-port 8020}}

:server
{
:target :node-script
:main degree9.server/start!
:output-dir "app"
:output-to "nodejs.js"
:compiler-options
{:reader-features #{:node}
:optimizations :simple}}
; :closure-defines
; {degree9.twilio.fax.fixtures/-test-fax-number #shadow/env "TWILIO_TEST_FAX_NUMBER"}}

:node-test
{
:target :node-test
Expand All @@ -63,6 +77,6 @@
:target :karma
:output-to "test/browser.js"
:compiler-options
{:reader-features #{:browser}}
:closure-defines
{degree9.twilio.fax.fixture/-test-fax-number #shadow/env "TWILIO_TEST_FAX_NUMBER"}}}}
{:reader-features #{:browser}}}}}
; :closure-defines
; {degree9.twilio.fax.fixture/-test-fax-number #shadow/env "TWILIO_TEST_FAX_NUMBER"}}}}
49 changes: 49 additions & 0 deletions src/degree9/hellosign/callback.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(ns degree9.hellosign.callback
(:require
degree9.multipart-form
degree9.twilio.fax.fixture
degree9.twilio.fax.api
degree9.twilio.client
degree9.hellosign.core))

(defn all-signed! [])

(defn data->parsed [data]
(js->clj
(.parse js/JSON
(.-json data))
:keywordize-keys true))

(defn parsed->final-copy-url [parsed]
(str
"https://"
(degree9.hellosign.core/api-key)
":@api.hellosign.com"
(:final_copy_uri (:signature_request parsed))))

(defn hellosign-success
[resolve reject]
(resolve "Hello API Event Received"))

(defn hellosign-service [& opts]
(reify Object
(create [this data params]
(let [parsed (data->parsed data)]
(when
(and
(-> parsed :event :event_type #{"signature_request_all_signed"})
(-> parsed :signature_request :has_error not)
(-> parsed :signature_request :is_complete)
(-> parsed :signature_request :is_declined not))
(.then
(degree9.twilio.fax.api/fax!
(degree9.twilio.client/client!)
(degree9.twilio.fax.fixture/simple-fax-request (parsed->final-copy-url parsed)))
hellosign-success))
(js/Promise. hellosign-success)))))

(defn with-callback! [app]
(degree9.multipart-form/multipart-none
app
"/hellosign/callback"
(hellosign-service)))
5 changes: 4 additions & 1 deletion src/degree9/hellosign/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
[degree9.env :as env]
["hellosign-sdk" :as hello]))

(def hellosign (hello #js{:key (env/get "HELLOSIGN_API_KEY")}))
(defn api-key []
#js{:key (env/get "HELLOSIGN_API_KEY")})

(def hellosign (hello (api-key)))

(def template (obj/get hellosign "template"))

Expand Down
Loading