@foundrykit/form-plugin 0.0.0-stage → 1.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +486 -2
- package/dist/assets/flags/AD.svg +8 -0
- package/dist/assets/flags/AE.svg +8 -0
- package/dist/assets/flags/AF.svg +7 -0
- package/dist/assets/flags/AG.svg +8 -0
- package/dist/assets/flags/AI.svg +17 -0
- package/dist/assets/flags/AL.svg +4 -0
- package/dist/assets/flags/AM.svg +5 -0
- package/dist/assets/flags/AO.svg +7 -0
- package/dist/assets/flags/AQ.svg +4 -0
- package/dist/assets/flags/AR.svg +6 -0
- package/dist/assets/flags/AS.svg +7 -0
- package/dist/assets/flags/AT.svg +5 -0
- package/dist/assets/flags/AU.svg +20 -0
- package/dist/assets/flags/AW.svg +7 -0
- package/dist/assets/flags/AX.svg +5 -0
- package/dist/assets/flags/AZ.svg +7 -0
- package/dist/assets/flags/BA.svg +16 -0
- package/dist/assets/flags/BB.svg +6 -0
- package/dist/assets/flags/BD.svg +4 -0
- package/dist/assets/flags/BE.svg +5 -0
- package/dist/assets/flags/BF.svg +5 -0
- package/dist/assets/flags/BG.svg +5 -0
- package/dist/assets/flags/BH.svg +4 -0
- package/dist/assets/flags/BI.svg +11 -0
- package/dist/assets/flags/BJ.svg +5 -0
- package/dist/assets/flags/BM.svg +27 -0
- package/dist/assets/flags/BN.svg +11 -0
- package/dist/assets/flags/BO.svg +5 -0
- package/dist/assets/flags/BQ-SA.svg +6 -0
- package/dist/assets/flags/BQ-SE.svg +11 -0
- package/dist/assets/flags/BQ.svg +7 -0
- package/dist/assets/flags/BR.svg +7 -0
- package/dist/assets/flags/BS.svg +6 -0
- package/dist/assets/flags/BT.svg +5 -0
- package/dist/assets/flags/BW.svg +6 -0
- package/dist/assets/flags/BY.svg +13 -0
- package/dist/assets/flags/BZ.svg +10 -0
- package/dist/assets/flags/CA-BC.svg +26 -0
- package/dist/assets/flags/CA.svg +6 -0
- package/dist/assets/flags/CC.svg +12 -0
- package/dist/assets/flags/CD.svg +6 -0
- package/dist/assets/flags/CF.svg +10 -0
- package/dist/assets/flags/CG.svg +5 -0
- package/dist/assets/flags/CH.svg +6 -0
- package/dist/assets/flags/CI.svg +5 -0
- package/dist/assets/flags/CK.svg +20 -0
- package/dist/assets/flags/CL-EI.svg +4 -0
- package/dist/assets/flags/CL.svg +6 -0
- package/dist/assets/flags/CM.svg +6 -0
- package/dist/assets/flags/CN.svg +8 -0
- package/dist/assets/flags/CO.svg +5 -0
- package/dist/assets/flags/CR.svg +6 -0
- package/dist/assets/flags/CU.svg +8 -0
- package/dist/assets/flags/CV.svg +16 -0
- package/dist/assets/flags/CW.svg +6 -0
- package/dist/assets/flags/CX.svg +12 -0
- package/dist/assets/flags/CY.svg +5 -0
- package/dist/assets/flags/CZ.svg +5 -0
- package/dist/assets/flags/DE.svg +5 -0
- package/dist/assets/flags/DJ.svg +6 -0
- package/dist/assets/flags/DK.svg +4 -0
- package/dist/assets/flags/DM.svg +21 -0
- package/dist/assets/flags/DO.svg +10 -0
- package/dist/assets/flags/DZ.svg +6 -0
- package/dist/assets/flags/EA-ML.svg +18 -0
- package/dist/assets/flags/EC-W.svg +5 -0
- package/dist/assets/flags/EC.svg +8 -0
- package/dist/assets/flags/EE.svg +5 -0
- package/dist/assets/flags/EG.svg +6 -0
- package/dist/assets/flags/EH.svg +8 -0
- package/dist/assets/flags/ER.svg +6 -0
- package/dist/assets/flags/ES-BV.svg +5 -0
- package/dist/assets/flags/ES-CE.svg +22 -0
- package/dist/assets/flags/ES-IB.svg +10 -0
- package/dist/assets/flags/ES.svg +7 -0
- package/dist/assets/flags/ET.svg +8 -0
- package/dist/assets/flags/EU.svg +11 -0
- package/dist/assets/flags/FI.svg +4 -0
- package/dist/assets/flags/FJ.svg +13 -0
- package/dist/assets/flags/FK.svg +17 -0
- package/dist/assets/flags/FL-BR.svg +11 -0
- package/dist/assets/flags/FM.svg +7 -0
- package/dist/assets/flags/FO.svg +5 -0
- package/dist/assets/flags/FR-COR.svg +5 -0
- package/dist/assets/flags/FR.svg +5 -0
- package/dist/assets/flags/GA.svg +5 -0
- package/dist/assets/flags/GB-ORK.svg +5 -0
- package/dist/assets/flags/GB-SCT.svg +7 -0
- package/dist/assets/flags/GB-WLS.svg +7 -0
- package/dist/assets/flags/GB.svg +22 -0
- package/dist/assets/flags/GD.svg +17 -0
- package/dist/assets/flags/GE-AB.svg +16 -0
- package/dist/assets/flags/GE.svg +8 -0
- package/dist/assets/flags/GG.svg +5 -0
- package/dist/assets/flags/GH.svg +6 -0
- package/dist/assets/flags/GI.svg +6 -0
- package/dist/assets/flags/GL.svg +6 -0
- package/dist/assets/flags/GM.svg +6 -0
- package/dist/assets/flags/GN.svg +5 -0
- package/dist/assets/flags/GQ.svg +9 -0
- package/dist/assets/flags/GR.svg +10 -0
- package/dist/assets/flags/GT.svg +7 -0
- package/dist/assets/flags/GU.svg +10 -0
- package/dist/assets/flags/GW.svg +6 -0
- package/dist/assets/flags/GY.svg +8 -0
- package/dist/assets/flags/HK.svg +8 -0
- package/dist/assets/flags/HN.svg +10 -0
- package/dist/assets/flags/HR.svg +24 -0
- package/dist/assets/flags/HT.svg +10 -0
- package/dist/assets/flags/HU.svg +5 -0
- package/dist/assets/flags/IC.svg +5 -0
- package/dist/assets/flags/ID.svg +4 -0
- package/dist/assets/flags/IE.svg +5 -0
- package/dist/assets/flags/IL.svg +6 -0
- package/dist/assets/flags/IM.svg +4 -0
- package/dist/assets/flags/IN.svg +6 -0
- package/dist/assets/flags/IO.svg +35 -0
- package/dist/assets/flags/IQ.svg +8 -0
- package/dist/assets/flags/IR.svg +30 -0
- package/dist/assets/flags/IS.svg +5 -0
- package/dist/assets/flags/IT.svg +5 -0
- package/dist/assets/flags/JE.svg +6 -0
- package/dist/assets/flags/JM.svg +7 -0
- package/dist/assets/flags/JO.svg +7 -0
- package/dist/assets/flags/JP.svg +4 -0
- package/dist/assets/flags/KE.svg +12 -0
- package/dist/assets/flags/KG.svg +10 -0
- package/dist/assets/flags/KH.svg +6 -0
- package/dist/assets/flags/KI.svg +9 -0
- package/dist/assets/flags/KM.svg +12 -0
- package/dist/assets/flags/KN.svg +8 -0
- package/dist/assets/flags/KP.svg +9 -0
- package/dist/assets/flags/KR.svg +25 -0
- package/dist/assets/flags/KW.svg +6 -0
- package/dist/assets/flags/KY.svg +17 -0
- package/dist/assets/flags/KZ.svg +6 -0
- package/dist/assets/flags/LA.svg +6 -0
- package/dist/assets/flags/LB.svg +6 -0
- package/dist/assets/flags/LC.svg +8 -0
- package/dist/assets/flags/LI.svg +5 -0
- package/dist/assets/flags/LK.svg +16 -0
- package/dist/assets/flags/LR.svg +11 -0
- package/dist/assets/flags/LS.svg +6 -0
- package/dist/assets/flags/LT.svg +5 -0
- package/dist/assets/flags/LU.svg +5 -0
- package/dist/assets/flags/LV.svg +5 -0
- package/dist/assets/flags/LY.svg +7 -0
- package/dist/assets/flags/MA.svg +4 -0
- package/dist/assets/flags/MC.svg +4 -0
- package/dist/assets/flags/MD-SN.svg +7 -0
- package/dist/assets/flags/MD.svg +8 -0
- package/dist/assets/flags/ME.svg +8 -0
- package/dist/assets/flags/MG.svg +5 -0
- package/dist/assets/flags/MH.svg +6 -0
- package/dist/assets/flags/MK.svg +13 -0
- package/dist/assets/flags/ML.svg +5 -0
- package/dist/assets/flags/MM.svg +6 -0
- package/dist/assets/flags/MN.svg +12 -0
- package/dist/assets/flags/MO.svg +11 -0
- package/dist/assets/flags/MQ.svg +8 -0
- package/dist/assets/flags/MR.svg +5 -0
- package/dist/assets/flags/MS.svg +16 -0
- package/dist/assets/flags/MT.svg +5 -0
- package/dist/assets/flags/MU.svg +6 -0
- package/dist/assets/flags/MV.svg +5 -0
- package/dist/assets/flags/MW.svg +6 -0
- package/dist/assets/flags/MX.svg +7 -0
- package/dist/assets/flags/MY.svg +10 -0
- package/dist/assets/flags/MZ.svg +10 -0
- package/dist/assets/flags/NA.svg +7 -0
- package/dist/assets/flags/NE.svg +6 -0
- package/dist/assets/flags/NF.svg +6 -0
- package/dist/assets/flags/NG.svg +5 -0
- package/dist/assets/flags/NI.svg +9 -0
- package/dist/assets/flags/NL.svg +5 -0
- package/dist/assets/flags/NO.svg +5 -0
- package/dist/assets/flags/NP.svg +8 -0
- package/dist/assets/flags/NR.svg +5 -0
- package/dist/assets/flags/NU.svg +29 -0
- package/dist/assets/flags/NZ.svg +17 -0
- package/dist/assets/flags/OM.svg +7 -0
- package/dist/assets/flags/PA.svg +7 -0
- package/dist/assets/flags/PE.svg +5 -0
- package/dist/assets/flags/PF.svg +10 -0
- package/dist/assets/flags/PG.svg +10 -0
- package/dist/assets/flags/PH.svg +9 -0
- package/dist/assets/flags/PK.svg +7 -0
- package/dist/assets/flags/PL.svg +5 -0
- package/dist/assets/flags/PN.svg +17 -0
- package/dist/assets/flags/PR.svg +8 -0
- package/dist/assets/flags/PS.svg +6 -0
- package/dist/assets/flags/PT.svg +7 -0
- package/dist/assets/flags/PW.svg +4 -0
- package/dist/assets/flags/PY.svg +7 -0
- package/dist/assets/flags/QA.svg +4 -0
- package/dist/assets/flags/RO.svg +5 -0
- package/dist/assets/flags/RS.svg +11 -0
- package/dist/assets/flags/RU.svg +6 -0
- package/dist/assets/flags/RW.svg +6 -0
- package/dist/assets/flags/SA.svg +11 -0
- package/dist/assets/flags/SB.svg +12 -0
- package/dist/assets/flags/SC.svg +9 -0
- package/dist/assets/flags/SD.svg +8 -0
- package/dist/assets/flags/SE.svg +6 -0
- package/dist/assets/flags/SG.svg +12 -0
- package/dist/assets/flags/SI.svg +10 -0
- package/dist/assets/flags/SK.svg +11 -0
- package/dist/assets/flags/SL.svg +7 -0
- package/dist/assets/flags/SM.svg +9 -0
- package/dist/assets/flags/SN.svg +8 -0
- package/dist/assets/flags/SO.svg +6 -0
- package/dist/assets/flags/SR.svg +9 -0
- package/dist/assets/flags/SS.svg +10 -0
- package/dist/assets/flags/ST.svg +8 -0
- package/dist/assets/flags/SV.svg +8 -0
- package/dist/assets/flags/SX.svg +12 -0
- package/dist/assets/flags/SY.svg +9 -0
- package/dist/assets/flags/SZ.svg +16 -0
- package/dist/assets/flags/TB.svg +32 -0
- package/dist/assets/flags/TC.svg +20 -0
- package/dist/assets/flags/TD.svg +5 -0
- package/dist/assets/flags/TG.svg +10 -0
- package/dist/assets/flags/TH.svg +8 -0
- package/dist/assets/flags/TJ.svg +15 -0
- package/dist/assets/flags/TK.svg +11 -0
- package/dist/assets/flags/TL.svg +6 -0
- package/dist/assets/flags/TM.svg +24 -0
- package/dist/assets/flags/TN.svg +8 -0
- package/dist/assets/flags/TO.svg +7 -0
- package/dist/assets/flags/TR.svg +7 -0
- package/dist/assets/flags/TT.svg +7 -0
- package/dist/assets/flags/TV.svg +32 -0
- package/dist/assets/flags/TW.svg +9 -0
- package/dist/assets/flags/TZ.svg +8 -0
- package/dist/assets/flags/UA.svg +6 -0
- package/dist/assets/flags/UG.svg +11 -0
- package/dist/assets/flags/UN.svg +7 -0
- package/dist/assets/flags/US-HI.svg +26 -0
- package/dist/assets/flags/US-MP.svg +7 -0
- package/dist/assets/flags/US.svg +22 -0
- package/dist/assets/flags/UY.svg +11 -0
- package/dist/assets/flags/UZ.svg +22 -0
- package/dist/assets/flags/VA.svg +8 -0
- package/dist/assets/flags/VC.svg +10 -0
- package/dist/assets/flags/VE.svg +15 -0
- package/dist/assets/flags/VG.svg +23 -0
- package/dist/assets/flags/VI.svg +13 -0
- package/dist/assets/flags/VN.svg +6 -0
- package/dist/assets/flags/VU.svg +12 -0
- package/dist/assets/flags/WS.svg +9 -0
- package/dist/assets/flags/XC.svg +7 -0
- package/dist/assets/flags/XO.svg +5 -0
- package/dist/assets/flags/XS.svg +13 -0
- package/dist/assets/flags/YE.svg +7 -0
- package/dist/assets/flags/ZA.svg +10 -0
- package/dist/assets/flags/ZM.svg +9 -0
- package/dist/assets/flags/ZW.svg +15 -0
- package/dist/blocks/fields/Address.d.ts +11 -0
- package/dist/blocks/fields/Address.js +46 -0
- package/dist/blocks/fields/Address.js.map +1 -0
- package/dist/blocks/fields/Checkbox.d.ts +2 -0
- package/dist/blocks/fields/Checkbox.js +31 -0
- package/dist/blocks/fields/Checkbox.js.map +1 -0
- package/dist/blocks/fields/CheckboxGroup.d.ts +2 -0
- package/dist/blocks/fields/CheckboxGroup.js +29 -0
- package/dist/blocks/fields/CheckboxGroup.js.map +1 -0
- package/dist/blocks/fields/Date.d.ts +2 -0
- package/dist/blocks/fields/Date.js +46 -0
- package/dist/blocks/fields/Date.js.map +1 -0
- package/dist/blocks/fields/Email.d.ts +2 -0
- package/dist/blocks/fields/Email.js +36 -0
- package/dist/blocks/fields/Email.js.map +1 -0
- package/dist/blocks/fields/File.d.ts +2 -0
- package/dist/blocks/fields/File.js +34 -0
- package/dist/blocks/fields/File.js.map +1 -0
- package/dist/blocks/fields/Number.d.ts +2 -0
- package/dist/blocks/fields/Number.js +34 -0
- package/dist/blocks/fields/Number.js.map +1 -0
- package/dist/blocks/fields/Phone.d.ts +2 -0
- package/dist/blocks/fields/Phone.js +62 -0
- package/dist/blocks/fields/Phone.js.map +1 -0
- package/dist/blocks/fields/RadioGroup.d.ts +2 -0
- package/dist/blocks/fields/RadioGroup.js +29 -0
- package/dist/blocks/fields/RadioGroup.js.map +1 -0
- package/dist/blocks/fields/Select.d.ts +2 -0
- package/dist/blocks/fields/Select.js +37 -0
- package/dist/blocks/fields/Select.js.map +1 -0
- package/dist/blocks/fields/Text.d.ts +2 -0
- package/dist/blocks/fields/Text.js +36 -0
- package/dist/blocks/fields/Text.js.map +1 -0
- package/dist/blocks/fields/Textarea.d.ts +2 -0
- package/dist/blocks/fields/Textarea.js +22 -0
- package/dist/blocks/fields/Textarea.js.map +1 -0
- package/dist/blocks/fields/TravelDate.d.ts +10 -0
- package/dist/blocks/fields/TravelDate.js +30 -0
- package/dist/blocks/fields/TravelDate.js.map +1 -0
- package/dist/blocks/fields/shared.d.ts +8 -0
- package/dist/blocks/fields/shared.js +158 -0
- package/dist/blocks/fields/shared.js.map +1 -0
- package/dist/blocks/fields/visibility.d.ts +9 -0
- package/dist/blocks/fields/visibility.js +203 -0
- package/dist/blocks/fields/visibility.js.map +1 -0
- package/dist/blocks/submissionActions/ConfirmationMessage.d.ts +7 -0
- package/dist/blocks/submissionActions/ConfirmationMessage.js +25 -0
- package/dist/blocks/submissionActions/ConfirmationMessage.js.map +1 -0
- package/dist/blocks/submissionActions/Redirect.d.ts +2 -0
- package/dist/blocks/submissionActions/Redirect.js +29 -0
- package/dist/blocks/submissionActions/Redirect.js.map +1 -0
- package/dist/blocks/submissionActions/SendEmail.d.ts +2 -0
- package/dist/blocks/submissionActions/SendEmail.js +50 -0
- package/dist/blocks/submissionActions/SendEmail.js.map +1 -0
- package/dist/collections/Forms.d.ts +12 -0
- package/dist/collections/Forms.js +327 -0
- package/dist/collections/Forms.js.map +1 -0
- package/dist/collections/Submissions.d.ts +8 -0
- package/dist/collections/Submissions.js +137 -0
- package/dist/collections/Submissions.js.map +1 -0
- package/dist/components/BeforeDashboardClient.d.ts +1 -0
- package/dist/components/BeforeDashboardClient.js +40 -0
- package/dist/components/BeforeDashboardClient.js.map +1 -0
- package/dist/components/BeforeDashboardServer.d.ts +2 -0
- package/dist/components/BeforeDashboardServer.js +22 -0
- package/dist/components/BeforeDashboardServer.js.map +1 -0
- package/dist/components/BeforeDashboardServer.module.css +5 -0
- package/dist/components/EnquiryForm/FieldTooltip.d.ts +5 -0
- package/dist/components/EnquiryForm/FieldTooltip.js +33 -0
- package/dist/components/EnquiryForm/FieldTooltip.js.map +1 -0
- package/dist/components/EnquiryForm/Step.d.ts +8 -0
- package/dist/components/EnquiryForm/Step.js +157 -0
- package/dist/components/EnquiryForm/Step.js.map +1 -0
- package/dist/components/EnquiryForm/StepIndicator.d.ts +17 -0
- package/dist/components/EnquiryForm/StepIndicator.js +59 -0
- package/dist/components/EnquiryForm/StepIndicator.js.map +1 -0
- package/dist/components/EnquiryForm/fields/AddressField.d.ts +20 -0
- package/dist/components/EnquiryForm/fields/AddressField.js +253 -0
- package/dist/components/EnquiryForm/fields/AddressField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/BudgetRangeField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/BudgetRangeField.js +48 -0
- package/dist/components/EnquiryForm/fields/BudgetRangeField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/CheckboxField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/CheckboxField.js +68 -0
- package/dist/components/EnquiryForm/fields/CheckboxField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/CountrySelect.d.ts +27 -0
- package/dist/components/EnquiryForm/fields/CountrySelect.js +208 -0
- package/dist/components/EnquiryForm/fields/CountrySelect.js.map +1 -0
- package/dist/components/EnquiryForm/fields/DateInputField.d.ts +18 -0
- package/dist/components/EnquiryForm/fields/DateInputField.js +69 -0
- package/dist/components/EnquiryForm/fields/DateInputField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/EmailInputField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/EmailInputField.js +56 -0
- package/dist/components/EnquiryForm/fields/EmailInputField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/MultiCounterField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/MultiCounterField.js +97 -0
- package/dist/components/EnquiryForm/fields/MultiCounterField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/NumberStepperField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/NumberStepperField.js +71 -0
- package/dist/components/EnquiryForm/fields/NumberStepperField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/OptionCardsField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/OptionCardsField.js +51 -0
- package/dist/components/EnquiryForm/fields/OptionCardsField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/PhoneInputField.d.ts +14 -0
- package/dist/components/EnquiryForm/fields/PhoneInputField.js +170 -0
- package/dist/components/EnquiryForm/fields/PhoneInputField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/SelectField.d.ts +13 -0
- package/dist/components/EnquiryForm/fields/SelectField.js +245 -0
- package/dist/components/EnquiryForm/fields/SelectField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/TextInputField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/TextInputField.js +46 -0
- package/dist/components/EnquiryForm/fields/TextInputField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/TextareaField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/TextareaField.js +46 -0
- package/dist/components/EnquiryForm/fields/TextareaField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/TravelDateField.d.ts +16 -0
- package/dist/components/EnquiryForm/fields/TravelDateField.js +351 -0
- package/dist/components/EnquiryForm/fields/TravelDateField.js.map +1 -0
- package/dist/components/EnquiryForm/fields/YesNoField.d.ts +8 -0
- package/dist/components/EnquiryForm/fields/YesNoField.js +51 -0
- package/dist/components/EnquiryForm/fields/YesNoField.js.map +1 -0
- package/dist/components/EnquiryForm/index.d.ts +2 -0
- package/dist/components/EnquiryForm/index.js +173 -0
- package/dist/components/EnquiryForm/index.js.map +1 -0
- package/dist/components/EnquiryForm/useEnquiryForm.d.ts +19 -0
- package/dist/components/EnquiryForm/useEnquiryForm.js +136 -0
- package/dist/components/EnquiryForm/useEnquiryForm.js.map +1 -0
- package/dist/components/SubmissionAnswers.d.ts +12 -0
- package/dist/components/SubmissionAnswers.js +33 -0
- package/dist/components/SubmissionAnswers.js.map +1 -0
- package/dist/components/SubmissionPanel.d.ts +25 -0
- package/dist/components/SubmissionPanel.js +188 -0
- package/dist/components/SubmissionPanel.js.map +1 -0
- package/dist/components/SubmissionPanel.module.css +147 -0
- package/dist/endpoints/customEndpointHandler.d.ts +2 -0
- package/dist/endpoints/customEndpointHandler.js +7 -0
- package/dist/endpoints/customEndpointHandler.js.map +1 -0
- package/dist/endpoints/fetchFormHandler.d.ts +3 -0
- package/dist/endpoints/fetchFormHandler.js +54 -0
- package/dist/endpoints/fetchFormHandler.js.map +1 -0
- package/dist/endpoints/submitFormHandler.d.ts +3 -0
- package/dist/endpoints/submitFormHandler.js +156 -0
- package/dist/endpoints/submitFormHandler.js.map +1 -0
- package/dist/exports/client.d.ts +5 -0
- package/dist/exports/client.js +10 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/frontend.d.ts +10 -0
- package/dist/exports/frontend.js +18 -0
- package/dist/exports/frontend.js.map +1 -0
- package/dist/exports/rich-text.d.ts +18 -0
- package/dist/exports/rich-text.js +20 -0
- package/dist/exports/rich-text.js.map +1 -0
- package/dist/exports/rsc.d.ts +5 -0
- package/dist/exports/rsc.js +6 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/fields/conditions/ConditionSourceField.d.ts +7 -0
- package/dist/fields/conditions/ConditionSourceField.js +36 -0
- package/dist/fields/conditions/ConditionSourceField.js.map +1 -0
- package/dist/fields/conditions/ConditionValueField.d.ts +9 -0
- package/dist/fields/conditions/ConditionValueField.js +82 -0
- package/dist/fields/conditions/ConditionValueField.js.map +1 -0
- package/dist/fields/conditions/collectSourceFields.d.ts +30 -0
- package/dist/fields/conditions/collectSourceFields.js +67 -0
- package/dist/fields/conditions/collectSourceFields.js.map +1 -0
- package/dist/fields/conditions/describeSource.d.ts +15 -0
- package/dist/fields/conditions/describeSource.js +32 -0
- package/dist/fields/conditions/describeSource.js.map +1 -0
- package/dist/fields/lockable/LockableTextField.d.ts +11 -0
- package/dist/fields/lockable/LockableTextField.js +96 -0
- package/dist/fields/lockable/LockableTextField.js.map +1 -0
- package/dist/fields/lockable/formatSlug.d.ts +17 -0
- package/dist/fields/lockable/formatSlug.js +27 -0
- package/dist/fields/lockable/formatSlug.js.map +1 -0
- package/dist/fields/lockable/index.d.ts +28 -0
- package/dist/fields/lockable/index.js +58 -0
- package/dist/fields/lockable/index.js.map +1 -0
- package/dist/fields/lockable/index.scss +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +432 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities/buildFieldRules.d.ts +19 -0
- package/dist/utilities/buildFieldRules.js +54 -0
- package/dist/utilities/buildFieldRules.js.map +1 -0
- package/dist/utilities/buildFormURL.d.ts +5 -0
- package/dist/utilities/buildFormURL.js +6 -0
- package/dist/utilities/buildFormURL.js.map +1 -0
- package/dist/utilities/buildIndicatorSteps.d.ts +15 -0
- package/dist/utilities/buildIndicatorSteps.js +33 -0
- package/dist/utilities/buildIndicatorSteps.js.map +1 -0
- package/dist/utilities/buildSubmitURL.d.ts +11 -0
- package/dist/utilities/buildSubmitURL.js +9 -0
- package/dist/utilities/buildSubmitURL.js.map +1 -0
- package/dist/utilities/buildZodSchemaFromForm.d.ts +40 -0
- package/dist/utilities/buildZodSchemaFromForm.js +218 -0
- package/dist/utilities/buildZodSchemaFromForm.js.map +1 -0
- package/dist/utilities/conditions/evaluateRule.d.ts +9 -0
- package/dist/utilities/conditions/evaluateRule.js +93 -0
- package/dist/utilities/conditions/evaluateRule.js.map +1 -0
- package/dist/utilities/conditions/index.d.ts +2 -0
- package/dist/utilities/conditions/index.js +4 -0
- package/dist/utilities/conditions/index.js.map +1 -0
- package/dist/utilities/conditions/visibility.d.ts +8 -0
- package/dist/utilities/conditions/visibility.js +40 -0
- package/dist/utilities/conditions/visibility.js.map +1 -0
- package/dist/utilities/countryFromLabel.d.ts +7 -0
- package/dist/utilities/countryFromLabel.js +37 -0
- package/dist/utilities/countryFromLabel.js.map +1 -0
- package/dist/utilities/countryFromLabel.test.d.ts +1 -0
- package/dist/utilities/countryFromLabel.test.js +40 -0
- package/dist/utilities/countryFromLabel.test.js.map +1 -0
- package/dist/utilities/describeSubmission.d.ts +82 -0
- package/dist/utilities/describeSubmission.js +291 -0
- package/dist/utilities/describeSubmission.js.map +1 -0
- package/dist/utilities/fetchEnquiryForm.d.ts +6 -0
- package/dist/utilities/fetchEnquiryForm.js +19 -0
- package/dist/utilities/fetchEnquiryForm.js.map +1 -0
- package/dist/utilities/flagAssets.d.ts +2 -0
- package/dist/utilities/flagAssets.js +19 -0
- package/dist/utilities/flagAssets.js.map +1 -0
- package/dist/utilities/lookupPostcode.d.ts +37 -0
- package/dist/utilities/lookupPostcode.js +49 -0
- package/dist/utilities/lookupPostcode.js.map +1 -0
- package/dist/utilities/normalizeFormSteps.d.ts +25 -0
- package/dist/utilities/normalizeFormSteps.js +27 -0
- package/dist/utilities/normalizeFormSteps.js.map +1 -0
- package/dist/utilities/normalizeSubmitError.d.ts +10 -0
- package/dist/utilities/normalizeSubmitError.js +24 -0
- package/dist/utilities/normalizeSubmitError.js.map +1 -0
- package/dist/utilities/recaptchaClient.d.ts +30 -0
- package/dist/utilities/recaptchaClient.js +68 -0
- package/dist/utilities/recaptchaClient.js.map +1 -0
- package/dist/utilities/sanitizeSubmission.d.ts +4 -0
- package/dist/utilities/sanitizeSubmission.js +8 -0
- package/dist/utilities/sanitizeSubmission.js.map +1 -0
- package/dist/utilities/toDateInputValue.d.ts +15 -0
- package/dist/utilities/toDateInputValue.js +27 -0
- package/dist/utilities/toDateInputValue.js.map +1 -0
- package/dist/utilities/toDateInputValue.test.d.ts +1 -0
- package/dist/utilities/toDateInputValue.test.js +39 -0
- package/dist/utilities/toDateInputValue.test.js.map +1 -0
- package/dist/utilities/travelDate.d.ts +14 -0
- package/dist/utilities/travelDate.js +56 -0
- package/dist/utilities/travelDate.js.map +1 -0
- package/dist/utilities/validateVisibleSubmission.d.ts +10 -0
- package/dist/utilities/validateVisibleSubmission.js +28 -0
- package/dist/utilities/validateVisibleSubmission.js.map +1 -0
- package/dist/utilities/verifyCaptcha.d.ts +55 -0
- package/dist/utilities/verifyCaptcha.js +98 -0
- package/dist/utilities/verifyCaptcha.js.map +1 -0
- package/package.json +122 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
type Row = {
|
|
2
|
+
fieldName?: null | string;
|
|
3
|
+
value?: null | string;
|
|
4
|
+
};
|
|
5
|
+
type FieldLike = {
|
|
6
|
+
blockType?: string;
|
|
7
|
+
counters?: {
|
|
8
|
+
label?: null | string;
|
|
9
|
+
name?: null | string;
|
|
10
|
+
}[] | null;
|
|
11
|
+
fields?: FieldLike[] | null;
|
|
12
|
+
label?: null | string;
|
|
13
|
+
name?: null | string;
|
|
14
|
+
options?: {
|
|
15
|
+
label?: null | string;
|
|
16
|
+
value?: null | string;
|
|
17
|
+
}[] | null;
|
|
18
|
+
};
|
|
19
|
+
type FormLike = {
|
|
20
|
+
fields?: FieldLike[] | null;
|
|
21
|
+
steps?: {
|
|
22
|
+
fields?: FieldLike[] | null;
|
|
23
|
+
title?: null | string;
|
|
24
|
+
}[] | null;
|
|
25
|
+
} | null;
|
|
26
|
+
export type PanelItem = {
|
|
27
|
+
/** Set when the value can be changed in the admin: the form path and how to edit it. */
|
|
28
|
+
edit?: {
|
|
29
|
+
multiline?: boolean;
|
|
30
|
+
options?: {
|
|
31
|
+
label: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}[];
|
|
34
|
+
path: string;
|
|
35
|
+
};
|
|
36
|
+
/** `mailto:`, `tel:` or web link for the value, when it is one. */
|
|
37
|
+
href?: string;
|
|
38
|
+
label: string;
|
|
39
|
+
tone?: 'bad' | 'good';
|
|
40
|
+
value: string;
|
|
41
|
+
/** Takes the full row: long text. */
|
|
42
|
+
wide?: boolean;
|
|
43
|
+
};
|
|
44
|
+
export type PanelGroup = {
|
|
45
|
+
items: PanelItem[];
|
|
46
|
+
title?: string;
|
|
47
|
+
};
|
|
48
|
+
export type Answer = {
|
|
49
|
+
name: string;
|
|
50
|
+
} & PanelItem;
|
|
51
|
+
export type AnswerGroup = {
|
|
52
|
+
answers: Answer[];
|
|
53
|
+
title?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Pairs each stored answer with its question on the form: labelled, option values shown as their
|
|
57
|
+
* labels, JSON answers (phone, counters, address) spelled out. Grouped by step on multi-step forms;
|
|
58
|
+
* answers the form no longer has (or never had, e.g. added by the site) come last.
|
|
59
|
+
*/
|
|
60
|
+
export declare function describeSubmission(form: FormLike, rows: null | Row[] | undefined): AnswerGroup[];
|
|
61
|
+
/**
|
|
62
|
+
* A readable title for a submission: the person's name, else their email, else the date.
|
|
63
|
+
* Looks for answers named like "name", "full-name" or "first-name" + "last-name", and "email".
|
|
64
|
+
*/
|
|
65
|
+
export declare function submissionTitle(doc: {
|
|
66
|
+
createdAt?: null | string;
|
|
67
|
+
data?: null | Row[];
|
|
68
|
+
submittedAt?: null | string;
|
|
69
|
+
}): string;
|
|
70
|
+
/**
|
|
71
|
+
* The request a submission came with (page, IP, browser) and its context, flattened: each object
|
|
72
|
+
* in the context becomes its own group, e.g. the `hidden` tracking values.
|
|
73
|
+
*/
|
|
74
|
+
export declare function describeDetails(doc: {
|
|
75
|
+
context?: null | Record<string, unknown>;
|
|
76
|
+
metadata?: {
|
|
77
|
+
ip?: null | string;
|
|
78
|
+
referrer?: null | string;
|
|
79
|
+
userAgent?: null | string;
|
|
80
|
+
} | null;
|
|
81
|
+
}): PanelGroup[];
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { parseTravelDate } from './travelDate.js';
|
|
2
|
+
const key = (name)=>name.toLowerCase().replace(/[^a-z]/g, '');
|
|
3
|
+
const humanise = (name)=>name.replace(/[-_]+/g, ' ').trim().replace(/^./, (c)=>c.toUpperCase());
|
|
4
|
+
function parse(value) {
|
|
5
|
+
if (!/^[[{]/.test(value)) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(value);
|
|
10
|
+
} catch {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function format(raw, field) {
|
|
15
|
+
const value = parse(raw.trim());
|
|
16
|
+
const optionLabel = (v)=>field?.options?.find((o)=>o.value === String(v))?.label?.trim() || String(v);
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
return {
|
|
19
|
+
value: value.map(optionLabel).join(', ')
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (value && typeof value === 'object') {
|
|
23
|
+
const record = value;
|
|
24
|
+
// Phone fields store { country, number, e164 }
|
|
25
|
+
if (typeof record.e164 === 'string' && record.e164) {
|
|
26
|
+
return {
|
|
27
|
+
href: `tel:${record.e164}`,
|
|
28
|
+
value: [
|
|
29
|
+
record.country,
|
|
30
|
+
record.number
|
|
31
|
+
].filter(Boolean).join(' ')
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
value: Object.entries(record).filter(([, v])=>v !== '' && v !== null && v !== undefined).map(([k, v])=>{
|
|
36
|
+
const counter = field?.counters?.find((c)=>c.name === k);
|
|
37
|
+
return `${counter?.label?.trim() || humanise(k)}: ${String(v)}`;
|
|
38
|
+
}).join(' · ')
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const text = String(value);
|
|
42
|
+
if (!text) {
|
|
43
|
+
return {
|
|
44
|
+
value: ''
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (field?.blockType === 'travelDate') {
|
|
48
|
+
return {
|
|
49
|
+
value: parseTravelDate(text)?.label ?? text
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (field?.blockType === 'checkbox' || field?.blockType === 'yesNo') {
|
|
53
|
+
if (text === 'true') {
|
|
54
|
+
return {
|
|
55
|
+
value: 'Yes'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (text === 'false') {
|
|
59
|
+
return {
|
|
60
|
+
value: 'No'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!/\s/.test(text) && /^[^@]+@[^@]+$/.test(text)) {
|
|
65
|
+
return {
|
|
66
|
+
href: `mailto:${text}`,
|
|
67
|
+
value: text
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
value: optionLabel(text)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* How an answer is corrected in the admin: a choice from the form's options, Yes/No, or text.
|
|
76
|
+
* Structured answers (phone, counters, address) are stored as JSON and are left alone.
|
|
77
|
+
*/ function editFor(raw, index, field) {
|
|
78
|
+
if (typeof parse(raw.trim()) === 'object') {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const path = `data.${index}.value`;
|
|
82
|
+
if (field?.blockType === 'checkbox' || field?.blockType === 'yesNo') {
|
|
83
|
+
return {
|
|
84
|
+
options: [
|
|
85
|
+
{
|
|
86
|
+
label: 'Yes',
|
|
87
|
+
value: 'true'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
label: 'No',
|
|
91
|
+
value: 'false'
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
path
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const options = field?.options?.filter((o)=>o.value).map((o)=>({
|
|
98
|
+
label: o.label?.trim() || o.value,
|
|
99
|
+
value: o.value
|
|
100
|
+
}));
|
|
101
|
+
if (options?.length) {
|
|
102
|
+
// Keep an answer the form no longer offers, so opening the editor doesn't change it.
|
|
103
|
+
if (raw && !options.some((o)=>o.value === raw)) {
|
|
104
|
+
options.push({
|
|
105
|
+
label: raw,
|
|
106
|
+
value: raw
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
options,
|
|
111
|
+
path
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
multiline: field?.blockType === 'textarea' || raw.length > 80,
|
|
116
|
+
path
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function collect(fields, into) {
|
|
120
|
+
for (const field of fields ?? []){
|
|
121
|
+
if (field.name) {
|
|
122
|
+
into.set(field.name, field);
|
|
123
|
+
}
|
|
124
|
+
collect(field.fields, into);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Pairs each stored answer with its question on the form: labelled, option values shown as their
|
|
129
|
+
* labels, JSON answers (phone, counters, address) spelled out. Grouped by step on multi-step forms;
|
|
130
|
+
* answers the form no longer has (or never had, e.g. added by the site) come last.
|
|
131
|
+
*/ export function describeSubmission(form, rows) {
|
|
132
|
+
const byName = new Map();
|
|
133
|
+
for (const [index, row] of (rows ?? []).entries()){
|
|
134
|
+
if (row.fieldName) {
|
|
135
|
+
byName.set(row.fieldName, {
|
|
136
|
+
index,
|
|
137
|
+
value: row.value ?? ''
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const answer = (name, field)=>{
|
|
142
|
+
const { index, value: raw } = byName.get(name);
|
|
143
|
+
const shown = format(raw, field);
|
|
144
|
+
return {
|
|
145
|
+
name,
|
|
146
|
+
label: field?.label?.trim() || humanise(name),
|
|
147
|
+
...shown,
|
|
148
|
+
edit: editFor(raw, index, field),
|
|
149
|
+
wide: shown.value.length > 80 || field?.blockType === 'textarea'
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const sections = form?.steps?.length ? form.steps.map((step)=>({
|
|
153
|
+
fields: step.fields,
|
|
154
|
+
title: step.title?.trim() || undefined
|
|
155
|
+
})) : [
|
|
156
|
+
{
|
|
157
|
+
fields: form?.fields,
|
|
158
|
+
title: undefined
|
|
159
|
+
}
|
|
160
|
+
];
|
|
161
|
+
const groups = [];
|
|
162
|
+
const used = new Set();
|
|
163
|
+
for (const section of sections){
|
|
164
|
+
const fields = new Map();
|
|
165
|
+
collect(section.fields, fields);
|
|
166
|
+
const answers = [];
|
|
167
|
+
for (const [name, field] of fields){
|
|
168
|
+
if (!byName.has(name) || used.has(name)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
used.add(name);
|
|
172
|
+
answers.push(answer(name, field));
|
|
173
|
+
}
|
|
174
|
+
if (answers.length) {
|
|
175
|
+
groups.push({
|
|
176
|
+
answers,
|
|
177
|
+
title: section.title
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const rest = [
|
|
182
|
+
...byName.keys()
|
|
183
|
+
].filter((name)=>!used.has(name)).map((name)=>answer(name));
|
|
184
|
+
if (rest.length) {
|
|
185
|
+
groups.push({
|
|
186
|
+
answers: rest,
|
|
187
|
+
title: groups.length ? 'Other answers' : undefined
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return groups;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A readable title for a submission: the person's name, else their email, else the date.
|
|
194
|
+
* Looks for answers named like "name", "full-name" or "first-name" + "last-name", and "email".
|
|
195
|
+
*/ export function submissionTitle(doc) {
|
|
196
|
+
const answers = new Map();
|
|
197
|
+
for (const row of doc.data ?? []){
|
|
198
|
+
const value = row.value?.trim();
|
|
199
|
+
if (row.fieldName && value) {
|
|
200
|
+
answers.set(key(row.fieldName), value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const name = answers.get('name') || answers.get('fullname') || answers.get('yourname') || [
|
|
204
|
+
answers.get('firstname'),
|
|
205
|
+
answers.get('lastname') || answers.get('surname')
|
|
206
|
+
].filter(Boolean).join(' ');
|
|
207
|
+
if (name) {
|
|
208
|
+
return name;
|
|
209
|
+
}
|
|
210
|
+
const email = [
|
|
211
|
+
...answers.entries()
|
|
212
|
+
].find(([k, v])=>k.includes('email') && v.includes('@'));
|
|
213
|
+
if (email) {
|
|
214
|
+
return email[1];
|
|
215
|
+
}
|
|
216
|
+
const date = doc.submittedAt || doc.createdAt;
|
|
217
|
+
return date ? new Date(date).toLocaleString('en-GB', {
|
|
218
|
+
dateStyle: 'medium',
|
|
219
|
+
timeStyle: 'short',
|
|
220
|
+
timeZone: 'Europe/London'
|
|
221
|
+
}) : 'Submission';
|
|
222
|
+
}
|
|
223
|
+
const CONTEXT_LABELS = {
|
|
224
|
+
fbclid: 'Facebook click ID',
|
|
225
|
+
gclid: 'Google click ID',
|
|
226
|
+
msclkid: 'Microsoft click ID'
|
|
227
|
+
};
|
|
228
|
+
const contextLabel = (key)=>CONTEXT_LABELS[key] || humanise(key).replace(/^Utm /, 'UTM ');
|
|
229
|
+
const asLink = (value)=>/^https?:\/\//.test(value) ? value : undefined;
|
|
230
|
+
/**
|
|
231
|
+
* The request a submission came with (page, IP, browser) and its context, flattened: each object
|
|
232
|
+
* in the context becomes its own group, e.g. the `hidden` tracking values.
|
|
233
|
+
*/ export function describeDetails(doc) {
|
|
234
|
+
const meta = doc.metadata ?? {};
|
|
235
|
+
const visit = [
|
|
236
|
+
{
|
|
237
|
+
href: asLink(meta.referrer ?? ''),
|
|
238
|
+
label: 'Sent from',
|
|
239
|
+
value: meta.referrer ?? ''
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
label: 'IP address',
|
|
243
|
+
value: meta.ip ?? ''
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
label: 'Browser',
|
|
247
|
+
value: meta.userAgent ?? '',
|
|
248
|
+
wide: true
|
|
249
|
+
}
|
|
250
|
+
];
|
|
251
|
+
const groups = [
|
|
252
|
+
{
|
|
253
|
+
items: visit
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
const toItem = ([key, value])=>{
|
|
257
|
+
const text = typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value ?? '');
|
|
258
|
+
return {
|
|
259
|
+
href: asLink(text),
|
|
260
|
+
label: contextLabel(key),
|
|
261
|
+
value: text,
|
|
262
|
+
wide: text.length > 80
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
const top = [];
|
|
266
|
+
for (const [key, value] of Object.entries(doc.context ?? {})){
|
|
267
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
268
|
+
const items = Object.entries(value).map(toItem);
|
|
269
|
+
if (items.length) {
|
|
270
|
+
groups.push({
|
|
271
|
+
items,
|
|
272
|
+
title: key === 'hidden' ? 'Tracking' : humanise(key)
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
top.push(toItem([
|
|
277
|
+
key,
|
|
278
|
+
value
|
|
279
|
+
]));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (top.length) {
|
|
283
|
+
groups.splice(1, 0, {
|
|
284
|
+
items: top,
|
|
285
|
+
title: 'Context'
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return groups;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
//# sourceMappingURL=describeSubmission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/describeSubmission.ts"],"sourcesContent":["import { parseTravelDate } from './travelDate.js';\n\ntype Row = { fieldName?: null | string; value?: null | string };\n\ntype FieldLike = {\n blockType?: string;\n counters?: { label?: null | string; name?: null | string }[] | null;\n fields?: FieldLike[] | null;\n label?: null | string;\n name?: null | string;\n options?: { label?: null | string; value?: null | string }[] | null;\n};\n\ntype FormLike = {\n fields?: FieldLike[] | null;\n steps?: { fields?: FieldLike[] | null; title?: null | string }[] | null;\n} | null;\n\nexport type PanelItem = {\n /** Set when the value can be changed in the admin: the form path and how to edit it. */\n edit?: {\n multiline?: boolean;\n options?: { label: string; value: string }[];\n path: string;\n };\n /** `mailto:`, `tel:` or web link for the value, when it is one. */\n href?: string;\n label: string;\n tone?: 'bad' | 'good';\n value: string;\n /** Takes the full row: long text. */\n wide?: boolean;\n};\n\nexport type PanelGroup = { items: PanelItem[]; title?: string };\n\nexport type Answer = { name: string } & PanelItem;\n\nexport type AnswerGroup = { answers: Answer[]; title?: string };\n\nconst key = (name: string) => name.toLowerCase().replace(/[^a-z]/g, '');\n\nconst humanise = (name: string) =>\n name\n .replace(/[-_]+/g, ' ')\n .trim()\n .replace(/^./, c => c.toUpperCase());\n\nfunction parse(value: string): unknown {\n if (!/^[[{]/.test(value)) {\n return value;\n }\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nfunction format(\n raw: string,\n field?: FieldLike\n): Pick<Answer, 'href' | 'value'> {\n const value = parse(raw.trim());\n const optionLabel = (v: unknown) =>\n field?.options?.find(o => o.value === String(v))?.label?.trim() ||\n String(v);\n\n if (Array.isArray(value)) {\n return { value: value.map(optionLabel).join(', ') };\n }\n\n if (value && typeof value === 'object') {\n const record = value as Record<string, unknown>;\n // Phone fields store { country, number, e164 }\n if (typeof record.e164 === 'string' && record.e164) {\n return {\n href: `tel:${record.e164}`,\n value: [record.country, record.number].filter(Boolean).join(' '),\n };\n }\n return {\n value: Object.entries(record)\n .filter(([, v]) => v !== '' && v !== null && v !== undefined)\n .map(([k, v]) => {\n const counter = field?.counters?.find(c => c.name === k);\n return `${counter?.label?.trim() || humanise(k)}: ${String(v)}`;\n })\n .join(' · '),\n };\n }\n\n const text = String(value);\n if (!text) {\n return { value: '' };\n }\n if (field?.blockType === 'travelDate') {\n return { value: parseTravelDate(text)?.label ?? text };\n }\n if (field?.blockType === 'checkbox' || field?.blockType === 'yesNo') {\n if (text === 'true') {\n return { value: 'Yes' };\n }\n if (text === 'false') {\n return { value: 'No' };\n }\n }\n if (!/\\s/.test(text) && /^[^@]+@[^@]+$/.test(text)) {\n return { href: `mailto:${text}`, value: text };\n }\n return { value: optionLabel(text) };\n}\n\n/**\n * How an answer is corrected in the admin: a choice from the form's options, Yes/No, or text.\n * Structured answers (phone, counters, address) are stored as JSON and are left alone.\n */\nfunction editFor(\n raw: string,\n index: number,\n field?: FieldLike\n): PanelItem['edit'] {\n if (typeof parse(raw.trim()) === 'object') {\n return undefined;\n }\n const path = `data.${index}.value`;\n if (field?.blockType === 'checkbox' || field?.blockType === 'yesNo') {\n return {\n options: [\n { label: 'Yes', value: 'true' },\n { label: 'No', value: 'false' },\n ],\n path,\n };\n }\n const options = field?.options\n ?.filter(o => o.value)\n .map(o => ({ label: o.label?.trim() || o.value!, value: o.value! }));\n if (options?.length) {\n // Keep an answer the form no longer offers, so opening the editor doesn't change it.\n if (raw && !options.some(o => o.value === raw)) {\n options.push({ label: raw, value: raw });\n }\n return { options, path };\n }\n return {\n multiline: field?.blockType === 'textarea' || raw.length > 80,\n path,\n };\n}\n\nfunction collect(\n fields: FieldLike[] | null | undefined,\n into: Map<string, FieldLike>\n) {\n for (const field of fields ?? []) {\n if (field.name) {\n into.set(field.name, field);\n }\n collect(field.fields, into);\n }\n}\n\n/**\n * Pairs each stored answer with its question on the form: labelled, option values shown as their\n * labels, JSON answers (phone, counters, address) spelled out. Grouped by step on multi-step forms;\n * answers the form no longer has (or never had, e.g. added by the site) come last.\n */\nexport function describeSubmission(\n form: FormLike,\n rows: null | Row[] | undefined\n): AnswerGroup[] {\n const byName = new Map<string, { index: number; value: string }>();\n for (const [index, row] of (rows ?? []).entries()) {\n if (row.fieldName) {\n byName.set(row.fieldName, { index, value: row.value ?? '' });\n }\n }\n\n const answer = (name: string, field?: FieldLike): Answer => {\n const { index, value: raw } = byName.get(name)!;\n const shown = format(raw, field);\n return {\n name,\n label: field?.label?.trim() || humanise(name),\n ...shown,\n edit: editFor(raw, index, field),\n wide: shown.value.length > 80 || field?.blockType === 'textarea',\n };\n };\n\n const sections = form?.steps?.length\n ? form.steps.map(step => ({\n fields: step.fields,\n title: step.title?.trim() || undefined,\n }))\n : [{ fields: form?.fields, title: undefined }];\n\n const groups: AnswerGroup[] = [];\n const used = new Set<string>();\n for (const section of sections) {\n const fields = new Map<string, FieldLike>();\n collect(section.fields, fields);\n const answers: Answer[] = [];\n for (const [name, field] of fields) {\n if (!byName.has(name) || used.has(name)) {\n continue;\n }\n used.add(name);\n answers.push(answer(name, field));\n }\n if (answers.length) {\n groups.push({ answers, title: section.title });\n }\n }\n\n const rest = [...byName.keys()]\n .filter(name => !used.has(name))\n .map(name => answer(name));\n if (rest.length) {\n groups.push({\n answers: rest,\n title: groups.length ? 'Other answers' : undefined,\n });\n }\n return groups;\n}\n\n/**\n * A readable title for a submission: the person's name, else their email, else the date.\n * Looks for answers named like \"name\", \"full-name\" or \"first-name\" + \"last-name\", and \"email\".\n */\nexport function submissionTitle(doc: {\n createdAt?: null | string;\n data?: null | Row[];\n submittedAt?: null | string;\n}): string {\n const answers = new Map<string, string>();\n for (const row of doc.data ?? []) {\n const value = row.value?.trim();\n if (row.fieldName && value) {\n answers.set(key(row.fieldName), value);\n }\n }\n\n const name =\n answers.get('name') ||\n answers.get('fullname') ||\n answers.get('yourname') ||\n [\n answers.get('firstname'),\n answers.get('lastname') || answers.get('surname'),\n ]\n .filter(Boolean)\n .join(' ');\n if (name) {\n return name;\n }\n\n const email = [...answers.entries()].find(\n ([k, v]) => k.includes('email') && v.includes('@')\n );\n if (email) {\n return email[1];\n }\n\n const date = doc.submittedAt || doc.createdAt;\n return date\n ? new Date(date).toLocaleString('en-GB', {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: 'Europe/London',\n })\n : 'Submission';\n}\n\nconst CONTEXT_LABELS: Record<string, string> = {\n fbclid: 'Facebook click ID',\n gclid: 'Google click ID',\n msclkid: 'Microsoft click ID',\n};\n\nconst contextLabel = (key: string) =>\n CONTEXT_LABELS[key] || humanise(key).replace(/^Utm /, 'UTM ');\n\nconst asLink = (value: string) =>\n /^https?:\\/\\//.test(value) ? value : undefined;\n\n/**\n * The request a submission came with (page, IP, browser) and its context, flattened: each object\n * in the context becomes its own group, e.g. the `hidden` tracking values.\n */\nexport function describeDetails(doc: {\n context?: null | Record<string, unknown>;\n metadata?: {\n ip?: null | string;\n referrer?: null | string;\n userAgent?: null | string;\n } | null;\n}): PanelGroup[] {\n const meta = doc.metadata ?? {};\n const visit: PanelItem[] = [\n {\n href: asLink(meta.referrer ?? ''),\n label: 'Sent from',\n value: meta.referrer ?? '',\n },\n { label: 'IP address', value: meta.ip ?? '' },\n { label: 'Browser', value: meta.userAgent ?? '', wide: true },\n ];\n const groups: PanelGroup[] = [{ items: visit }];\n\n const toItem = ([key, value]: [string, unknown]): PanelItem => {\n const text =\n typeof value === 'object' && value !== null\n ? JSON.stringify(value)\n : String(value ?? '');\n return {\n href: asLink(text),\n label: contextLabel(key),\n value: text,\n wide: text.length > 80,\n };\n };\n const top: PanelItem[] = [];\n for (const [key, value] of Object.entries(doc.context ?? {})) {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n const items = Object.entries(value).map(toItem);\n if (items.length) {\n groups.push({\n items,\n title: key === 'hidden' ? 'Tracking' : humanise(key),\n });\n }\n } else {\n top.push(toItem([key, value]));\n }\n }\n if (top.length) {\n groups.splice(1, 0, { items: top, title: 'Context' });\n }\n return groups;\n}\n"],"names":["parseTravelDate","key","name","toLowerCase","replace","humanise","trim","c","toUpperCase","parse","value","test","JSON","format","raw","field","optionLabel","v","options","find","o","String","label","Array","isArray","map","join","record","e164","href","country","number","filter","Boolean","Object","entries","undefined","k","counter","counters","text","blockType","editFor","index","path","length","some","push","multiline","collect","fields","into","set","describeSubmission","form","rows","byName","Map","row","fieldName","answer","get","shown","edit","wide","sections","steps","step","title","groups","used","Set","section","answers","has","add","rest","keys","submissionTitle","doc","data","email","includes","date","submittedAt","createdAt","Date","toLocaleString","dateStyle","timeStyle","timeZone","CONTEXT_LABELS","fbclid","gclid","msclkid","contextLabel","asLink","describeDetails","meta","metadata","visit","referrer","ip","userAgent","items","toItem","stringify","top","context","splice"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAwClD,MAAMC,MAAM,CAACC,OAAiBA,KAAKC,WAAW,GAAGC,OAAO,CAAC,WAAW;AAEpE,MAAMC,WAAW,CAACH,OAChBA,KACGE,OAAO,CAAC,UAAU,KAClBE,IAAI,GACJF,OAAO,CAAC,MAAMG,CAAAA,IAAKA,EAAEC,WAAW;AAErC,SAASC,MAAMC,KAAa;IAC1B,IAAI,CAAC,QAAQC,IAAI,CAACD,QAAQ;QACxB,OAAOA;IACT;IACA,IAAI;QACF,OAAOE,KAAKH,KAAK,CAACC;IACpB,EAAE,OAAM;QACN,OAAOA;IACT;AACF;AAEA,SAASG,OACPC,GAAW,EACXC,KAAiB;IAEjB,MAAML,QAAQD,MAAMK,IAAIR,IAAI;IAC5B,MAAMU,cA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ACfW,OAAOX,SAAS;QACtB,OAAO;YACLmB,MAAMmE,OAAOxD;YACblB,OAAOyE,aAAa9F;YACpBS,OAAO8B;YACPwB,MAAMxB,KAAKK,MAAM,GAAG;QACtB;IACF;IACA,MAAM8D,MAAmB,EAAE;IAC3B,KAAK,MAAM,CAAC1G,KAAKS,MAAM,IAAIwB,OAAOC,OAAO,CAAC4C,IAAI6B,OAAO,IAAI,CAAC,GAAI;QAC5D,IAAIlG,SAAS,OAAOA,UAAU,YAAY,CAACa,MAAMC,OAAO,CAACd,QAAQ;YAC/D,MAAM8F,QAAQtE,OAAOC,OAAO,CAACzB,OAAOe,GAAG,CAACgF;YACxC,IAAID,MAAM3D,MAAM,EAAE;gBAChBwB,OAAOtB,IAAI,CAAC;oBACVyD;oBACApC,OAAOnE,QAAQ,WAAW,aAAaI,SAASJ;gBAClD;YACF;QACF,OAAO;YACL0G,IAAI5D,IAAI,CAAC0D,OAAO;gBAACxG;gBAAKS;aAAM;QAC9B;IACF;IACA,IAAIiG,IAAI9D,MAAM,EAAE;QACdwB,OAAOwC,MAAM,CAAC,GAAG,GAAG;YAAEL,OAAOG;YAAKvC,OAAO;QAAU;IACrD;IACA,OAAOC;AACT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { buildFormURL } from './buildFormURL.js';
|
|
2
|
+
export async function fetchForm({ slug, baseUrl, formsSlug }) {
|
|
3
|
+
const url = buildFormURL({
|
|
4
|
+
slug,
|
|
5
|
+
baseUrl,
|
|
6
|
+
formsSlug
|
|
7
|
+
});
|
|
8
|
+
const res = await fetch(url, {
|
|
9
|
+
next: {
|
|
10
|
+
revalidate: 0
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
throw new Error(`Failed to fetch form "${slug}": ${res.status} ${res.statusText}`);
|
|
15
|
+
}
|
|
16
|
+
return res.json();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=fetchEnquiryForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/fetchEnquiryForm.ts"],"sourcesContent":["import type { FormDocument } from '../types.js';\nimport { buildFormURL } from './buildFormURL.js';\n\nexport async function fetchForm({\n slug,\n baseUrl,\n formsSlug,\n}: {\n slug: string;\n baseUrl?: string;\n formsSlug?: string;\n}): Promise<FormDocument> {\n const url = buildFormURL({ slug, baseUrl, formsSlug });\n const res = await fetch(url, { next: { revalidate: 0 } } as RequestInit);\n if (!res.ok) {\n throw new Error(\n `Failed to fetch form \"${slug}\": ${res.status} ${res.statusText}`\n );\n }\n return res.json() as Promise<FormDocument>;\n}\n"],"names":["buildFormURL","fetchForm","slug","baseUrl","formsSlug","url","res","fetch","next","revalidate","ok","Error","status","statusText","json"],"mappings":"AACA,SAASA,YAAY,QAAQ,oBAAoB;AAEjD,OAAO,eAAeC,UAAU,EAC9BC,IAAI,EACJC,OAAO,EACPC,SAAS,EAKV;IACC,MAAMC,MAAML,aAAa;QAAEE;QAAMC;QAASC;IAAU;IACpD,MAAME,MAAM,MAAMC,MAAMF,KAAK;QAAEG,MAAM;YAAEC,YAAY;QAAE;IAAE;IACvD,IAAI,CAACH,IAAII,EAAE,EAAE;QACX,MAAM,IAAIC,MACR,CAAC,sBAAsB,EAAET,KAAK,GAAG,EAAEI,IAAIM,MAAM,CAAC,CAAC,EAAEN,IAAIO,UAAU,EAAE;IAErE;IACA,OAAOP,IAAIQ,IAAI;AACjB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the flag SVGs are served from.
|
|
3
|
+
*
|
|
4
|
+
* The 257 files ship in this package under `dist/assets/flags`, but a package
|
|
5
|
+
* cannot serve static files — the consuming app has to. Copy them somewhere
|
|
6
|
+
* public (Turquoise puts them in `public/flags`) and, if that is not `/flags`,
|
|
7
|
+
* call `setFlagBasePath` once at startup.
|
|
8
|
+
*
|
|
9
|
+
* They are files rather than inlined data URIs on purpose: all 257 come to
|
|
10
|
+
* 286KB, which is far too much to put in a form's JavaScript when a visitor
|
|
11
|
+
* sees at most a few dozen. As files the browser fetches only the flags it
|
|
12
|
+
* draws, and caches them.
|
|
13
|
+
*/ let basePath = '/flags';
|
|
14
|
+
export const setFlagBasePath = (path)=>{
|
|
15
|
+
basePath = path.replace(/\/+$/, '');
|
|
16
|
+
};
|
|
17
|
+
export const flagSrc = (code)=>`${basePath}/${code.toUpperCase()}.svg`;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=flagAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/flagAssets.ts"],"sourcesContent":["/**\n * Where the flag SVGs are served from.\n *\n * The 257 files ship in this package under `dist/assets/flags`, but a package\n * cannot serve static files — the consuming app has to. Copy them somewhere\n * public (Turquoise puts them in `public/flags`) and, if that is not `/flags`,\n * call `setFlagBasePath` once at startup.\n *\n * They are files rather than inlined data URIs on purpose: all 257 come to\n * 286KB, which is far too much to put in a form's JavaScript when a visitor\n * sees at most a few dozen. As files the browser fetches only the flags it\n * draws, and caches them.\n */\nlet basePath = '/flags';\n\nexport const setFlagBasePath = (path: string): void => {\n basePath = path.replace(/\\/+$/, '');\n};\n\nexport const flagSrc = (code: string): string =>\n `${basePath}/${code.toUpperCase()}.svg`;\n"],"names":["basePath","setFlagBasePath","path","replace","flagSrc","code","toUpperCase"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GACD,IAAIA,WAAW;AAEf,OAAO,MAAMC,kBAAkB,CAACC;IAC9BF,WAAWE,KAAKC,OAAO,CAAC,QAAQ;AAClC,EAAE;AAEF,OAAO,MAAMC,UAAU,CAACC,OACtB,GAAGL,SAAS,CAAC,EAAEK,KAAKC,WAAW,GAAG,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UK postcode lookup, backed by postcodes.io.
|
|
3
|
+
*
|
|
4
|
+
* postcodes.io is a free, open service over Royal Mail's PAF-derived ONS data.
|
|
5
|
+
* It needs no API key and bills nobody per call, which is why it is used here
|
|
6
|
+
* rather than a metered provider: an address field can be dropped onto any
|
|
7
|
+
* public form without anyone having to watch a lookup quota.
|
|
8
|
+
*
|
|
9
|
+
* It resolves a postcode to its town/county/country only — it does not return
|
|
10
|
+
* a list of premises, so the street and building still have to be typed. The
|
|
11
|
+
* field is always usable manually.
|
|
12
|
+
*/
|
|
13
|
+
export type PostcodeAddress = {
|
|
14
|
+
postcode: string;
|
|
15
|
+
city: string;
|
|
16
|
+
county: string;
|
|
17
|
+
country: string;
|
|
18
|
+
};
|
|
19
|
+
export type PostcodeLookup = {
|
|
20
|
+
status: 'ok';
|
|
21
|
+
address: PostcodeAddress;
|
|
22
|
+
} | {
|
|
23
|
+
status: 'notFound';
|
|
24
|
+
} | {
|
|
25
|
+
status: 'error';
|
|
26
|
+
};
|
|
27
|
+
/** postcodes.io returns place names upper-cased; forms want them readable. */
|
|
28
|
+
export declare function toTitleCase(value: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Look up a postcode. Never throws — a network failure, a non-JSON body or an
|
|
31
|
+
* unknown postcode all resolve to a status the caller can render.
|
|
32
|
+
*
|
|
33
|
+
* `fetchImpl` exists so tests can drive it without a network.
|
|
34
|
+
*/
|
|
35
|
+
export declare function lookupPostcode(postcode: string, { fetchImpl }?: {
|
|
36
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
37
|
+
}): Promise<PostcodeLookup>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UK postcode lookup, backed by postcodes.io.
|
|
3
|
+
*
|
|
4
|
+
* postcodes.io is a free, open service over Royal Mail's PAF-derived ONS data.
|
|
5
|
+
* It needs no API key and bills nobody per call, which is why it is used here
|
|
6
|
+
* rather than a metered provider: an address field can be dropped onto any
|
|
7
|
+
* public form without anyone having to watch a lookup quota.
|
|
8
|
+
*
|
|
9
|
+
* It resolves a postcode to its town/county/country only — it does not return
|
|
10
|
+
* a list of premises, so the street and building still have to be typed. The
|
|
11
|
+
* field is always usable manually.
|
|
12
|
+
*/ const ENDPOINT = 'https://api.postcodes.io/postcodes';
|
|
13
|
+
/** postcodes.io returns place names upper-cased; forms want them readable. */ export function toTitleCase(value) {
|
|
14
|
+
return value.toLowerCase().replace(/\b\w/g, (c)=>c.toUpperCase());
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Look up a postcode. Never throws — a network failure, a non-JSON body or an
|
|
18
|
+
* unknown postcode all resolve to a status the caller can render.
|
|
19
|
+
*
|
|
20
|
+
* `fetchImpl` exists so tests can drive it without a network.
|
|
21
|
+
*/ export async function lookupPostcode(postcode, { fetchImpl = globalThis.fetch } = {}) {
|
|
22
|
+
const cleaned = postcode.trim();
|
|
23
|
+
if (!cleaned) return {
|
|
24
|
+
status: 'notFound'
|
|
25
|
+
};
|
|
26
|
+
try {
|
|
27
|
+
const res = await fetchImpl(`${ENDPOINT}/${encodeURIComponent(cleaned)}`);
|
|
28
|
+
const body = await res.json();
|
|
29
|
+
if (body?.status !== 200 || !body.result) return {
|
|
30
|
+
status: 'notFound'
|
|
31
|
+
};
|
|
32
|
+
const { postcode: formatted, postal_town, admin_district, admin_county, country } = body.result;
|
|
33
|
+
return {
|
|
34
|
+
status: 'ok',
|
|
35
|
+
address: {
|
|
36
|
+
postcode: formatted || cleaned.toUpperCase(),
|
|
37
|
+
city: toTitleCase(postal_town || admin_district || ''),
|
|
38
|
+
county: toTitleCase(admin_county || admin_district || ''),
|
|
39
|
+
country: country || 'United Kingdom'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
} catch {
|
|
43
|
+
return {
|
|
44
|
+
status: 'error'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=lookupPostcode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/lookupPostcode.ts"],"sourcesContent":["/**\n * UK postcode lookup, backed by postcodes.io.\n *\n * postcodes.io is a free, open service over Royal Mail's PAF-derived ONS data.\n * It needs no API key and bills nobody per call, which is why it is used here\n * rather than a metered provider: an address field can be dropped onto any\n * public form without anyone having to watch a lookup quota.\n *\n * It resolves a postcode to its town/county/country only — it does not return\n * a list of premises, so the street and building still have to be typed. The\n * field is always usable manually.\n */\n\nconst ENDPOINT = 'https://api.postcodes.io/postcodes';\n\nexport type PostcodeAddress = {\n postcode: string;\n city: string;\n county: string;\n country: string;\n};\n\nexport type PostcodeLookup =\n | { status: 'ok'; address: PostcodeAddress }\n | { status: 'notFound' }\n | { status: 'error' };\n\ntype PostcodesIOResponse = {\n status: number;\n result: {\n postcode?: string | null;\n postal_town?: string | null;\n admin_district?: string | null;\n admin_county?: string | null;\n country?: string | null;\n } | null;\n};\n\n/** postcodes.io returns place names upper-cased; forms want them readable. */\nexport function toTitleCase(value: string): string {\n return value.toLowerCase().replace(/\\b\\w/g, c => c.toUpperCase());\n}\n\n/**\n * Look up a postcode. Never throws — a network failure, a non-JSON body or an\n * unknown postcode all resolve to a status the caller can render.\n *\n * `fetchImpl` exists so tests can drive it without a network.\n */\nexport async function lookupPostcode(\n postcode: string,\n { fetchImpl = globalThis.fetch }: { fetchImpl?: typeof globalThis.fetch } = {}\n): Promise<PostcodeLookup> {\n const cleaned = postcode.trim();\n if (!cleaned) return { status: 'notFound' };\n\n try {\n const res = await fetchImpl(`${ENDPOINT}/${encodeURIComponent(cleaned)}`);\n const body = (await res.json()) as PostcodesIOResponse;\n\n if (body?.status !== 200 || !body.result) return { status: 'notFound' };\n\n const {\n postcode: formatted,\n postal_town,\n admin_district,\n admin_county,\n country,\n } = body.result;\n\n return {\n status: 'ok',\n address: {\n postcode: formatted || cleaned.toUpperCase(),\n city: toTitleCase(postal_town || admin_district || ''),\n county: toTitleCase(admin_county || admin_district || ''),\n country: country || 'United Kingdom',\n },\n };\n } catch {\n return { status: 'error' };\n }\n}\n"],"names":["ENDPOINT","toTitleCase","value","toLowerCase","replace","c","toUpperCase","lookupPostcode","postcode","fetchImpl","globalThis","fetch","cleaned","trim","status","res","encodeURIComponent","body","json","result","formatted","postal_town","admin_district","admin_county","country","address","city","county"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,MAAMA,WAAW;AAyBjB,4EAA4E,GAC5E,OAAO,SAASC,YAAYC,KAAa;IACvC,OAAOA,MAAMC,WAAW,GAAGC,OAAO,CAAC,SAASC,CAAAA,IAAKA,EAAEC,WAAW;AAChE;AAEA;;;;;CAKC,GACD,OAAO,eAAeC,eACpBC,QAAgB,EAChB,EAAEC,YAAYC,WAAWC,KAAK,EAA2C,GAAG,CAAC,CAAC;IAE9E,MAAMC,UAAUJ,SAASK,IAAI;IAC7B,IAAI,CAACD,SAAS,OAAO;QAAEE,QAAQ;IAAW;IAE1C,IAAI;QACF,MAAMC,MAAM,MAAMN,UAAU,GAAGT,SAAS,CAAC,EAAEgB,mBAAmBJ,UAAU;QACxE,MAAMK,OAAQ,MAAMF,IAAIG,IAAI;QAE5B,IAAID,MAAMH,WAAW,OAAO,CAACG,KAAKE,MAAM,EAAE,OAAO;YAAEL,QAAQ;QAAW;QAEtE,MAAM,EACJN,UAAUY,SAAS,EACnBC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,OAAO,EACR,GAAGP,KAAKE,MAAM;QAEf,OAAO;YACLL,QAAQ;YACRW,SAAS;gBACPjB,UAAUY,aAAaR,QAAQN,WAAW;gBAC1CoB,MAAMzB,YAAYoB,eAAeC,kBAAkB;gBACnDK,QAAQ1B,YAAYsB,gBAAgBD,kBAAkB;gBACtDE,SAASA,WAAW;YACtB;QACF;IACF,EAAE,OAAM;QACN,OAAO;YAAEV,QAAQ;QAAQ;IAC3B;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FormDocument, FormFieldBlock, FormStep } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shape accepted by {@link normalizeFormSteps}. A form can store its fields in
|
|
4
|
+
* one of two ways:
|
|
5
|
+
*
|
|
6
|
+
* - **Single-stage** (default): a flat `fields` array on the document, with
|
|
7
|
+
* `multiStep` falsy.
|
|
8
|
+
* - **Multi-stage**: a `steps` array, each step carrying its own `fields`,
|
|
9
|
+
* with `multiStep` truthy.
|
|
10
|
+
*/
|
|
11
|
+
type NormalizableForm = Partial<Pick<FormDocument, 'multiStep' | 'steps' | 'title'>> & {
|
|
12
|
+
fields?: FormFieldBlock[] | null;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Collapse a form document into the canonical `FormStep[]` shape the runtime
|
|
16
|
+
* (and public API response) always expects, regardless of how it was authored
|
|
17
|
+
* in the admin.
|
|
18
|
+
*
|
|
19
|
+
* Multi-stage forms pass their `steps` through unchanged. Single-stage forms
|
|
20
|
+
* are wrapped into a single synthetic step using their top-level `fields`. For
|
|
21
|
+
* backwards-compatibility with forms authored before the single-stage option
|
|
22
|
+
* existed, a form with no top-level `fields` falls back to any `steps` present.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeFormSteps(form: NormalizableForm): FormStep[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapse a form document into the canonical `FormStep[]` shape the runtime
|
|
3
|
+
* (and public API response) always expects, regardless of how it was authored
|
|
4
|
+
* in the admin.
|
|
5
|
+
*
|
|
6
|
+
* Multi-stage forms pass their `steps` through unchanged. Single-stage forms
|
|
7
|
+
* are wrapped into a single synthetic step using their top-level `fields`. For
|
|
8
|
+
* backwards-compatibility with forms authored before the single-stage option
|
|
9
|
+
* existed, a form with no top-level `fields` falls back to any `steps` present.
|
|
10
|
+
*/ export function normalizeFormSteps(form) {
|
|
11
|
+
if (form.multiStep) {
|
|
12
|
+
return form.steps ?? [];
|
|
13
|
+
}
|
|
14
|
+
const fields = form.fields ?? [];
|
|
15
|
+
if (fields.length === 0 && (form.steps?.length ?? 0) > 0) {
|
|
16
|
+
// Legacy document authored as steps before single-stage existed.
|
|
17
|
+
return form.steps;
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
title: form.title ?? '',
|
|
22
|
+
fields
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=normalizeFormSteps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/normalizeFormSteps.ts"],"sourcesContent":["import type { FormDocument, FormFieldBlock, FormStep } from '../types.js';\n\n/**\n * Shape accepted by {@link normalizeFormSteps}. A form can store its fields in\n * one of two ways:\n *\n * - **Single-stage** (default): a flat `fields` array on the document, with\n * `multiStep` falsy.\n * - **Multi-stage**: a `steps` array, each step carrying its own `fields`,\n * with `multiStep` truthy.\n */\ntype NormalizableForm = Partial<\n Pick<FormDocument, 'multiStep' | 'steps' | 'title'>\n> & {\n fields?: FormFieldBlock[] | null;\n};\n\n/**\n * Collapse a form document into the canonical `FormStep[]` shape the runtime\n * (and public API response) always expects, regardless of how it was authored\n * in the admin.\n *\n * Multi-stage forms pass their `steps` through unchanged. Single-stage forms\n * are wrapped into a single synthetic step using their top-level `fields`. For\n * backwards-compatibility with forms authored before the single-stage option\n * existed, a form with no top-level `fields` falls back to any `steps` present.\n */\nexport function normalizeFormSteps(form: NormalizableForm): FormStep[] {\n if (form.multiStep) {\n return form.steps ?? [];\n }\n\n const fields = form.fields ?? [];\n if (fields.length === 0 && (form.steps?.length ?? 0) > 0) {\n // Legacy document authored as steps before single-stage existed.\n return form.steps as FormStep[];\n }\n\n return [\n {\n title: form.title ?? '',\n fields,\n },\n ];\n}\n"],"names":["normalizeFormSteps","form","multiStep","steps","fields","length","title"],"mappings":"AAiBA;;;;;;;;;CASC,GACD,OAAO,SAASA,mBAAmBC,IAAsB;IACvD,IAAIA,KAAKC,SAAS,EAAE;QAClB,OAAOD,KAAKE,KAAK,IAAI,EAAE;IACzB;IAEA,MAAMC,SAASH,KAAKG,MAAM,IAAI,EAAE;IAChC,IAAIA,OAAOC,MAAM,KAAK,KAAK,AAACJ,CAAAA,KAAKE,KAAK,EAAEE,UAAU,CAAA,IAAK,GAAG;QACxD,iEAAiE;QACjE,OAAOJ,KAAKE,KAAK;IACnB;IAEA,OAAO;QACL;YACEG,OAAOL,KAAKK,KAAK,IAAI;YACrBF;QACF;KACD;AACH"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SubmitError } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Coerce whatever the submit endpoint returned into a well-formed `SubmitError`.
|
|
4
|
+
*
|
|
5
|
+
* The handler's intended error responses are already `{ success: false, errors }`,
|
|
6
|
+
* but unexpected responses (a Payload `{ message }` 404, a 500, or a non-JSON
|
|
7
|
+
* body parsed as `null`) lack an `errors` array. Normalising here means the UI
|
|
8
|
+
* always has `errors` to render and never crashes on `error.errors.map`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeSubmitError(payload: unknown): SubmitError;
|