import process from "node:process";
import { basicAuthorization } from "https://esm.town/v/stevekrouse/basicAuthorization";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export const mt = async (req, res) => {
const r = await fetchJSON(
"https://app.moderntreasury.com/api/user_onboardings",
{
method: "POST",
body: JSON.stringify({
flow_alias: "default-individual",
}),
headers: await basicAuthorization(
process.env.mtOrganizationId,
process.env.mtApiKey,
),
},
);
res.send(`<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.moderntreasury.com/compliance/v1/mt-onboarding.js"></script>
<script type="application/ecmascript">
function openIframe() {
const onSuccess = function (event) {
// handle success event (e.g. move user to the next step of your flow following KYC)
};
const onError = function (event) {
// handle error event (e.g. open the iframe again)
};
const onCancel = function (event) {
// handle cancel event (e.g. email the user later to try and reactivate them)
// note: this event will not be triggered if the user closes their browser.
};
const userOnboardingId = document.getElementById('userOnboardingId').value;
window.onboardingInstance = MTOnboarding.open({
userOnboardingId: userOnboardingId, // required
onSuccess: onSuccess, // optional
onError: onError, // optional
onClose: onCancel, // optional
});
}
</script>
</head>
<body>
<label for="userOnboardingId">User Onboarding ID:</label>
<input type="text" value="${r.id}" name="userOnboardingId" id="userOnboardingId">
<br/>
<button onclick="openIframe()">
Open
</button>
</body>
</html>`);
};