50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
(function (root, factory) {
|
|
"use strict";
|
|
var api = factory();
|
|
if (typeof module === "object" && module.exports) module.exports = api;
|
|
if (root) root.ToolCtrlSubmission = api;
|
|
})(typeof globalThis === "object" ? globalThis : this, function () {
|
|
"use strict";
|
|
|
|
function createSubmissionId(cryptoApi) {
|
|
if (!cryptoApi || typeof cryptoApi.getRandomValues !== "function") {
|
|
throw new Error("Secure browser randomness is unavailable");
|
|
}
|
|
if (typeof cryptoApi.randomUUID === "function") {
|
|
return cryptoApi.randomUUID();
|
|
}
|
|
var bytes = new Uint8Array(16);
|
|
cryptoApi.getRandomValues(bytes);
|
|
return "web-" + Array.from(bytes, function (value) {
|
|
return value.toString(16).padStart(2, "0");
|
|
}).join("");
|
|
}
|
|
|
|
function normalizedName(value) {
|
|
return String(value || "").trim().replace(/\s+/g, " ");
|
|
}
|
|
|
|
function createLeadFingerprint(input) {
|
|
return JSON.stringify({
|
|
name: normalizedName(input.name),
|
|
company: String(input.firma || "").trim(),
|
|
email: String(input.email || "").trim().toLowerCase(),
|
|
phone: String(input.telefon || "").trim(),
|
|
message: String(input.nachricht || "").trim(),
|
|
formId: "contact-form",
|
|
consent: true
|
|
});
|
|
}
|
|
|
|
function bindSubmissionId(pending, fingerprint, createId) {
|
|
if (pending && pending.fingerprint === fingerprint) return pending;
|
|
return { id: createId(), fingerprint: fingerprint };
|
|
}
|
|
|
|
return {
|
|
bindSubmissionId: bindSubmissionId,
|
|
createLeadFingerprint: createLeadFingerprint,
|
|
createSubmissionId: createSubmissionId
|
|
};
|
|
});
|