(()=>{"use strict";var e={57214:(e,t,r)=>{r.d(t,{m:()=>n});const n={now:()=>Date.now()}},82492:(e,t,r)=>{r.d(t,{z:()=>s});var n=r(133599);const s=n.X.createMessage((()=>({submissionId:n.X.requiredString(1),data:n.X.requiredString(2),documentId:n.X.optionalString(3),elementId:n.X.optionalString(4),pageId:n.X.optionalString(7),websiteDeploymentId:n.X.optionalString(5),websiteAccessToken:n.X.optionalString(6)})))},96890:(e,t,r)=>{r.d(t,{n:()=>n});const n=r(133599).X.createMessage((()=>({})))},106780:(e,t,r)=>{r.d(t,{B:()=>n.B});var n=r(887271)},111903:(e,t,r)=>{r.d(t,{e:()=>s});var n=r(718214);function s(e,t,r,s,o){return e.handle(t,(async e=>{const i=function(e,t,r){if(void 0===r)throw new n.cC({code:"internal_error",message:`${e}: request cannot be undefined.`});return t.deserialize(r)}(t,r,e),a=await s(i);if(o)return o.serialize(a)}))}},133599:(e,t,r)=>{r.d(t,{X:()=>p,y:()=>S});var n=r(106780),s=r(376231),o=r(758754);const i={STRING:{typeOfValue:"string"},BOOLEAN:{typeOfValue:"boolean",defaultValue:!1,fixedSize:1},DOUBLE:{typeOfValue:"number",defaultValue:0,fixedSize:8},INT32:{typeOfValue:"number",defaultValue:0},INT64:{typeOfValue:"number",defaultValue:0},BYTES:{typeOfValue:"Uint8Array"}};function a(e,t,r,n,s,o,i,a,l,c,d){return{tag:e,fieldLabel:t,typeOfValue:r,jsonFullKey:n,jsonFullValue:s,value:o,defaults:i,default:a,defaultValue:l,obj:c,typeOfKey:d}}function l(e){const{tag:t,jsonFullKeyOrJsonMiniKey:r,jsonFullValue:n,value:s,defaults:i}=e,l=r===T?void 0:r;return a(t,o.d.CONSTANT,"string",l,n,s,i,void 0,void 0,void 0,void 0)}function c(e,t,r,n){return a(r,o.d.REQUIRED,e.typeOfValue,t,void 0,void 0,void 0,null!=n?n:e.defaultValue,e.defaultValue,void 0,void 0)}function d(e,t,r){return a(r,o.d.OPTIONAL,e.typeOfValue,t,void 0,void 0,void 0,void 0,e.defaultValue,void 0,void 0)}function u(e,t,r){return a(r,o.d.REPEATED,e.typeOfValue,t,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}function h(e,t){return(r,n,s)=>{const{tag:i,jsonFullKey:l,other1:c}=M(r,n,s);let d;return d="object"===t?"object":"enum"===t?"string":t.typeOfValue,a(i,o.d.MAP,d,l,void 0,void 0,void 0,void 0,void 0,c,e.typeOfValue)}}class p{static constantString(e,t,r,n){const{tag:s,jsonFullKey:o,other1:i}=M(t,r,n);return l({tag:s,jsonFullKeyOrJsonMiniKey:e,jsonFullValue:o,value:i,defaults:!1})}static constantStringWithDefault(e,t,r,n){const{tag:s,jsonFullKey:o,other1:i}=M(t,r,n);return l({tag:s,jsonFullKeyOrJsonMiniKey:e,jsonFullValue:o,value:i,defaults:!0})}static requiredObject(e,t,r){const{tag:n,jsonFullKey:s,other1:i}=M(e,t,r);return a(n,o.d.REQUIRED,"object",s,void 0,void 0,void 0,void 0,void 0,i,void 0)}static optionalObject(e,t,r){const{tag:n,jsonFullKey:s,other1:i}=M(e,t,r);return a(n,o.d.OPTIONAL,"object",s,void 0,void 0,void 0,void 0,void 0,i,void 0)}static repeatedObject(e,t,r){const{tag:n,jsonFullKey:s,other1:i}=M(e,t,r);return a(n,o.d.REPEATED,"object",s,void 0,void 0,void 0,void 0,void 0,i,void 0)}static requiredStringEnum(e,t,r,n){const{tag:s,jsonFullKey:i,other1:l,other2:c}=M(e,t,r,n);return a(s,o.d.REQUIRED,"string",i,void 0,void 0,void 0,c,void 0,l,void 0)}static optionalStringEnum(e,t,r){const{tag:n,jsonFullKey:s,other1:i}=M(e,t,r);return a(n,o.d.OPTIONAL,"string",s,void 0,void 0,void 0,void 0,void 0,i,void 0)}static repeatedStringEnum(e,t,r){const{tag:n,jsonFullKey:s,other1:i}=M(e,t,r);return a(n,o.d.REPEATED,"string",s,void 0,void 0,void 0,void 0,void 0,i,void 0)}static createMessage(e,t={}){const r=(0,n.B)((()=>{const r=e(),n=Object.keys(r),i={},a={};for(let e=0;eString.fromCodePoint(e))).join("");return btoa(t)}(e):n.obj?n.obj.serializeWithPath(e,r):e}static deserialize(e){return i.deserializeWithPath(e,[])}static deserializeValue(e,t,r){const{config:n}=t;return"Uint8Array"===n.typeOfValue?(s=e,Uint8Array.from(atob(s),(e=>e.codePointAt(0)))):n.obj?n.obj.deserializeWithPath(e,r):e;var s}static deserializeWithPath(e,t){const{fieldMetadata:n}=r(),a=Object.create(i.prototype);for(let r=0;r{throw new TypeError(`Unproducible oneof case ${b(t)}`)}:(e,t)=>{if(null==e||"object"!=typeof e)throw new TypeError(`Expected type object, found: ${I(e)} ${b(t)}`);const{fieldMetadata:n}=r(),a={};for(let r=0;r{const n=e(),s=Object.keys(n)[0];let i,a;const l=new Map,c=new Map,d=new Map;for(let e=0;e{const{discriminatorKey:r,nameToObject:n}=s(),o=e[r],i=n.get(o);if(!i)throw new TypeError(`Unknown oneof deserialized case: ${JSON.stringify(o)} ${b(t)}`);return i.serializeWithPath(e,t)},a=(e,t)=>{const{serializedToObject:r,discriminatorJsonKeyEncodings:n,defaultObject:o}=s(),{primaryJsonKey:i,secondaryJsonKey:a}=n;let l=e[i];if(null==l&&a&&(l=e[a]),null==l&&o)return o.deserializeWithPath(e,t);const c=r.get(l);if(!c)throw new TypeError(`Unknown oneof serialized case: ${JSON.stringify(l)} ${b(t)}`);return c.deserializeWithPath(e,t)};return{init:s,serialize:e=>i(e,[]),serializeWithPath:i,deserialize:e=>a(e,[]),deserializeWithPath:a}}static createEnumUtil(e,t=0,r={}){const s=(0,n.B)((()=>{const n=e(),s=[],o=new Map,i=new Map,a=new Map,l=new Map,c=new Set;let d=0,u=1;for(;d{const{unproducible:n}=s();if(n&&n.has(e))throw new TypeError(`Unproducible enum value: ${JSON.stringify(e)} ${r?b(r):""}`);const o=t.get(e);if(null==o)throw new TypeError(`The proto enum serializer failed to serialize value ${JSON.stringify(e)} into JSON.\nIt does not recognize value ${JSON.stringify(e)} as a valid member of the TypeScript enum.\n${r?b(r):""}`);return o},i=(e,t)=>{const r=s().serializedToValue.get(e);if(null==r)throw new TypeError(`The proto enum deserializer failed to deserialize JSON ${JSON.stringify(e)} into an enum value.\nIt does not recognize JSON ${JSON.stringify(e)} as a valid JSON value encoding of the enum.\n${b(t)}`);return r};return{values:()=>s().values,producibleValues:()=>{const{values:e,unproducible:t}=s();return null==t?e:e.filter((e=>!t.has(e)))},serialize:e=>o(e,s().valueToSerialized,[]),serializeWithPath:(e,t)=>o(e,s().valueToSerialized,t),deserialize:e=>i(e,[]),deserializeWithPath:i}}}function f(e,t){return Object.entries(e).map((([e,r])=>{const n=function(e,t){let r,n=N(e.tag-1);if(e.fieldLabel===o.d.CONSTANT){const{primary:s,secondary:o}=y(n,e.jsonFullValue,t);n=T,r={primaryJsonValue:s,secondaryJsonValue:o}}const{primary:s,secondary:i}=y(n,e.jsonFullKey,t);return{keyEncodings:{primaryJsonKey:s,secondaryJsonKey:i},valueEncodings:r}}(r,t);return{config:r,name:e,primaryJsonKey:n.keyEncodings.primaryJsonKey,secondaryJsonKey:n.keyEncodings.secondaryJsonKey,primaryJsonValue:n.valueEncodings?.primaryJsonValue,secondaryJsonValue:n.valueEncodings?.secondaryJsonValue}}))}function y(e,t,r){if(!t){if(void 0!==r)throw new Error("Dual Deserialization config templated but JSON full key/value wasn't");return{primary:e,secondary:void 0}}if(void 0===r)return{primary:t,secondary:void 0};if(0===r)return{primary:e,secondary:t};if(1===r)return{primary:t,secondary:e};throw new Error("function should have been exhaustive, but wasn't")}function g(e,t,r,n){return new TypeError(`Expected repeated ${r} value for key ${v(e)}, found: ${I(t)} ${b(n)}`)}function m(e,t,r,n){return new TypeError(`Expected optional ${r} value for key ${v(e)}, found: ${I(t)} ${b(n)}`)}function w(e,t,r,n,s){return new TypeError(`Expected ${r} value${void 0!==s?` at index ${s}`:""} for key ${v(e)}, found: ${I(t)} ${b(n)}`)}function v(e){const{primaryJsonKey:t,secondaryJsonKey:r}=e;return r?`either "${t}" OR "${r}"`:`"${t}"`}function E(e){const{primaryJsonValue:t,secondaryJsonValue:r}=e;return r?`either "${t}" OR "${r}"`:`"${t}"`}function b(e){return`(path: .${e.join(".")})`}function I(e){return null===e?"null":Array.isArray(e)?"array":typeof e}p.requiredDouble=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.DOUBLE,s,n,o)},p.requiredInt32=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.INT32,s,n,o)},p.requiredInt64=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.INT64,s,n,o)},p.optionalDouble=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.DOUBLE,n,r)},p.optionalInt32=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.INT32,n,r)},p.optionalInt64=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.INT64,n,r)},p.repeatedDouble=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.DOUBLE,n,r)},p.repeatedInt32=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.INT32,n,r)},p.repeatedInt64=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.INT64,n,r)},p.requiredString=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.STRING,s,n,o)},p.optionalString=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.STRING,n,r)},p.repeatedString=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.STRING,n,r)},p.requiredBoolean=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.BOOLEAN,s,n,o)},p.optionalBoolean=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.BOOLEAN,n,r)},p.repeatedBoolean=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.BOOLEAN,n,r)},p.requiredBytes=(e,t,r)=>{const{tag:n,jsonFullKey:s,other1:o}=M(e,t,r);return c(i.BYTES,s,n,o)},p.optionalBytes=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return d(i.BYTES,n,r)},p.repeatedBytes=(e,t)=>{const{tag:r,jsonFullKey:n}=M(e,t);return u(i.BYTES,n,r)},p.booleanInt64Map=h(i.BOOLEAN,i.INT64),p.int32Int32Map=h(i.INT32,i.INT32),p.int32Int64Map=h(i.INT32,i.INT64),p.int32BoolMap=h(i.INT32,i.BOOLEAN),p.int32DoubleMap=h(i.INT32,i.DOUBLE),p.int32StringMap=h(i.INT32,i.STRING),p.int32StringEnumMap=h(i.INT32,"enum"),p.int32ObjectMap=h(i.INT32,"object"),p.int32BytesMap=h(i.INT32,i.BYTES),p.int64Int32Map=h(i.INT64,i.INT32),p.int64Int64Map=h(i.INT64,i.INT64),p.int64BooleanMap=h(i.INT64,i.BOOLEAN),p.int64DoubleMap=h(i.INT64,i.DOUBLE),p.int64StringMap=h(i.INT64,i.STRING),p.int64StringEnumMap=h(i.INT64,"enum"),p.int64ObjectMap=h(i.INT64,"object"),p.int64BytesMap=h(i.INT64,i.BYTES),p.doubleInt32Map=h(i.DOUBLE,i.INT32),p.doubleInt64Map=h(i.DOUBLE,i.INT64),p.doubleBoolMap=h(i.DOUBLE,i.BOOLEAN),p.doubleDoubleMap=h(i.DOUBLE,i.DOUBLE),p.doubleStringMap=h(i.DOUBLE,i.STRING),p.doubleStringEnumMap=h(i.DOUBLE,"enum"),p.doubleObjectMap=h(i.DOUBLE,"object"),p.doubleBytesMap=h(i.DOUBLE,i.BYTES),p.stringInt32Map=h(i.STRING,i.INT32),p.stringInt64Map=h(i.STRING,i.INT64),p.stringBooleanMap=h(i.STRING,i.BOOLEAN),p.stringDoubleMap=h(i.STRING,i.DOUBLE),p.stringStringMap=h(i.STRING,i.STRING),p.stringStringEnumMap=h(i.STRING,"enum"),p.stringObjectMap=h(i.STRING,"object"),p.stringBytesMap=h(i.STRING,i.BYTES);const S={MINI_PRIMARY_FULL_SECONDARY:0,FULL_PRIMARY_MINI_SECONDARY:1},T="A?",O="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function N(e){if(e0;)t.push(O.charAt(e%O.length)),e=Math.floor(e/O.length);return t.reverse().join("")}}function M(e,t,r,n){return"string"==typeof e?{jsonFullKey:e,tag:t,other1:r,other2:n}:{tag:e,other1:t,other2:r}}function k(e,t){return typeof e===t||function(e,t){return"Uint8Array"===t&&"string"==typeof e}(e,t)}},175104:(e,t,r)=>{r.d(t,{J:()=>s,w:()=>n});class n{static checkArgument(e,t,...r){if(!e)throw new Error(null==t?"invalid argument":n.format(t,...r))}static checkState(e,t,...r){if(!e)throw new Error(null==t?"invalid state":n.format(t,...r))}static checkEquals(e,t,r,...s){if(e!==t)throw new Error(null==r?n.format("{} != {}",n.stringify(e),n.stringify(t)):n.format(r,...s))}static stringify(e){if(null==e||"symbol"==typeof e)return String(e);try{return JSON.stringify(e)}catch(t){return String(e)}}static checkExists(e,t,...r){if(null==e)throw new Error(null==t?"argument is null":n.format(t,...r));return e}static format(e,...t){let r=0;return e.replace(/\{}/g,(()=>r{r.d(t,{C:()=>n});class n{static ok(e){return new n(!0,e,void 0)}static error(e){return new n(!1,void 0,e)}get isOk(){return this._success}get isError(){return!this._success}get data(){if(!this._success)throw new Error("Cannot access data on error result");return this._data}get error(){if(this._success)throw new Error("Cannot access error on success result");return this._error}constructor(e,t,r){this._success=e,this._data=t,this._error=r}}},248590:(e,t,r)=>{r.d(t,{J:()=>n,X:()=>s});class n extends Error{constructor(){super("[internal_error] Comms promise timed out.")}}class s{reset(e){e&&(this.timeoutMs=e),this.setTimeout()}resolve(e){clearTimeout(this.timeoutId),this.resolveFn(e)}reject(e){clearTimeout(this.timeoutId),this.rejectFn(e)}promise(){return this.p}rejectOnNextTick(){this.timeoutId=setTimeout((()=>{this.rejectFn(new n)}),500)}setTimeout(){clearTimeout(this.timeoutId),this.timeoutId=setTimeout((()=>{this.rejectOnNextTick()}),Math.max(this.timeoutMs-500,500))}constructor(e){this.timeoutMs=e,this.p=new Promise(((e,t)=>{this.resolveFn=e,this.rejectFn=t})),this.setTimeout()}}},252044:(e,t,r)=>{r.d(t,{j:()=>d});var n=r(367426),s=r(953686),o=r(779201),i=r(209369),a=r(304822);const l=[403,501];function c(e,t){if(e===t)return!0;const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(const s of r){if(!Object.prototype.hasOwnProperty.call(t,s))return!1;const r=e[s],n=t[s];if(!Object.is(r,n))return!1}return!0}class d{async setupCommsClient(){const e=await this.connectToParent(this.errorService,"*",window,n.zm);if(!e.ok)return i.C.error(new Error("Failed to establish connection to parent"));this.errorService.info("Successfully connected to parent");const t=this.createDataClientComms(e.value);return this.commsClient=t,i.C.ok(t)}async create(e){try{if(!this.dataHandler)return i.C.error(new Error("SDK must be initialized with init() before calling create()"));await this.persistenceService.create(e,this.documentId,this.elementId,this.pageId,this.websiteContext);const t=await this.read();return t.isError?i.C.error(t.error):i.C.ok(void 0)}catch(t){const e=t instanceof Error?t:new Error(String(t));return i.C.error(e)}}async update(e){try{if(!this.dataHandler)return i.C.error(new Error("SDK must be initialized with init() before calling update()"));await this.persistenceService.update(e,this.documentId,this.elementId,this.pageId,this.websiteContext);const t=await this.read();return t.isError?i.C.error(t.error):i.C.ok(void 0)}catch(t){const e=t instanceof Error?t:new Error(String(t));return i.C.error(e)}}async delete(e){try{if(!this.dataHandler)return i.C.error(new Error("SDK must be initialized with init() before calling delete()"));await this.persistenceService.delete(e.__backendId,this.documentId,this.elementId,this.pageId,this.websiteContext);const t=await this.read();return t.isError?i.C.error(t.error):i.C.ok(void 0)}catch(t){const e=t instanceof Error?t:new Error(String(t));return i.C.error(e)}}async read(){try{if(!this.dataHandler)return i.C.error(new Error("SDK must be initialized with init() before calling read()"));this.pollingState.lastReadTimestamp=Date.now();const{submissions:e,pollingRateMs:t}=await this.persistenceService.read(this.documentId,this.elementId,this.pageId,this.websiteContext);return t&&t!==this.pollingState.pollingIntervalMs&&(this.pollingState.pollingIntervalMs=t,null==this.pollingState.pollingInterval||this.pollingState.hasTerminalErrors||this.startPolling()),this.hasNotifiedHandler&&function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r{try{if(Date.now()-this.pollingState.lastReadTimestamp=5?(this.errorService.error(new Error(`Stopping polling after ${this.pollingState.consecutiveErrorCount} consecutive errors.`,{cause:e})),this.pollingState.hasTerminalErrors=!0,!0):(this.errorService.warning(new Error(`Polling error ${this.pollingState.consecutiveErrorCount}/5`,{cause:e})),!1)))}resetErrorCount(){this.pollingState.consecutiveErrorCount=0}async triggerInitialReadAndReady(){try{const e=await this.read();e.isOk||this.errorService.error(new Error("Failed to initialize with data",{cause:e.error}))}finally{this.commsClient?.sendRenderReady(new s.R)}}async init(e){try{const t=await this.setupCommsClient();if(t?.isError)return this.errorService.error(new Error("Failed to establish connection to parent & initialize Data SDK",{cause:t.error})),i.C.error(t.error);const r=t.data,n=await r.sendInitData(new o.C),{documentId:a,elementId:l,pageId:c,documentExtension:d,websiteContext:u}=n;return a&&(this.documentId=a),l&&(this.elementId=l),c&&l===c&&(this.pageId=c,this.elementId=void 0),d&&(this.documentExtension=d),u&&(this.websiteContext=u),this.dataHandler=e,this.hasNotifiedHandler=!1,this.errorService.info("Data SDK initialized"),!n.isPreview||n.documentId&&n.elementId?(this.triggerInitialReadAndReady(),n.isPreview||this.startPolling(),i.C.ok(void 0)):(r.sendRenderReady(new s.R),i.C.ok(void 0))}catch(t){const e=t instanceof Error?t:new Error(String(t));return i.C.error(e)}}constructor(e,t,r,n){this.persistenceService=e,this.connectToParent=t,this.createDataClientComms=r,this.errorService=n,this.dataHandler=null,this.lastKnownData=[],this.hasNotifiedHandler=!1,this.pollingState={pollingInterval:null,consecutiveErrorCount:0,hasTerminalErrors:!1,pollingIntervalMs:2500,lastReadTimestamp:0}}}},260192:(e,t,r)=>{r.d(t,{v:()=>n});const n=r(133599).X.createMessage((()=>({})))},299865:(e,t,r)=>{r.d(t,{N:()=>s});var n=r(786190);class s{log(e,...t){console[e](n.K,`[CLIENT (${this.context})]`,...t)}report(e,t,...r){const[n,s]=r;this.beforeReportHandlers.forEach((e=>e(t,n,s))),this.log(e,...r)}createChild(e){const t=new s(`${this.context}:${e}`);return t.beforeReportHandlers=this.beforeReportHandlers,t}withOfflineStatus(){}setContext(e){this.log("debug","context set",e)}setTag(e,t){this.log("debug","tag set",e,t)}addBeforeSendHandler(){}addBeforeReportHandler(e){this.beforeReportHandlers.push(e)}setFilters(){}setSensitiveStrings(e){}addBreadCrumb(e){this.log("debug","breadcrumb added",e)}debug(e,t){this.report("debug","debug",e,t)}info(...e){this.report("info","info",...e)}warn(...e){this.report("warn","warning",...e)}warning(e,t){this.report("warn","warning",e,t)}warningException(e,t){this.report("warn","warning",e,t)}error(e,t){this.report("error","error",e,t)}errorException(e,t){this.report("error","error",e,t)}critical(e,t){this.report("error","fatal",e,t)}criticalException(e,t){this.report("error","fatal",e,t)}constructor(e){this.context=e,this.beforeReportHandlers=[]}}},304822:(e,t,r)=>{r.d(t,{P:()=>p,j:()=>h});var n=r(626271),s=r(976898),o=r(536511),i=r(827813),a=r(82492),l=r(260192),c=r(567658),d=r(676854),u=r(937001);class h extends Error{constructor(e,t,r){super(e),this.status=t,this.statusText=r,this.name="HttpError"}}class p{checkRateLimit(){const e=Date.now(),t=e-this.lastMutationTimestamp;if(t=this.rateLimitThreshold){const e=this.rateLimitMs-t;throw new h(`Rate limit exceeded. Please wait ${e}ms before making another mutation request.`,429,"Too Many Requests")}}else this.consecutiveRateLimitBreaches=0;this.lastMutationTimestamp=e}async create(e,t,r,s,a){return this.checkRateLimit(),this.executeMutation((async()=>{const l=new o.i({data:JSON.stringify(e),documentId:t,elementId:r,pageId:s,websiteDeploymentId:a?.deploymentId,websiteAccessToken:a?.accessToken}),c=await fetch((0,n.n)("/data/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o.i.serialize(l))});if(!c.ok)throw new h(`Failed to create record: ${c.status} ${c.statusText}`,c.status,c.statusText);const d=await c.json(),u=i.w.deserialize(d);if(!u?.submission?.id)throw new Error("Failed to create record: backend did not return an id");return{...e,__backendId:u.submission.id}}))}async update(e,t,r,s,o){return this.checkRateLimit(),this.executeMutation((async()=>{const i={...e};delete i.__backendId;const c=new a.z({submissionId:e.__backendId,data:JSON.stringify(i),documentId:t,elementId:r,pageId:s,websiteDeploymentId:o?.deploymentId,websiteAccessToken:o?.accessToken}),d=await fetch((0,n.n)("/data/update"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a.z.serialize(c))});if(!d.ok)throw new h(`Failed to update record: ${d.status} ${d.statusText}`,d.status,d.statusText);const u=await d.json();return l.v.deserialize(u),e}))}async delete(e,t,r,s,o){await this.executeMutation((async()=>{const i=new c.F({submissionId:e,documentId:t,elementId:r,pageId:s,websiteDeploymentId:o?.deploymentId,websiteAccessToken:o?.accessToken}),a=await fetch((0,n.n)("/data/remove"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c.F.serialize(i))});if(!a.ok)throw new h(`Failed to delete record: ${a.status} ${a.statusText}`,a.status,a.statusText);const l=await a.json();d.h.deserialize(l)}))}async executeMutation(e){try{return await this.mutationCircuitBreaker.call(e)}catch(t){if(t instanceof s._T){const e=t.lastError,r=e instanceof h?`last error: ${e.status} ${e.statusText}: ${e.message}`:e instanceof Error?`last error: ${e.message}`:"unknown error";throw new h(`Mutations temporarily disabled after repeated failures (${r}). Please try again later.`,503,"Service Unavailable")}throw t}}async read(e,t,r,s){const o=await fetch((0,n.p)("/data/getAll",{document_id:e,element_id:t,page_id:r,website_deployment_id:s?.deploymentId,website_access_token:s?.accessToken}),{method:"GET",headers:{"Content-Type":"application/json"}});if(!o.ok)throw new h(`Failed to read record: ${o.status} ${o.statusText}`,o.status,o.statusText);const i=await o.json(),a=u.E.deserialize(i),l=[];for(const n of a.enrichedSubmissions)try{const e=n.id,t=JSON.parse(n.data);l.push({...t,__backendId:e})}catch(c){throw new Error(`Failed to parse submission: ${n}, ${c}`)}return{submissions:l,pollingRateMs:a.pollEveryMs}}constructor(e=500,t=5,r=new s.gE(5,3e4)){this.rateLimitMs=e,this.rateLimitThreshold=t,this.mutationCircuitBreaker=r,this.lastMutationTimestamp=0,this.consecutiveRateLimitBreaches=0}}},367426:(e,t,r)=>{r.d(t,{Zx:()=>c,zm:()=>l});r(111903);var n=r(904119),s=r(779201),o=r(675263),i=r(953686),a=r(96890);const l="canva-code-data-sdk";class c{async sendInitData(e){const t=d(await this.comms.request(n.c.INIT_DATA,s.C.serialize(e)),n.c.INIT_DATA);return o.E.deserialize(t)}async sendRenderReady(e){const t=d(await this.comms.request(n.c.DATA_RENDER_READY,i.R.serialize(e)),n.c.DATA_RENDER_READY);return a.n.deserialize(t)}constructor(e){this.comms=e}}function d(e,t){if(!e.ok)throw new Error(`Encountered an error while sending ${t} request: ${e.error}`);if(null==e.value)throw new Error(`${t}: Result cannot be empty`);return e.value}},376231:(e,t,r)=>{r.d(t,{J:()=>n.J});var n=r(175104)},459418:(e,t,r)=>{r.d(t,{V:()=>s});var n=r(133599);const s=n.X.createMessage((()=>({id:n.X.requiredString(1),data:n.X.requiredString(2)})))},488051:(e,t,r)=>{r.d(t,{A:()=>a});var n=r(376231),s=r(658435),o=r(500383),i=r(697604);async function a(e,t,{parent:r,addEventListener:a,removeEventListener:l}=window,c){const d=Promise.withResolvers(),u=({ports:t,data:r})=>{const s=(0,i.lT)(r,"parent",c);if(!s.ok){switch(s.error){case i.Gz.INVALID_SOURCE:e.info(s.error,{errorMessagePrefix:"failed to verify message",extra:new Map([["data.sandboxCommsSource",r?.sandboxCommsSource]])});break;case i.Gz.MISSING_DATA:case i.Gz.MISSING_SOURCE:case i.Gz.UNKNOWN_CLIENT_ID:break;default:throw new n.J(s.error)}return}if(1!==t.length)return void e.error("invalid number of ports received from the parent");const[o]=t;d.resolve(o)};a("message",u);try{const n=(0,i.v7)("iframe",c);r.postMessage(n,t);const a=await d.promise;return s.Q.Ok(new o.I(a,e.createChild("comms"),!1))}catch(h){return s.Q.Err(h)}finally{l("message",u)}}},500383:(e,t,r)=>{r.d(t,{I:()=>a});var n=r(376231),s=r(841857),o=r(611411),i=r(749972);class a{constructor(e,t,r){this.request=(e,t)=>this.client.request(e,t),this.handle=(e,t)=>this.requestHandler.handle(e,t),this.addErrorObserver=e=>this.requestHandler.addErrorObserver(e);const s=new l((e=>{switch(e.type){case"ack":case"error":case"response":return void this.client.handleReply(e);case"request":return void this.requestHandler.handleRequest(e);default:throw new n.J(e)}}),e,t.createChild("bus"));this.client=new o.K(s.sendRequest,t.createChild("client")),this.requestHandler=new i.w(s,t.createChild("requestHandler"),r)}}class l{sendResponse(e,t){return this.bus.send({type:"response",requestId:e,payload:t})}sendError(e,t,r){return this.bus.send({type:"error",requestId:e,code:t,message:r})}sendAck(e){return this.bus.send({type:"ack",requestId:e})}constructor(e,t,r){this.handleMessage=e,this.sendRequest=(e,t,r)=>this.bus.send({type:"request",requestId:e,path:t,payload:r}),this.onReceive=e=>{switch(e.type){case"ack":return void this.handleMessage({type:"ack",requestId:e.requestId});case"error":return void this.handleMessage({type:"error",requestId:e.requestId,code:e.code,message:e.message});case"response":return void this.handleMessage({type:"response",requestId:e.requestId,payload:e.payload});case"request":return void this.handleMessage({type:"request",requestId:e.requestId,path:e.path,payload:e.payload});default:throw new n.J(e)}},this.bus=new s.Q({receive:this.onReceive},t,r)}}},536511:(e,t,r)=>{r.d(t,{i:()=>s});var n=r(133599);const s=n.X.createMessage((()=>({data:n.X.requiredString(1),documentId:n.X.optionalString(2),elementId:n.X.optionalString(3),pageId:n.X.optionalString(6),websiteDeploymentId:n.X.optionalString(4),websiteAccessToken:n.X.optionalString(5)})))},567658:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(133599);const s=n.X.createMessage((()=>({submissionId:n.X.requiredString(1),documentId:n.X.optionalString(2),elementId:n.X.optionalString(3),pageId:n.X.optionalString(6),websiteDeploymentId:n.X.optionalString(4),websiteAccessToken:n.X.optionalString(5)})))},604642:(e,t,r)=>{r.d(t,{V:()=>s});var n=r(133599);const s=n.X.createMessage((()=>({deploymentId:n.X.requiredString(1),accessToken:n.X.requiredString(2)})))},611411:(e,t,r)=>{r.d(t,{K:()=>c});var n=r(376231),s=r(658435),o=r(737329),i=r(718214),a=r(624859),l=r(248590);class c{request(e,t){const r=this.pendingRequests,n=this.recentTimedOutRequests,o=new l.X(a.FU),c=this.requestIdGenerator(),d=async function(){r.set(c,{path:e,requestPromise:o});try{const e=await o.promise();return s.Q.Ok(e)}catch(t){return t instanceof l.J?(n.set(c,[e,Date.now()]),n.size>32&&n.delete(n.keys().next().value),s.Q.Err(new i.cC({code:"internal_error",message:`Comms promise timed out (${e}).`}))):s.Q.Err(t)}finally{r.delete(c)}}(),u=this.send(c,e,t);return u.ok||(this.errorService.errorException(u.error,{errorMessagePrefix:"unable to send request",tags:new Map([["type","request"],["path",e]])}),o.reject(u.error)),d}handleReply(e){const{requestId:t,type:r}=e,{path:s,requestPromise:o}=this.pendingRequests.get(t)||{};if(o)switch(r){case"response":return void o.resolve(e.payload);case"ack":return void o.reset(a.I6);case"error":this.errorService.addBreadCrumb({level:"info",category:"sandbox_comms",message:"Error response received",data:{path:s??"unknown"}});const{code:t,message:r}=e;return void o.reject(new i.cC({code:t,message:r}));default:throw new n.J(e)}else if("ack"!==r){const[e,n]=this.recentTimedOutRequests.get(t)??["not_recently_timed_out",void 0],s=void 0!==n?new Map([["time_since_timeout",Date.now()-n]]):void 0;this.errorService.error("request has already been handled and resolved or was not sent from this client",{tags:new Map([["type",r],["path",e]]),extra:s})}}constructor(e,t,r=o.g){this.send=e,this.errorService=t,this.requestIdGenerator=r,this.pendingRequests=new Map,this.recentTimedOutRequests=new Map}}},624859:(e,t,r)=>{r.d(t,{FU:()=>s,I6:()=>o,MY:()=>n});const n=9e3,s=2e4,o=3e4},626271:(e,t,r)=>{function n(e,t){const r=t??window.location.href;let n;try{const e=new URL(r);e.hash="",e.search="";const t=e.pathname;if((t.split("/").pop()??"").toLowerCase().endsWith(".html")){const r=t.split("/");r.pop(),e.pathname=r.join("/")||"/"}n=e.toString()}catch{n=r.split("#")[0].split("?")[0]}n.endsWith("/")&&(n=n.slice(0,-1));return n+(e.startsWith("/")?e:"/"+e)}function s(e,t,r){const s=n(e,r),o=new URL(s);if(t)for(const[n,i]of Object.entries(t))void 0!==i&&o.searchParams.set(n,i);return o.toString()}r.d(t,{n:()=>n,p:()=>s})},658435:(e,t,r)=>{r.d(t,{Q:()=>o});class n{get ok(){return!0}map(e){return new n(e(this.value))}flatMap(e){return e(this.value)}mapError(){return this}get(){return this.value}constructor(e){this.value=e}}class s{get ok(){return!1}map(){return this}mapError(e){return new s(e(this.error))}flatMap(){return this}get(){}constructor(e){this.error=e}}const o={Ok:function(e){return void 0===e?i:new n(e)},Err:function(e){return void 0===e?a:new s(e)}},i=new n(void 0),a=new s(void 0)},675263:(e,t,r)=>{r.d(t,{E:()=>o});var n=r(133599),s=r(604642);const o=n.X.createMessage((()=>({documentId:n.X.optionalString("documentId",1),elementId:n.X.optionalString("elementId",2),pageId:n.X.optionalString("pageId",6),websiteContext:n.X.optionalObject("websiteContext",3,s.V),documentExtension:n.X.optionalString("documentExtension",5),isPreview:n.X.optionalBoolean("isPreview",4)})),{dualDeserializationConfig:n.y.MINI_PRIMARY_FULL_SECONDARY})},676854:(e,t,r)=>{r.d(t,{h:()=>n});const n=r(133599).X.createMessage((()=>({})))},697604:(e,t,r)=>{r.d(t,{Gz:()=>s,lT:()=>i,v7:()=>o});var n=r(658435);const s={MISSING_DATA:"missing 'data' field in MessageEvent",MISSING_SOURCE:"'sandboxCommsSource' is missing in MessageEvent data object",INVALID_SOURCE:"invalid source",UNKNOWN_CLIENT_ID:"unknown client id"};function o(e,t){return{sandboxCommsSource:e,clientId:t}}function i(e,t,r){if(!e)return n.Q.Err("missing 'data' field in MessageEvent");const s=e,o=s.sandboxCommsSource;return o?o!==t?n.Q.Err("invalid source"):s.clientId!==r?n.Q.Err("unknown client id"):n.Q.Ok():n.Q.Err("'sandboxCommsSource' is missing in MessageEvent data object")}},718214:(e,t,r)=>{r.d(t,{cC:()=>s});var n=r(903661);class s extends Error{constructor(e){e.code=o(e.code),super((0,n.C)(e)),this.code=e.code,this.name="CanvaError",this.rawMessage=e.message,Object.setPrototypeOf(this,s.prototype)}}let o=e=>e},737329:(e,t,r)=>{function n(e){const t=s(e,31);let r=0;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(e){const n=Number(e);return(n^t[r++]&15>>n/4).toString(16)}))}r.d(t,{g:()=>n});function s(e,t){if(!e&&"undefined"!=typeof window&&void 0!==window.crypto&&"function"==typeof window.crypto.getRandomValues)return window.crypto.getRandomValues(new Uint8Array(t));const r=e??Math.random;return Array.from({length:t},(()=>Math.floor(255*r())))}},749972:(e,t,r)=>{r.d(t,{w:()=>l});var n=r(718214),s=r(624859);const o=()=>"Something went wrong on our end, if this issue persists please contact us.",i=e=>`No request handler configured for path: "${e}".`,a=e=>`Handler for '${e}' is already defined.`;class l{addErrorObserver(e){return this.errorObservers.add(e),()=>this.errorObservers.delete(e)}handle(e,t){if(this.requestHandler.has(e))throw new n.cC({code:"internal_error",message:a(e)});return this.requestHandler.set(e,t),()=>this.requestHandler.delete(e)}async handleRequest(e){const{requestId:t,path:r,payload:a}=e,l=this.requestHandler.get(r);if(!l){const e=this.messenger.sendError(t,"internal_error",i(r));return void(e.ok||this.errorService.criticalException(e.error,{errorMessagePrefix:"unable to send error response",tags:new Map([["type","request"],["path",r]])}))}this.messenger.sendAck(t);const c=setInterval((()=>this.messenger.sendAck(t)),s.MY);let d;try{const e=await l(a);clearInterval(c),this.messenger.sendResponse(t,e)}catch(u){clearInterval(c);let e="internal_error",s=o();u instanceof n.cC?(d=u,"internal_error"===u.code?this.errorService.errorException(u,{errorMessagePrefix:"Internal error in comms handler",tags:new Map([["type","request"],["path",r]])}):(e=u.code,s=u.rawMessage)):this.reportNonCanvaErrors?this.errorService.errorException(u,{errorMessagePrefix:"Unexpected error type thrown from comms handler",tags:new Map([["type","request"],["path",r]])}):this.devConsole.error(u);const i=this.messenger.sendError(t,e,s);i.ok||this.errorService.criticalException(i.error,{errorMessagePrefix:"unable to send error response",tags:new Map([["type","request"],["path",r]])})}if(null!=d)for(const n of this.errorObservers)try{n(d)}catch(u){this.errorService.warningException(u,{errorMessagePrefix:"Error executing errorObserver"})}}constructor(e,t,r,n=console){this.messenger=e,this.errorService=t,this.reportNonCanvaErrors=r,this.devConsole=n,this.requestHandler=new Map,this.errorObservers=new Set}}},758754:(e,t,r)=>{r.d(t,{d:()=>n.dh,g:()=>n.gs});var n=r(923410)},779201:(e,t,r)=>{r.d(t,{C:()=>n});const n=r(133599).X.createMessage((()=>({})))},786190:(e,t,r)=>{r.d(t,{K:()=>n});const n=Symbol("canvaSystemLog")},827813:(e,t,r)=>{r.d(t,{w:()=>o});var n=r(133599),s=r(459418);const o=n.X.createMessage((()=>({submission:n.X.optionalObject(1,s.V)})))},841857:(e,t,r)=>{r.d(t,{Q:()=>o});var n=r(658435),s=r(718214);class o{constructor(e,t,r){this.handler=e,this.port=t,this.errorService=r,this.send=e=>{try{return this.port.postMessage(e),n.Q.Ok()}catch(t){return this.errorService.errorException(t),n.Q.Err(t)}},this.onMessageError=e=>{this.errorService.errorException(e)},this.onMessage=({data:e})=>{if(e)try{this.handler.receive(e)}catch(t){this.errorService.errorException(t)}else this.errorService.error(new s.cC({code:"internal_error",message:"missing data in 'MessageEvent'"}))},this.port.onmessage=this.onMessage,this.port.onmessageerror=this.onMessageError}}},887271:(e,t,r)=>{r.d(t,{B:()=>s});var n=r(175104);function s(e,{invalidateOnError:t}={invalidateOnError:!1}){let r,s=!1,o=!1;return(...i)=>{if(n.w.checkArgument(0===i.length),!o||t&&(!r.ok||s))try{s=!1,r={ok:!0,value:e()},o=!0,null!=(a=r.value)&&null!=a.then&&r.value.then(null,(e=>s=!0))}catch(l){r={ok:!1,error:l},o=!0}var a;if(r.ok)return r.value;throw r.error}}},903661:(e,t,r)=>{r.d(t,{C:()=>n});const n=e=>{const t=e.message.endsWith(".")?"":".";return`[${e.code}]: ${e.message}${t}`.trim()}},904119:(e,t,r)=>{r.d(t,{c:()=>n});const n={INIT_DATA:"INIT_DATA",DATA_RENDER_READY:"DATA_RENDER_READY"}},923410:(e,t,r)=>{r.d(t,{dh:()=>s,gs:()=>n});const n={CONCRETE:1,ONEOF:2},s={CONSTANT:1,REQUIRED:2,OPTIONAL:3,REPEATED:4,MAP:5}},937001:(e,t,r)=>{r.d(t,{E:()=>o});var n=r(133599),s=r(459418);const o=n.X.createMessage((()=>({enrichedSubmissions:n.X.repeatedObject(2,s.V),pollEveryMs:n.X.optionalInt32(3)})))},953686:(e,t,r)=>{r.d(t,{R:()=>n});const n=r(133599).X.createMessage((()=>({})))},976898:(e,t,r)=>{r.d(t,{_T:()=>s,gE:()=>o});var n=r(57214);class s extends Error{constructor(e){super("Circuit is in open state right now. Please try again later."),this.lastError=e}}class o{trip(){this.state=1}reset(){this.state=0,this.failureCount=0}handleFailure(e){this.failureCount++,this.lastFailureTimestamp=this.clock.now(),this.lastError=e,this.failureCount>=this.failureThreshold&&this.trip()}isClosed(){return 0===this.state}async call(e){if(1===this.state&&this.lastFailureTimestamp+this.resetAfterMs>this.clock.now())throw new s(this.lastError);try{const t=await e();return this.reset(),t}catch(t){throw this.handleFailure(t),t}}constructor(e,t,r=n.m){this.failureThreshold=e,this.resetAfterMs=t,this.clock=r,this.state=0,this.failureCount=0,this.lastFailureTimestamp=0,this.lastError=void 0}}}},t={};function r(n){var s=t[n];if(void 0!==s)return s.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n=r(488051),s=r(367426),o=r(299865),i=r(252044),a=r(304822);window.dataSdk=new i.j(new a.P,n.A,(e=>new s.Zx(e)),function(){const e=window.telemetrySdk?.errorService;return e?.createChild("Data")??new o.N("Data")}())})(); //# sourceMappingURL=sourcemaps/b3bf9e8ac58e6ad6.data_sdk.js.map