@overturo/js 1.5.1 → 1.5.2

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.
@@ -1,2 +1,2 @@
1
- "use strict";var OverturoField=(()=>{var X=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var De=Object.prototype.hasOwnProperty;var fe=t=>{throw TypeError(t)};var je=(t,s)=>()=>{try{return s||t((s={exports:{}}).exports,s),s.exports}catch(i){throw s=0,i}},Le=(t,s)=>{for(var i in s)X(t,i,{get:s[i],enumerable:!0})},Ce=(t,s,i,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let p of Re(s))!De.call(t,p)&&p!==i&&X(t,p,{get:()=>s[p],enumerable:!(a=Se(s,p))||a.enumerable});return t};var Oe=t=>Ce(X({},"__esModule",{value:!0}),t);var ee=(t,s,i)=>s.has(t)||fe("Cannot "+i);var d=(t,s,i)=>(ee(t,s,"read from private field"),i?i.call(t):s.get(t)),g=(t,s,i)=>s.has(t)?fe("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,i),f=(t,s,i,a)=>(ee(t,s,"write to private field"),a?a.call(t,i):s.set(t,i),i),h=(t,s,i)=>(ee(t,s,"access private method"),i);var oe=je(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});function _e(t){let s=t.length,i=0,a=0,p;for(;a<s;)i++,p=t.charCodeAt(a++),p>=55296&&p<=56319&&a<s&&(p=t.charCodeAt(a),(p&64512)===56320&&a++);return i}se.default=_e;_e.code='require("ajv/dist/runtime/ucs2length").default'});var et={};Le(et,{APPEARANCE_KEYS:()=>te,ConsentFieldElement:()=>P,FIELD_ALREADY_DEFINED_CODE:()=>me,FIELD_DOCUMENT_PATH:()=>j,FIELD_ELEMENT_NAME:()=>T,FIELD_MESSAGE_TYPES:()=>m,FIELD_PROTOCOL_VERSION:()=>D,FieldCaptureError:()=>_,default:()=>P,encodeAppearance:()=>L,fieldEnvelope:()=>G,registerConsentFieldElement:()=>Q,sanitiseAppearance:()=>re,validateField:()=>B,validateFieldEnvelope:()=>ne,validateFieldPayload:()=>ae});var Me={width:"100%",minHeight:"400px",maxHeight:"none",border:"none",borderRadius:"0",background:"transparent"},rt=Object.keys(Me);var he="https://overturo.com";var ye="overturo-consent-field";var D=1,T=ye,m={READY:"overturo-field:ready",STATE:"overturo-field:state",RESIZE:"overturo-field:resize",COMPLETE:"overturo-field:complete",ERROR:"overturo-field:error",SUBMIT_REQUESTED:"overturo-field:submit_requested",INIT:"overturo-field:init",CAPTURE:"overturo-field:capture",RESET:"overturo-field:reset"},j="/decisions/fields";var te=["fontFamily","fontSize","text","muted","accent","border","radius","density"];function re(t){let s={};if(!t||typeof t!="object")return s;for(let i of te){let a=t[i];typeof a=="string"&&a.length<=64&&(s[i]=a)}return s}function L(t){let s=re(t);if(Object.keys(s).length===0)return"";let i=JSON.stringify(s);return`#a=${btoa(unescape(encodeURIComponent(i))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}var ge=C,Ne={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/envelope.json",title:"Embedded consent field envelope v1",type:"object",additionalProperties:!1,required:["type","version","payload","ts","message_id"],properties:{type:{type:"string",enum:["overturo-field:ready","overturo-field:state","overturo-field:resize","overturo-field:complete","overturo-field:error","overturo-field:submit_requested","overturo-field:init","overturo-field:capture","overturo-field:reset"]},version:{type:"integer",const:1},payload:{type:"object",additionalProperties:!0},ts:{type:"string",pattern:"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"},message_id:{type:"string",pattern:"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"}}},qe=new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$","u"),Ue=new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$","u");function C(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=C.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.type===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"type"},message:"must have required property 'type'"};e===null?e=[r]:e.push(r),o++}if(t.version===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"version"},message:"must have required property 'version'"};e===null?e=[r]:e.push(r),o++}if(t.payload===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"payload"},message:"must have required property 'payload'"};e===null?e=[r]:e.push(r),o++}if(t.ts===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"ts"},message:"must have required property 'ts'"};e===null?e=[r]:e.push(r),o++}if(t.message_id===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"message_id"},message:"must have required property 'message_id'"};e===null?e=[r]:e.push(r),o++}for(let r in t)if(!(r==="type"||r==="version"||r==="payload"||r==="ts"||r==="message_id")){let n={instancePath:s,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:r},message:"must NOT have additional properties"};e===null?e=[n]:e.push(n),o++}if(t.type!==void 0){let r=t.type;if(typeof r!="string"){let n={instancePath:s+"/type",schemaPath:"#/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}if(!(r==="overturo-field:ready"||r==="overturo-field:state"||r==="overturo-field:resize"||r==="overturo-field:complete"||r==="overturo-field:error"||r==="overturo-field:submit_requested"||r==="overturo-field:init"||r==="overturo-field:capture"||r==="overturo-field:reset")){let n={instancePath:s+"/type",schemaPath:"#/properties/type/enum",keyword:"enum",params:{allowedValues:Ne.properties.type.enum},message:"must be equal to one of the allowed values"};e===null?e=[n]:e.push(n),o++}}if(t.version!==void 0){let r=t.version;if(!(typeof r=="number"&&!(r%1)&&!isNaN(r))){let n={instancePath:s+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"integer"},message:"must be integer"};e===null?e=[n]:e.push(n),o++}if(r!==1){let n={instancePath:s+"/version",schemaPath:"#/properties/version/const",keyword:"const",params:{allowedValue:1},message:"must be equal to constant"};e===null?e=[n]:e.push(n),o++}}if(t.payload!==void 0){let r=t.payload;if(!(r&&typeof r=="object"&&!Array.isArray(r))){let n={instancePath:s+"/payload",schemaPath:"#/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}if(t.ts!==void 0){let r=t.ts;if(typeof r=="string"){if(!qe.test(r)){let n={instancePath:s+"/ts",schemaPath:"#/properties/ts/pattern",keyword:"pattern",params:{pattern:"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"},message:'must match pattern "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"'};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/ts",schemaPath:"#/properties/ts/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.message_id!==void 0){let r=t.message_id;if(typeof r=="string"){if(!Ue.test(r)){let n={instancePath:s+"/message_id",schemaPath:"#/properties/message_id/pattern",keyword:"pattern",params:{pattern:"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},message:'must match pattern "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"'};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/message_id",schemaPath:"#/properties/message_id/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return C.errors=e,o===0}C.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Ee=O;function O(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=O.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return O.errors=e,o===0}O.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var be=M,Ve={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/state.json",title:"STATE payload",type:"object",additionalProperties:!0,required:["decisions"],properties:{decisions:{type:"object",additionalProperties:{type:"string",enum:["granted","declined"]}}}};function M(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=M.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.decisions===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"decisions"},message:"must have required property 'decisions'"};e===null?e=[r]:e.push(r),o++}if(t.decisions!==void 0){let r=t.decisions;if(r&&typeof r=="object"&&!Array.isArray(r))for(let n in r){let J=r[n];if(typeof J!="string"){let w={instancePath:s+"/decisions/"+n.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/decisions/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[w]:e.push(w),o++}if(!(J==="granted"||J==="declined")){let w={instancePath:s+"/decisions/"+n.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/decisions/additionalProperties/enum",keyword:"enum",params:{allowedValues:Ve.properties.decisions.additionalProperties.enum},message:"must be equal to one of the allowed values"};e===null?e=[w]:e.push(w),o++}}else{let n={instancePath:s+"/decisions",schemaPath:"#/properties/decisions/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return M.errors=e,o===0}M.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var ve=N;function N(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=N.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.height===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};e===null?e=[r]:e.push(r),o++}if(t.height!==void 0){let r=t.height;if(!(typeof r=="number"&&!(r%1)&&!isNaN(r))){let n={instancePath:s+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"integer"},message:"must be integer"};e===null?e=[n]:e.push(n),o++}if(typeof r=="number"&&(r<0||isNaN(r))){let n={instancePath:s+"/height",schemaPath:"#/properties/height/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return N.errors=e,o===0}N.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Pe=q,$e={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/complete.json",title:"COMPLETE payload (the capture token)",type:"object",additionalProperties:!0,required:["token","committed"],properties:{token:{type:"string",minLength:1},committed:{type:"boolean"},record_id:{type:["string","null"]}}},He=oe().default;function q(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=q.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.token===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"token"},message:"must have required property 'token'"};e===null?e=[r]:e.push(r),o++}if(t.committed===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"committed"},message:"must have required property 'committed'"};e===null?e=[r]:e.push(r),o++}if(t.token!==void 0){let r=t.token;if(typeof r=="string"){if(He(r)<1){let n={instancePath:s+"/token",schemaPath:"#/properties/token/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/token",schemaPath:"#/properties/token/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.committed!==void 0&&typeof t.committed!="boolean"){let r={instancePath:s+"/committed",schemaPath:"#/properties/committed/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};e===null?e=[r]:e.push(r),o++}if(t.record_id!==void 0){let r=t.record_id;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/record_id",schemaPath:"#/properties/record_id/type",keyword:"type",params:{type:$e.properties.record_id.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return q.errors=e,o===0}q.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Ae=U;var Ye=oe().default;function U(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=U.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.code===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"code"},message:"must have required property 'code'"};e===null?e=[r]:e.push(r),o++}if(t.code!==void 0){let r=t.code;if(typeof r=="string"){if(Ye(r)<1){let n={instancePath:s+"/code",schemaPath:"#/properties/code/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/code",schemaPath:"#/properties/code/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.message!==void 0&&typeof t.message!="string"){let r={instancePath:s+"/message",schemaPath:"#/properties/message/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return U.errors=e,o===0}U.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var xe=V;function V(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=V.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return V.errors=e,o===0}V.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var ke=$;function $(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=$.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.locale!==void 0&&typeof t.locale!="string"){let r={instancePath:s+"/locale",schemaPath:"#/properties/locale/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return $.errors=e,o===0}$.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Te=H,ie={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/capture.json",title:"CAPTURE payload (host \u2192 frame; what only the host knows)",type:"object",additionalProperties:!0,properties:{subject:{type:"object",additionalProperties:!0,properties:{email:{type:"string"},external_id:{type:"string"}}},page_url:{type:["string","null"]},form_id:{type:["string","null"]},submitter:{type:["string","null"]},commit:{type:"boolean"}}};function H(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=H.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.subject!==void 0){let r=t.subject;if(r&&typeof r=="object"&&!Array.isArray(r)){if(r.email!==void 0&&typeof r.email!="string"){let n={instancePath:s+"/subject/email",schemaPath:"#/properties/subject/properties/email/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}if(r.external_id!==void 0&&typeof r.external_id!="string"){let n={instancePath:s+"/subject/external_id",schemaPath:"#/properties/subject/properties/external_id/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/subject",schemaPath:"#/properties/subject/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}if(t.page_url!==void 0){let r=t.page_url;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/page_url",schemaPath:"#/properties/page_url/type",keyword:"type",params:{type:ie.properties.page_url.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.form_id!==void 0){let r=t.form_id;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/form_id",schemaPath:"#/properties/form_id/type",keyword:"type",params:{type:ie.properties.form_id.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.submitter!==void 0){let r=t.submitter;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/submitter",schemaPath:"#/properties/submitter/type",keyword:"type",params:{type:ie.properties.submitter.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.commit!==void 0&&typeof t.commit!="boolean"){let r={instancePath:s+"/commit",schemaPath:"#/properties/commit/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return H.errors=e,o===0}H.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var we=Y;function Y(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=Y.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return Y.errors=e,o===0}Y.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Be={[m.READY]:Ee,[m.STATE]:be,[m.RESIZE]:ve,[m.COMPLETE]:Pe,[m.ERROR]:Ae,[m.SUBMIT_REQUESTED]:xe,[m.INIT]:ke,[m.CAPTURE]:Te,[m.RESET]:we},Fe=ge;function ne(t){let s=Fe(t);return{valid:s,errors:s?null:Fe.errors??null}}function ae(t){let s=Be[t.type];if(!s)return{valid:!1,errors:[{message:`Unknown type ${t.type}`}]};let i=s(t.payload);return{valid:i,errors:i?null:s.errors??null}}function B(t){let s=ne(t);return s.valid?ae(t):s}function G(t,s){return{type:t,version:D,payload:s,ts:new Date().toISOString(),message_id:Ge()}}function Ge(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let s=Math.random()*16|0;return(t==="x"?s:s&3|8).toString(16)})}var le=class extends Error{constructor(s){super(s),this.name="OverturoError"}},F=class extends le{constructor(s){super(s),this.name="OverturoValidationError"}};var Ke="overturo_capture_token",K="overturoCaptured",ze=5e3,pe=new WeakMap;function Ie(t,s,i){if(pe.has(t))throw new F("duplicate_attach: this form already has a capture interception; detach it before attaching again");pe.set(t,!0);let a=!1,p=s.tokenFieldName??Ke,u=e=>{if(t.dataset[K]==="1"){delete t.dataset[K];return}if(e.preventDefault(),e.stopImmediatePropagation(),a)return;a=!0,t.querySelector(`input[name="${p}"]`)?.remove();let o=e.submitter??null;(async()=>{try{let{token:l}=await Ze(i({submitter:o}),ze);Qe(t,p,l)}catch(l){s.onError?.(l)}finally{a=!1,s.submitAfterCapture!==!1&&(t.dataset[K]="1",We(t,o))}})()};return t.addEventListener("submit",u,{capture:!0}),()=>{pe.delete(t),t.removeEventListener("submit",u,{capture:!0}),delete t.dataset[K],t.querySelector(`input[name="${p}"]`)?.remove()}}function Ze(t,s){return new Promise((i,a)=>{let p=setTimeout(()=>a(new F(`capture timed out after ${s} ms; the form submits without a capture token`)),s);t.then(u=>{clearTimeout(p),i(u)},u=>{clearTimeout(p),a(u)})})}function We(t,s){if(s&&s.isConnected&&typeof t.requestSubmit=="function")try{t.requestSubmit(s);return}catch{}typeof t.requestSubmit=="function"?t.requestSubmit():s&&typeof s.click=="function"?s.click():t.submit()}function Qe(t,s,i){let a=t.querySelector(`input[name="${s}"]`);a||(a=document.createElement("input"),a.type="hidden",a.name=s,t.appendChild(a)),a.value=i}function de(t,s){let i=t.querySelector(s);return i instanceof HTMLInputElement?i:null}var me="OVERTURO_FIELD_ELEMENT_ALREADY_DEFINED",_=class extends Error{constructor(s,i){super(i||s),this.name="FieldCaptureError",this.code=s}},b,I,y,x,v,k,S,R,E,c,z,W,Z,ue,A,ce,P=class extends HTMLElement{constructor(){super();g(this,c);g(this,b,null);g(this,I);g(this,y,null);g(this,x,null);g(this,v,"");g(this,k,!1);g(this,S,"");g(this,R,{});g(this,E,null);g(this,W,i=>{if(!d(this,y)||i.origin!==d(this,v))return;let a=d(this,y).contentWindow;if(!a||i.source!==a)return;if(!B(i.data).valid){h(this,c,A).call(this,"field:error",{code:"protocol_violation"});return}let u=i.data;switch(u.type){case m.READY:f(this,k,!0),this.setAttribute("aria-busy","false"),h(this,c,Z).call(this,m.INIT,this.getAttribute("locale")?{locale:this.getAttribute("locale")}:{}),h(this,c,A).call(this,"field:ready",{});break;case m.STATE:f(this,R,{...u.payload.decisions}),h(this,c,A).call(this,"field:state",{decisions:this.decisions});break;case m.RESIZE:{let e=u.payload.height;typeof e=="number"&&d(this,y)&&(d(this,y).style.height=`${e}px`);break}case m.COMPLETE:{let e=u.payload;h(this,c,ue).call(this,e.token);let o={token:e.token,committed:e.committed===!0,recordId:e.record_id??null};d(this,E)?.resolve(o),f(this,E,null),h(this,c,A).call(this,"field:complete",o);break}case m.ERROR:{let e=u.payload;d(this,E)?.reject(new _(e.code,e.message)),f(this,E,null),h(this,c,A).call(this,"field:error",e);break}case m.SUBMIT_REQUESTED:this.form?.requestSubmit?.();break}});if(f(this,I,this.attachShadow({mode:"open"})),typeof this.attachInternals=="function")try{f(this,b,this.attachInternals())}catch{f(this,b,null)}}get value(){return d(this,S)}get form(){return d(this,b)?.form??this.closest("form")}get decisions(){return{...d(this,R)}}get ready(){return d(this,k)}connectedCallback(){this.style.display||(this.style.display="block"),this.hasAttribute("role")||this.setAttribute("role","group"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.getAttribute("name")||"Consent choices"),this.setAttribute("aria-busy","true"),h(this,c,z).call(this)}disconnectedCallback(){h(this,c,ce).call(this)}attributeChangedCallback(i,a,p){if(!(a===p||!this.isConnected)){if(i==="name"){this.setAttribute("aria-label",p||"Consent choices"),d(this,y)&&(d(this,y).title=p||"Consent choices");return}h(this,c,ce).call(this),h(this,c,z).call(this)}}configure(i){this.setAttribute("base-url",i.flowBaseUrl.replace(/\/+$/,"")),this.setAttribute("publishable-key",i.publishableKey),this.isConnected&&!d(this,y)&&h(this,c,z).call(this)}capture(i){return new Promise((a,p)=>{if(!d(this,k)||!d(this,v)){p(new _("field_not_ready","The consent field has not finished loading."));return}if(d(this,E)){p(new _("capture_in_flight","A capture is already in progress; the first one answers."));return}f(this,E,{resolve:a,reject:p}),h(this,c,Z).call(this,m.CAPTURE,{subject:i.subject??{},page_url:i.pageUrl??null,form_id:i.formId??null,submitter:i.submitter??null,commit:i.commit===!0})})}attachTo(i,a,p){return this.getAttribute("flow")||this.setAttribute("flow",a.flowId),a.locale&&!this.getAttribute("locale")&&this.setAttribute("locale",a.locale),this.configure(p),Ie(i,a,async({submitter:u})=>{let e=de(i,a.subjectField),o=a.externalIdField?de(i,a.externalIdField):null,l=await this.capture({subject:{email:e?.value?.trim()||void 0,external_id:o?.value?.trim()||void 0},pageUrl:typeof window<"u"?window.location.href:void 0,formId:i.getAttribute("id")||void 0,submitter:u?.getAttribute("name")??null,commit:a.commit===!0}),r={token:l.token,attestationId:"",committed:l.committed,wordingVerdict:"match",recordId:l.recordId};return a.onCaptured?.(r),{token:l.token}})}reset(){h(this,c,Z).call(this,m.RESET,{}),h(this,c,ue).call(this,"")}formResetCallback(){this.reset()}};b=new WeakMap,I=new WeakMap,y=new WeakMap,x=new WeakMap,v=new WeakMap,k=new WeakMap,S=new WeakMap,R=new WeakMap,E=new WeakMap,c=new WeakSet,z=function(){let i=this.getAttribute("flow"),a=this.getAttribute("publishable-key");if(!i||!a)return;let p=(this.getAttribute("base-url")||Xe()).replace(/\/+$/,""),u=new URL(`${p}${j}/${encodeURIComponent(i)}`);u.searchParams.set("pk",a);for(let r of["locale","purposes","theme"]){let n=this.getAttribute(r);n&&u.searchParams.set(r,n)}let e=this.getAttribute("appearance");if(e)try{u.hash=L(JSON.parse(e))}catch{u.hash=""}f(this,v,u.origin);let o=document.createElement("iframe");o.src=u.toString(),o.title=this.getAttribute("name")||"Consent choices",o.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups"),o.setAttribute("referrerpolicy","strict-origin"),o.style.cssText="width:100%;height:0;border:0;display:block;background:transparent;";let l=Je();l&&o.setAttribute("nonce",l),o.addEventListener("error",()=>{h(this,c,A).call(this,"field:error",{code:"iframe_load_failed",message:"The consent field failed to load."}),this.setAttribute("aria-busy","false")}),f(this,x,new AbortController),window.addEventListener("message",d(this,W),{signal:d(this,x).signal}),f(this,y,o),d(this,I).appendChild(o)},W=new WeakMap,Z=function(i,a){let p=d(this,y)?.contentWindow;if(!(!p||!d(this,v)))try{p.postMessage(G(i,a),d(this,v))}catch{}},ue=function(i){f(this,S,i),d(this,b)&&typeof d(this,b).setFormValue=="function"&&d(this,b).setFormValue(i||null)},A=function(i,a){this.dispatchEvent(new CustomEvent(i,{detail:a,bubbles:!0,composed:!0}))},ce=function(){d(this,x)?.abort(),f(this,x,null),d(this,y)?.parentNode&&d(this,y).parentNode.removeChild(d(this,y)),f(this,y,null),f(this,k,!1),f(this,v,""),d(this,E)?.reject(new _("field_unmounted")),f(this,E,null),this.setAttribute("aria-busy","true")},P.formAssociated=!0,P.observedAttributes=["flow","purposes","locale","theme","name","appearance","publishable-key","base-url"];function Je(){return typeof document>"u"?null:document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content")??null}function Xe(){return he}function Q(){if(!(typeof customElements>"u")){if(customElements.get(T)){console.warn("[overturo:sdk]",me,`<${T}> already registered; skipping.`);return}customElements.define(T,P)}}Q();return Oe(et);})();
1
+ "use strict";var OverturoField=(()=>{var X=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var fe=t=>{throw TypeError(t)};var Le=(t,s)=>()=>{try{return s||t((s={exports:{}}).exports,s),s.exports}catch(i){throw s=0,i}},Ce=(t,s)=>{for(var i in s)X(t,i,{get:s[i],enumerable:!0})},Me=(t,s,i,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let p of De(s))!je.call(t,p)&&p!==i&&X(t,p,{get:()=>s[p],enumerable:!(a=Re(s,p))||a.enumerable});return t};var Oe=t=>Me(X({},"__esModule",{value:!0}),t);var ee=(t,s,i)=>s.has(t)||fe("Cannot "+i);var d=(t,s,i)=>(ee(t,s,"read from private field"),i?i.call(t):s.get(t)),g=(t,s,i)=>s.has(t)?fe("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,i),f=(t,s,i,a)=>(ee(t,s,"write to private field"),a?a.call(t,i):s.set(t,i),i),h=(t,s,i)=>(ee(t,s,"access private method"),i);var oe=Le(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});function _e(t){let s=t.length,i=0,a=0,p;for(;a<s;)i++,p=t.charCodeAt(a++),p>=55296&&p<=56319&&a<s&&(p=t.charCodeAt(a),(p&64512)===56320&&a++);return i}se.default=_e;_e.code='require("ajv/dist/runtime/ucs2length").default'});var tt={};Ce(tt,{APPEARANCE_KEYS:()=>te,ConsentFieldElement:()=>P,FIELD_ALREADY_DEFINED_CODE:()=>me,FIELD_DOCUMENT_PATH:()=>j,FIELD_ELEMENT_NAME:()=>k,FIELD_MESSAGE_TYPES:()=>m,FIELD_PROTOCOL_VERSION:()=>D,FieldCaptureError:()=>_,default:()=>P,encodeAppearance:()=>L,fieldEnvelope:()=>G,registerConsentFieldElement:()=>Q,sanitiseAppearance:()=>re,validateField:()=>B,validateFieldEnvelope:()=>ne,validateFieldPayload:()=>ae});var Ne={width:"100%",minHeight:"400px",maxHeight:"none",border:"none",borderRadius:"0",background:"transparent"},st=Object.keys(Ne);var he="https://overturo.com";var ye="overturo-consent-field";var D=1,k=ye,m={READY:"overturo-field:ready",STATE:"overturo-field:state",RESIZE:"overturo-field:resize",COMPLETE:"overturo-field:complete",ERROR:"overturo-field:error",SUBMIT_REQUESTED:"overturo-field:submit_requested",INIT:"overturo-field:init",CAPTURE:"overturo-field:capture",RESET:"overturo-field:reset"},j="/decisions/fields";var te=["fontFamily","fontSize","text","muted","accent","border","radius","density"];function re(t){let s={};if(!t||typeof t!="object")return s;for(let i of te){let a=t[i];typeof a=="string"&&a.length<=64&&(s[i]=a)}return s}function L(t){let s=re(t);if(Object.keys(s).length===0)return"";let i=JSON.stringify(s);return`#a=${btoa(unescape(encodeURIComponent(i))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}var ge=C,qe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/envelope.json",title:"Embedded consent field envelope v1",type:"object",additionalProperties:!1,required:["type","version","payload","ts","message_id"],properties:{type:{type:"string",enum:["overturo-field:ready","overturo-field:state","overturo-field:resize","overturo-field:complete","overturo-field:error","overturo-field:submit_requested","overturo-field:init","overturo-field:capture","overturo-field:reset"]},version:{type:"integer",const:1},payload:{type:"object",additionalProperties:!0},ts:{type:"string",pattern:"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"},message_id:{type:"string",pattern:"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"}}},Ue=new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$","u"),Ve=new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$","u");function C(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=C.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.type===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"type"},message:"must have required property 'type'"};e===null?e=[r]:e.push(r),o++}if(t.version===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"version"},message:"must have required property 'version'"};e===null?e=[r]:e.push(r),o++}if(t.payload===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"payload"},message:"must have required property 'payload'"};e===null?e=[r]:e.push(r),o++}if(t.ts===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"ts"},message:"must have required property 'ts'"};e===null?e=[r]:e.push(r),o++}if(t.message_id===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"message_id"},message:"must have required property 'message_id'"};e===null?e=[r]:e.push(r),o++}for(let r in t)if(!(r==="type"||r==="version"||r==="payload"||r==="ts"||r==="message_id")){let n={instancePath:s,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:r},message:"must NOT have additional properties"};e===null?e=[n]:e.push(n),o++}if(t.type!==void 0){let r=t.type;if(typeof r!="string"){let n={instancePath:s+"/type",schemaPath:"#/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}if(!(r==="overturo-field:ready"||r==="overturo-field:state"||r==="overturo-field:resize"||r==="overturo-field:complete"||r==="overturo-field:error"||r==="overturo-field:submit_requested"||r==="overturo-field:init"||r==="overturo-field:capture"||r==="overturo-field:reset")){let n={instancePath:s+"/type",schemaPath:"#/properties/type/enum",keyword:"enum",params:{allowedValues:qe.properties.type.enum},message:"must be equal to one of the allowed values"};e===null?e=[n]:e.push(n),o++}}if(t.version!==void 0){let r=t.version;if(!(typeof r=="number"&&!(r%1)&&!isNaN(r))){let n={instancePath:s+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"integer"},message:"must be integer"};e===null?e=[n]:e.push(n),o++}if(r!==1){let n={instancePath:s+"/version",schemaPath:"#/properties/version/const",keyword:"const",params:{allowedValue:1},message:"must be equal to constant"};e===null?e=[n]:e.push(n),o++}}if(t.payload!==void 0){let r=t.payload;if(!(r&&typeof r=="object"&&!Array.isArray(r))){let n={instancePath:s+"/payload",schemaPath:"#/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}if(t.ts!==void 0){let r=t.ts;if(typeof r=="string"){if(!Ue.test(r)){let n={instancePath:s+"/ts",schemaPath:"#/properties/ts/pattern",keyword:"pattern",params:{pattern:"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"},message:'must match pattern "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"'};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/ts",schemaPath:"#/properties/ts/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.message_id!==void 0){let r=t.message_id;if(typeof r=="string"){if(!Ve.test(r)){let n={instancePath:s+"/message_id",schemaPath:"#/properties/message_id/pattern",keyword:"pattern",params:{pattern:"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},message:'must match pattern "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"'};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/message_id",schemaPath:"#/properties/message_id/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return C.errors=e,o===0}C.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Ee=M;function M(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=M.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return M.errors=e,o===0}M.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var be=O,$e={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/state.json",title:"STATE payload",type:"object",additionalProperties:!0,required:["decisions"],properties:{decisions:{type:"object",additionalProperties:{type:"string",enum:["granted","declined"]}}}};function O(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=O.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.decisions===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"decisions"},message:"must have required property 'decisions'"};e===null?e=[r]:e.push(r),o++}if(t.decisions!==void 0){let r=t.decisions;if(r&&typeof r=="object"&&!Array.isArray(r))for(let n in r){let J=r[n];if(typeof J!="string"){let w={instancePath:s+"/decisions/"+n.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/decisions/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[w]:e.push(w),o++}if(!(J==="granted"||J==="declined")){let w={instancePath:s+"/decisions/"+n.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/decisions/additionalProperties/enum",keyword:"enum",params:{allowedValues:$e.properties.decisions.additionalProperties.enum},message:"must be equal to one of the allowed values"};e===null?e=[w]:e.push(w),o++}}else{let n={instancePath:s+"/decisions",schemaPath:"#/properties/decisions/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return O.errors=e,o===0}O.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var ve=N;function N(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=N.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.height===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};e===null?e=[r]:e.push(r),o++}if(t.height!==void 0){let r=t.height;if(!(typeof r=="number"&&!(r%1)&&!isNaN(r))){let n={instancePath:s+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"integer"},message:"must be integer"};e===null?e=[n]:e.push(n),o++}if(typeof r=="number"&&(r<0||isNaN(r))){let n={instancePath:s+"/height",schemaPath:"#/properties/height/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return N.errors=e,o===0}N.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Pe=q,He={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/complete.json",title:"COMPLETE payload (the capture token)",type:"object",additionalProperties:!0,required:["token","committed"],properties:{token:{type:"string",minLength:1},committed:{type:"boolean"},record_id:{type:["string","null"]}}},Ye=oe().default;function q(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=q.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.token===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"token"},message:"must have required property 'token'"};e===null?e=[r]:e.push(r),o++}if(t.committed===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"committed"},message:"must have required property 'committed'"};e===null?e=[r]:e.push(r),o++}if(t.token!==void 0){let r=t.token;if(typeof r=="string"){if(Ye(r)<1){let n={instancePath:s+"/token",schemaPath:"#/properties/token/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/token",schemaPath:"#/properties/token/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.committed!==void 0&&typeof t.committed!="boolean"){let r={instancePath:s+"/committed",schemaPath:"#/properties/committed/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};e===null?e=[r]:e.push(r),o++}if(t.record_id!==void 0){let r=t.record_id;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/record_id",schemaPath:"#/properties/record_id/type",keyword:"type",params:{type:He.properties.record_id.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return q.errors=e,o===0}q.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Ae=U;var Be=oe().default;function U(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=U.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.code===void 0){let r={instancePath:s,schemaPath:"#/required",keyword:"required",params:{missingProperty:"code"},message:"must have required property 'code'"};e===null?e=[r]:e.push(r),o++}if(t.code!==void 0){let r=t.code;if(typeof r=="string"){if(Be(r)<1){let n={instancePath:s+"/code",schemaPath:"#/properties/code/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/code",schemaPath:"#/properties/code/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}if(t.message!==void 0&&typeof t.message!="string"){let r={instancePath:s+"/message",schemaPath:"#/properties/message/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return U.errors=e,o===0}U.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var xe=V;function V(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=V.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return V.errors=e,o===0}V.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Te=$;function $(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=$.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.locale!==void 0&&typeof t.locale!="string"){let r={instancePath:s+"/locale",schemaPath:"#/properties/locale/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return $.errors=e,o===0}$.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var ke=H,ie={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://schemas.overturo.com/field-v1/capture.json",title:"CAPTURE payload (host \u2192 frame; what only the host knows)",type:"object",additionalProperties:!0,properties:{subject:{type:"object",additionalProperties:!0,properties:{email:{type:"string"},external_id:{type:"string"}}},page_url:{type:["string","null"]},form_id:{type:["string","null"]},submitter:{type:["string","null"]},commit:{type:"boolean"}}};function H(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=H.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),t&&typeof t=="object"&&!Array.isArray(t)){if(t.subject!==void 0){let r=t.subject;if(r&&typeof r=="object"&&!Array.isArray(r)){if(r.email!==void 0&&typeof r.email!="string"){let n={instancePath:s+"/subject/email",schemaPath:"#/properties/subject/properties/email/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}if(r.external_id!==void 0&&typeof r.external_id!="string"){let n={instancePath:s+"/subject/external_id",schemaPath:"#/properties/subject/properties/external_id/type",keyword:"type",params:{type:"string"},message:"must be string"};e===null?e=[n]:e.push(n),o++}}else{let n={instancePath:s+"/subject",schemaPath:"#/properties/subject/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[n]:e.push(n),o++}}if(t.page_url!==void 0){let r=t.page_url;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/page_url",schemaPath:"#/properties/page_url/type",keyword:"type",params:{type:ie.properties.page_url.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.form_id!==void 0){let r=t.form_id;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/form_id",schemaPath:"#/properties/form_id/type",keyword:"type",params:{type:ie.properties.form_id.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.submitter!==void 0){let r=t.submitter;if(typeof r!="string"&&r!==null){let n={instancePath:s+"/submitter",schemaPath:"#/properties/submitter/type",keyword:"type",params:{type:ie.properties.submitter.type},message:"must be string,null"};e===null?e=[n]:e.push(n),o++}}if(t.commit!==void 0&&typeof t.commit!="boolean"){let r={instancePath:s+"/commit",schemaPath:"#/properties/commit/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};e===null?e=[r]:e.push(r),o++}}else{let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return H.errors=e,o===0}H.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var we=Y;function Y(t,{instancePath:s="",parentData:i,parentDataProperty:a,rootData:p=t,dynamicAnchors:u={}}={}){let e=null,o=0,l=Y.evaluated;if(l.dynamicProps&&(l.props=void 0),l.dynamicItems&&(l.items=void 0),!(t&&typeof t=="object"&&!Array.isArray(t))){let r={instancePath:s,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};e===null?e=[r]:e.push(r),o++}return Y.errors=e,o===0}Y.evaluated={props:!0,dynamicProps:!1,dynamicItems:!1};var Ge={[m.READY]:Ee,[m.STATE]:be,[m.RESIZE]:ve,[m.COMPLETE]:Pe,[m.ERROR]:Ae,[m.SUBMIT_REQUESTED]:xe,[m.INIT]:Te,[m.CAPTURE]:ke,[m.RESET]:we},Fe=ge;function ne(t){let s=Fe(t);return{valid:s,errors:s?null:Fe.errors??null}}function ae(t){let s=Ge[t.type];if(!s)return{valid:!1,errors:[{message:`Unknown type ${t.type}`}]};let i=s(t.payload);return{valid:i,errors:i?null:s.errors??null}}function B(t){let s=ne(t);return s.valid?ae(t):s}function G(t,s){return{type:t,version:D,payload:s,ts:new Date().toISOString(),message_id:Ke()}}function Ke(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let s=Math.random()*16|0;return(t==="x"?s:s&3|8).toString(16)})}var le=class extends Error{constructor(s){super(s),this.name="OverturoError"}},F=class extends le{constructor(s){super(s),this.name="OverturoValidationError"}};var ze="overturo_capture_token",K="overturoCaptured",Ze=5e3,pe=new WeakMap;function Ie(t,s,i){if(pe.has(t))throw new F("duplicate_attach: this form already has a capture interception; detach it before attaching again");pe.set(t,!0);let a=!1,p=s.tokenFieldName??ze,u=e=>{if(t.dataset[K]==="1"){delete t.dataset[K];return}if(e.preventDefault(),e.stopImmediatePropagation(),a)return;a=!0,t.querySelector(`input[name="${p}"]`)?.remove();let o=e.submitter??null;(async()=>{try{let{token:l}=await We(i({submitter:o}),Ze);Je(t,p,l)}catch(l){s.onError?.(l)}finally{a=!1,s.submitAfterCapture!==!1&&(t.dataset[K]="1",Qe(t,o))}})()};return t.addEventListener("submit",u,{capture:!0}),()=>{pe.delete(t),t.removeEventListener("submit",u,{capture:!0}),delete t.dataset[K],t.querySelector(`input[name="${p}"]`)?.remove()}}function We(t,s){return new Promise((i,a)=>{let p=setTimeout(()=>a(new F(`capture timed out after ${s} ms; the form submits without a capture token`)),s);t.then(u=>{clearTimeout(p),i(u)},u=>{clearTimeout(p),a(u)})})}function Qe(t,s){if(s&&s.isConnected&&typeof t.requestSubmit=="function")try{t.requestSubmit(s);return}catch{}typeof t.requestSubmit=="function"?t.requestSubmit():s&&typeof s.click=="function"?s.click():t.submit()}function Je(t,s,i){let a=t.querySelector(`input[name="${s}"]`);a||(a=document.createElement("input"),a.type="hidden",a.name=s,t.appendChild(a)),a.value=i}function de(t,s){let i=t.querySelector(s);return i instanceof HTMLInputElement?i:null}var Se=typeof HTMLElement>"u"?class{}:HTMLElement;var me="OVERTURO_FIELD_ELEMENT_ALREADY_DEFINED",_=class extends Error{constructor(s,i){super(i||s),this.name="FieldCaptureError",this.code=s}},b,I,y,x,v,T,S,R,E,c,z,W,Z,ue,A,ce,P=class extends Se{constructor(){super();g(this,c);g(this,b,null);g(this,I);g(this,y,null);g(this,x,null);g(this,v,"");g(this,T,!1);g(this,S,"");g(this,R,{});g(this,E,null);g(this,W,i=>{if(!d(this,y)||i.origin!==d(this,v))return;let a=d(this,y).contentWindow;if(!a||i.source!==a)return;if(!B(i.data).valid){h(this,c,A).call(this,"field:error",{code:"protocol_violation"});return}let u=i.data;switch(u.type){case m.READY:f(this,T,!0),this.setAttribute("aria-busy","false"),h(this,c,Z).call(this,m.INIT,this.getAttribute("locale")?{locale:this.getAttribute("locale")}:{}),h(this,c,A).call(this,"field:ready",{});break;case m.STATE:f(this,R,{...u.payload.decisions}),h(this,c,A).call(this,"field:state",{decisions:this.decisions});break;case m.RESIZE:{let e=u.payload.height;typeof e=="number"&&d(this,y)&&(d(this,y).style.height=`${e}px`);break}case m.COMPLETE:{let e=u.payload;h(this,c,ue).call(this,e.token);let o={token:e.token,committed:e.committed===!0,recordId:e.record_id??null};d(this,E)?.resolve(o),f(this,E,null),h(this,c,A).call(this,"field:complete",o);break}case m.ERROR:{let e=u.payload;d(this,E)?.reject(new _(e.code,e.message)),f(this,E,null),h(this,c,A).call(this,"field:error",e);break}case m.SUBMIT_REQUESTED:this.form?.requestSubmit?.();break}});if(f(this,I,this.attachShadow({mode:"open"})),typeof this.attachInternals=="function")try{f(this,b,this.attachInternals())}catch{f(this,b,null)}}get value(){return d(this,S)}get form(){return d(this,b)?.form??this.closest("form")}get decisions(){return{...d(this,R)}}get ready(){return d(this,T)}connectedCallback(){this.style.display||(this.style.display="block"),this.hasAttribute("role")||this.setAttribute("role","group"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.getAttribute("name")||"Consent choices"),this.setAttribute("aria-busy","true"),h(this,c,z).call(this)}disconnectedCallback(){h(this,c,ce).call(this)}attributeChangedCallback(i,a,p){if(!(a===p||!this.isConnected)){if(i==="name"){this.setAttribute("aria-label",p||"Consent choices"),d(this,y)&&(d(this,y).title=p||"Consent choices");return}h(this,c,ce).call(this),h(this,c,z).call(this)}}configure(i){this.setAttribute("base-url",i.flowBaseUrl.replace(/\/+$/,"")),this.setAttribute("publishable-key",i.publishableKey),this.isConnected&&!d(this,y)&&h(this,c,z).call(this)}capture(i){return new Promise((a,p)=>{if(!d(this,T)||!d(this,v)){p(new _("field_not_ready","The consent field has not finished loading."));return}if(d(this,E)){p(new _("capture_in_flight","A capture is already in progress; the first one answers."));return}f(this,E,{resolve:a,reject:p}),h(this,c,Z).call(this,m.CAPTURE,{subject:i.subject??{},page_url:i.pageUrl??null,form_id:i.formId??null,submitter:i.submitter??null,commit:i.commit===!0})})}attachTo(i,a,p){return this.getAttribute("flow")||this.setAttribute("flow",a.flowId),a.locale&&!this.getAttribute("locale")&&this.setAttribute("locale",a.locale),this.configure(p),Ie(i,a,async({submitter:u})=>{let e=de(i,a.subjectField),o=a.externalIdField?de(i,a.externalIdField):null,l=await this.capture({subject:{email:e?.value?.trim()||void 0,external_id:o?.value?.trim()||void 0},pageUrl:typeof window<"u"?window.location.href:void 0,formId:i.getAttribute("id")||void 0,submitter:u?.getAttribute("name")??null,commit:a.commit===!0}),r={token:l.token,attestationId:"",committed:l.committed,wordingVerdict:"match",recordId:l.recordId};return a.onCaptured?.(r),{token:l.token}})}reset(){h(this,c,Z).call(this,m.RESET,{}),h(this,c,ue).call(this,"")}formResetCallback(){this.reset()}};b=new WeakMap,I=new WeakMap,y=new WeakMap,x=new WeakMap,v=new WeakMap,T=new WeakMap,S=new WeakMap,R=new WeakMap,E=new WeakMap,c=new WeakSet,z=function(){let i=this.getAttribute("flow"),a=this.getAttribute("publishable-key");if(!i||!a)return;let p=(this.getAttribute("base-url")||et()).replace(/\/+$/,""),u=new URL(`${p}${j}/${encodeURIComponent(i)}`);u.searchParams.set("pk",a);for(let r of["locale","purposes","theme"]){let n=this.getAttribute(r);n&&u.searchParams.set(r,n)}let e=this.getAttribute("appearance");if(e)try{u.hash=L(JSON.parse(e))}catch{u.hash=""}f(this,v,u.origin);let o=document.createElement("iframe");o.src=u.toString(),o.title=this.getAttribute("name")||"Consent choices",o.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups"),o.setAttribute("referrerpolicy","strict-origin"),o.style.cssText="width:100%;height:0;border:0;display:block;background:transparent;";let l=Xe();l&&o.setAttribute("nonce",l),o.addEventListener("error",()=>{h(this,c,A).call(this,"field:error",{code:"iframe_load_failed",message:"The consent field failed to load."}),this.setAttribute("aria-busy","false")}),f(this,x,new AbortController),window.addEventListener("message",d(this,W),{signal:d(this,x).signal}),f(this,y,o),d(this,I).appendChild(o)},W=new WeakMap,Z=function(i,a){let p=d(this,y)?.contentWindow;if(!(!p||!d(this,v)))try{p.postMessage(G(i,a),d(this,v))}catch{}},ue=function(i){f(this,S,i),d(this,b)&&typeof d(this,b).setFormValue=="function"&&d(this,b).setFormValue(i||null)},A=function(i,a){this.dispatchEvent(new CustomEvent(i,{detail:a,bubbles:!0,composed:!0}))},ce=function(){d(this,x)?.abort(),f(this,x,null),d(this,y)?.parentNode&&d(this,y).parentNode.removeChild(d(this,y)),f(this,y,null),f(this,T,!1),f(this,v,""),d(this,E)?.reject(new _("field_unmounted")),f(this,E,null),this.setAttribute("aria-busy","true")},P.formAssociated=!0,P.observedAttributes=["flow","purposes","locale","theme","name","appearance","publishable-key","base-url"];function Xe(){return typeof document>"u"?null:document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content")??null}function et(){return he}function Q(){if(!(typeof customElements>"u")){if(customElements.get(k)){console.warn("[overturo:sdk]",me,`<${k}> already registered; skipping.`);return}customElements.define(k,P)}}Q();return Oe(tt);})();
2
2
  if(typeof window!=='undefined'){window.OverturoField=OverturoField.ConsentFieldElement?OverturoField:OverturoField}