Rocky_Mountain_Vending/lib/sms-compliance.ts

54 lines
2 KiB
TypeScript

import { businessConfig } from "@/lib/seo-config"
export const SMS_CONSENT_VERSION = "sms-consent-v1-2026-03-26"
export type SmsConsentFields = {
serviceTextConsent: boolean
marketingTextConsent: boolean
consentVersion: string
consentCapturedAt: string
consentSourcePage: string
}
export function normalizeConsentSourcePage(value: string | undefined | null) {
const trimmed = String(value || "").trim()
if (!trimmed) {
return "/"
}
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`
}
export function createSmsConsentPayload(input: {
consentCapturedAt?: string | null
consentSourcePage?: string | null
consentVersion?: string | null
marketingTextConsent?: boolean | null
serviceTextConsent?: boolean | null
}): SmsConsentFields {
return {
serviceTextConsent: Boolean(input.serviceTextConsent),
marketingTextConsent: Boolean(input.marketingTextConsent),
consentVersion:
String(input.consentVersion || SMS_CONSENT_VERSION).trim() ||
SMS_CONSENT_VERSION,
consentCapturedAt:
typeof input.consentCapturedAt === "string" &&
input.consentCapturedAt.trim()
? input.consentCapturedAt
: new Date().toISOString(),
consentSourcePage: normalizeConsentSourcePage(input.consentSourcePage),
}
}
export function isValidConsentTimestamp(value: string | undefined | null) {
if (!value) {
return false
}
return !Number.isNaN(Date.parse(value))
}
export const SERVICE_SMS_DISCLOSURE = `${businessConfig.legalName} may send conversational SMS about your inquiry, scheduling, support, repairs, moving, and follow-up. Message frequency varies. Message and data rates may apply. Reply STOP to opt out and HELP for help. Consent is not a condition of purchase.`
export const MARKETING_SMS_DISCLOSURE = `${businessConfig.legalName} may send promotional and marketing SMS. Message frequency varies. Message and data rates may apply. Reply STOP to opt out and HELP for help. Consent is not a condition of purchase.`