@notionhq/custom-blocks-host 0.4.0 → 0.4.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.
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- function On(e){let{manifestProperties:t,propertySchemasById:i}=e,s=[];for(let[c,l]of Object.entries(t)){let p=Rn({propertyKey:c,manifestProperty:l,propertySchemasById:i});p!==void 0&&s.push([c,p])}return Object.fromEntries(s)}function Rn(e){let{propertyKey:t,manifestProperty:i,propertySchemasById:s}=e,c=Pt(i.name),l=Object.entries(s).filter(([p,y])=>y.type===i.type&&(p===t||Pt(y.name)===c));return l.length===1?l[0][0]:void 0}function Pt(e){return e.trim().toLowerCase()}var Ne,jn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function et(e){return!e&&!Ne?jn:{lang:e?.lang??Ne?.lang,message:e?.message,abortEarly:e?.abortEarly??Ne?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Ne?.abortPipeEarly}}var Mn;function Bn(e){return Mn?.get(e)}var Dn;function wn(e){return Dn?.get(e)}var Tn;function qn(e,t){return Tn?.get(e)?.get(t)}function he(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function w(e,t,i,s,c){let l=c&&"input"in c?c.input:i.value,p=c?.expected??e.expects??null,y=c?.received??he(l),m={kind:e.kind,type:e.type,input:l,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},x=e.kind==="schema",_=c?.message??e.message??qn(e.reference,m.lang)??(x?wn(m.lang):null)??s.message??Bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(i.typed=!1),i.issues?i.issues.push(m):i.issues=[m]}function An(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Nn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function tt(e,t){let i=[...new Set(e)];return i.length>1?`(${i.join(` ${t} `)})`:i[0]??"never"}function X(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},et())},e}var Un=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ae(e){return{kind:"transformation",type:"brand",reference:ae,async:!1,name:e,"~run"(t){return t}}}function xe(e){return{kind:"validation",type:"finite",reference:xe,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,i){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,i),t}}}function rt(e,t){let i=he(e);return{kind:"validation",type:"includes",reference:rt,async:!1,expects:i,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&w(this,"content",s,c,{received:`!${i}`}),s}}}function Ue(e,t){return{kind:"validation",type:"max_length",reference:Ue,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length>this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Ce(e,t){return{kind:"validation",type:"min_length",reference:Ce,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length<this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Pe(e,t){return{kind:"validation",type:"min_value",reference:Pe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!(i.value>=this.requirement)&&w(this,"value",i,s,{received:i.value instanceof Date?i.value.toJSON():he(i.value)}),i}}}function nt(e,t){return{kind:"validation",type:"regex",reference:nt,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!this.requirement.test(i.value)&&w(this,"format",i,s),i}}}function ot(e){return{kind:"transformation",type:"transform",reference:ot,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var Ot={abortEarly:!0};function Rt(e,t,i){return typeof e.fallback=="function"?e.fallback(t,i):e.fallback}function Fe(e,t,i){return typeof e.default=="function"?e.default(t,i):e.default}function jt(e,t){return!e["~run"]({value:t},Ot).issues}function O(e,t){return X({kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:t,"~run"(i,s){let c=i.value;if(Array.isArray(c)){i.typed=!0,i.value=[];for(let l=0;l<c.length;l++){let p=c[l],y=this.item["~run"]({value:p},s);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:p};for(let x of y.issues)x.path?x.path.unshift(m):x.path=[m],i.issues?.push(x);if(i.issues||(i.issues=y.issues),s.abortEarly){i.typed=!1;break}}y.typed||(i.typed=!1),i.value.push(y.value)}}else w(this,"type",i,s);return i}})}function g(e){return X({kind:"schema",type:"boolean",reference:g,expects:"boolean",async:!1,message:e,"~run"(t,i){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,i),t}})}function o(e,t){return X({kind:"schema",type:"literal",reference:o,expects:he(e),async:!1,literal:e,message:t,"~run"(i,s){return An(i.value,this.literal)?i.typed=!0:w(this,"type",i,s),i}})}function it(e){return X({kind:"schema",type:"nan",reference:it,expects:"NaN",async:!1,message:e,"~run"(t,i){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function z(e,t){return X({kind:"schema",type:"nullable",reference:z,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===null&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===null)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function E(e){return X({kind:"schema",type:"number",reference:E,expects:"number",async:!1,message:e,"~run"(t,i){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function n(e,t){return X({kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}}else w(this,"type",i,s);return i}})}function u(e,t){return X({kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===void 0&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===void 0)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function T(e,t){return X({kind:"schema",type:"picklist",reference:T,expects:tt(e.map(he),"|"),async:!1,options:e,message:t,"~run"(i,s){return this.options.includes(i.value)?i.typed=!0:w(this,"type",i,s),i}})}function $(e,t,i){return X({kind:"schema",type:"record",reference:$,expects:"Object",async:!1,key:e,value:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let p in l)if(Nn(l,p)){let y=l[p],m=this.key["~run"]({value:p},c);if(m.issues){let _={type:"object",origin:"key",input:l,key:p,value:y};for(let B of m.issues)B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=m.issues),c.abortEarly){s.typed=!1;break}}let x=this.value["~run"]({value:y},c);if(x.issues){let _={type:"object",origin:"value",input:l,key:p,value:y};for(let B of x.issues)B.path?B.path.unshift(_):B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=x.issues),c.abortEarly){s.typed=!1;break}}(!m.typed||!x.typed)&&(s.typed=!1),m.typed&&(s.value[m.value]=x.value)}}else w(this,"type",s,c);return s}})}function f(e,t){return X({kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!i.issues||!s.abortEarly){for(let l in c)if(!Object.prototype.hasOwnProperty.call(this.entries,l)){w(this,"key",i,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",i,s);return i}})}function r(e){return X({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,i){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,i),t}})}function Et(e){let t;if(e)for(let i of e)if(t)for(let s of i.issues)t.push(s);else t=i.issues;return t}function b(e,t){return X({kind:"schema",type:"union",reference:b,expects:tt(e.map(i=>i.expects),"|"),async:!1,options:e,message:t,"~run"(i,s){let c,l,p;for(let y of this.options){let m=y["~run"]({value:i.value},s);if(m.typed)if(m.issues)l?l.push(m):l=[m];else{c=m;break}else p?p.push(m):p=[m]}if(c)return c;if(l){if(l.length===1)return l[0];w(this,"type",i,s,{issues:Et(l)}),i.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",i,s,{issues:Et(p)})}return i}})}function Ee(){return X({kind:"schema",type:"unknown",reference:Ee,expects:"unknown",async:!1,"~run"(e){return e.typed=!0,e}})}function v(e,t,i){return X({kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(B,Q)=>{for(let H of B.options){if(H.type==="variant")_(H,new Set(Q).add(H.key));else{let h=!0,q=0;for(let R of Q){let U=H.entries[R];if(R in l?U["~run"]({typed:!1,value:l[R]},Ot).issues:U.type!=="exact_optional"&&U.type!=="optional"&&U.type!=="nullish"){h=!1,m!==R&&(y<q||y===q&&R in l&&!(m in l))&&(y=q,m=R,x=[]),m===R&&x.push(H.entries[R].expects);break}q++}if(h){let R=H["~run"]({value:l},c);(!p||!p.typed&&R.typed)&&(p=R)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",s,c,{input:l[m],expected:tt(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",s,c);return s}})}function Mt(e,t){let i={...e.entries};for(let s of t)delete i[s];return X({...e,entries:i})}function ie(e,t,i){let s=e["~run"]({value:t},et(i));if(s.issues)throw new Un(s.issues);return s.value}function V(...e){return X({...e[0],pipe:e,"~run"(t,i){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!i.abortEarly&&!i.abortPipeEarly)&&(t=s["~run"](t,i))}return t}})}function ge(e,t,i){let s=e["~run"]({value:t},et(i));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var ue=V(r(),ae("NotionBlockId")),K=V(r(),ae("NotionDataSourceId")),N=V(r(),ae("NotionPageId")),Bt=V(r(),ae("NotionAgentId")),Dt=V(r(),ae("NotionSpaceId"));var wt=T(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),st=n({id:r(),name:r(),color:u(wt),description:u(r())}),Fn=n({id:r(),name:r(),color:u(wt),option_ids:O(r())}),zn=n({synced_property_id:r(),synced_property_name:r()}),j=n({name:r(),description:u(r())}),Hn=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],Tt=T(Hn),qt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],at=v("type",[n({...j.entries,type:o("title")}),n({...j.entries,type:o("rich_text")}),n({...j.entries,type:o("number")}),n({...j.entries,type:o("checkbox")}),n({...j.entries,type:o("url")}),n({...j.entries,type:o("email")}),n({...j.entries,type:o("phone_number")}),n({...j.entries,type:o("select"),options:O(st)}),n({...j.entries,type:o("multi_select"),options:O(st)}),n({...j.entries,type:o("status"),options:O(st),groups:O(Fn)}),n({...j.entries,type:o("date")}),n({...j.entries,type:o("people")}),n({...j.entries,type:o("files")}),n({...j.entries,type:o("unique_id")}),n({...j.entries,type:o("relation"),data_source_id:u(r()),dual_property:u(zn)}),n({...j.entries,type:o("place")}),n({...j.entries,type:o("formula")}),n({...j.entries,type:o("rollup")}),n({...j.entries,type:o("button")}),n({...j.entries,type:o("verification")}),n({...j.entries,type:o("last_visited_time")}),n({...j.entries,type:o("location")}),n({...j.entries,type:o("created_time")}),n({...j.entries,type:o("last_edited_time")}),n({...j.entries,type:o("created_by")}),n({...j.entries,type:o("last_edited_by")})]);var At={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var Nt=n({id:K,table:r(),spaceId:u(Dt)}),Ut=n({id:u(K),propertiesById:$(r(),at)}),ai=n({key:r(),collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:$(r(),u(r())),propertySchemasById:$(r(),at)}),Ln=n({collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:u($(r(),u(r())))}),me=$(r(),Ln);var be=T(["standard","high"]),Ft="standard";var zt=n({type:o("contrastModeChanged"),contrastMode:be});var ze=n({unit:T(["year","month","week","day"]),value:E(),time:r(),defaultTimeZone:u(r())}),Vn=n({unit:T(["hour","minute"]),value:E()}),Oe=n({unit:o("none")}),ut=b([ze,Vn]),Ht=u(b([ze,Oe])),Lt=u(b([ut,Oe])),Gn=n({type:o("date"),start_date:r(),reminder:Ht}),$n=n({type:o("daterange"),start_date:r(),end_date:r(),reminder:Ht}),Qn=n({type:o("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:Lt}),Wn=n({type:o("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:Lt}),Vt=v("type",[Gn,$n,Qn,Wn]);var He=n({id:r(),table:r()});var se=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K}),n({type:o("workspace"),workspace:o(!0)}),n({type:o("block_id"),block_id:ue}),n({type:o("agent_id"),agent_id:Bt}),n({type:o("unavailable")})]);var Se=v("type",[n({type:o("unavailable")}),n({type:o("page"),id:N,parent:se})]),Xn=n({type:o("emoji"),emoji:r()}),Kn=n({type:o("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),$t=n({type:o("external"),external:n({url:r()})}),Qt=n({type:o("file"),file:n({url:r(),expiry_time:u(r())})}),Ve=v("type",[Xn,Kn,$t,Qt]),Ge=v("type",[$t,Qt]),Z=z(r()),Gt=$(r(),Ee()),ct=b([n({id:r(),name:u(r()),color:u(r()),description:u(Z)}),n({name:r(),id:u(r()),color:u(r()),description:u(Z)})]),lt={start:r(),end:u(Z),time_zone:u(Z),reminder:u(b([ut,Oe]))},Zn=b([n({...lt,start:V(r(),rt("T"))}),n({...lt,time_zone:r()}),n({...lt,reminder:u(b([ze,Oe]))})]),Jn=b([n({object:u(o("user")),id:r()}),n({object:o("group"),id:r(),name:u(Z)})]),Yn=n({id:r()}),eo=b([n({type:o("external"),name:r(),external:n({url:r()})}),n({type:o("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),to=n({lat:E(),lon:E(),name:u(Z),address:u(Z),aws_place_id:u(Z),google_place_id:u(Z)}),M={id:r()},Le=z(n({...He.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Wt=v("type",[n({...M,type:o("title"),title:O(Gt)}),n({...M,type:o("rich_text"),rich_text:O(Gt)}),n({...M,type:o("number"),number:z(E())}),n({...M,type:o("url"),url:Z}),n({...M,type:o("email"),email:Z}),n({...M,type:o("phone_number"),phone_number:Z}),n({...M,type:o("checkbox"),checkbox:g()}),n({...M,type:o("select"),select:z(ct)}),n({...M,type:o("status"),status:z(ct)}),n({...M,type:o("multi_select"),multi_select:O(ct)}),n({...M,type:o("date"),date:z(Zn)}),n({...M,type:o("people"),people:O(Jn)}),n({...M,type:o("relation"),has_more:u(g()),relation:O(Yn)}),n({...M,type:o("files"),files:O(eo)}),n({...M,type:o("place"),place:z(to)}),n({...M,type:o("created_time"),created_time:Z}),n({...M,type:o("last_edited_time"),last_edited_time:Z}),n({...M,type:o("created_by"),created_by:Le}),n({...M,type:o("last_edited_by"),last_edited_by:Le}),n({...M,type:o("last_visited_time"),last_visited_time:Z}),n({...M,type:o("unique_id"),unique_id:r()}),n({...M,type:o("button"),button:r()}),n({...M,type:o("formula"),formula:r()}),n({...M,type:o("location"),location:r()}),n({...M,type:o("rollup"),rollup:r()}),n({...M,type:o("verification"),verification:r()})]),Re=$(r(),Wt),ro=$(r(),z(Wt)),re=n({object:o("page"),id:N,parent:se,properties:ro,created_by:u(Le,null),last_edited_by:u(Le,null),last_visited_time:u(z(r()),null),created_time:u(z(r()),null),last_edited_time:u(z(r()),null),icon:u(z(Ve),null),cover:u(z(Ge),null),url:u(z(r()),null),public_url:u(z(r()),null),is_archived:g(),in_trash:g()}),ke=n({object:o("page"),id:N,parent:se,properties:Re,created_time:u(r()),last_edited_time:u(r()),icon:u(Ve),cover:u(Ge),url:u(r()),public_url:u(r()),is_archived:g(),in_trash:g()});var no=r(),Xt=n({code:no,message:r(),isRetryable:g()}),Kt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]),Zt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]);var pt=V(r(),ae("NotionUserId")),ce=n({object:o("user"),id:pt,name:u(r()),avatar_url:z(r()),type:o("person"),person:n({email:r()})}),Jt=n({object:o("list"),results:O(ce),next_cursor:z(r()),has_more:g(),type:o("user"),user:$(r(),Ee())});var Yt=n({type:o("currentUserChanged"),currentUser:ce});var er=n({type:o("dataSourcesChanged"),dataSources:n({bindings:me})});var oo=r(),tr=n({code:oo,message:r(),isRetryable:g()}),rr=n({type:o("getPage"),requestId:r(),pageId:N,dataSourceId:u(K)}),nr=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]),or=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]);var io=r(),so=n({code:io,message:r(),isRetryable:g()}),ir=n({type:o("getUser"),requestId:r(),userId:pt}),sr=v("status",[n({type:o("getUserResult"),requestId:r(),status:o("success"),user:ce}),n({type:o("getUserResult"),requestId:r(),status:o("error"),error:so})]);var ao=v("type",[n({type:o("emoji"),emoji:r()}),n({type:o("external"),url:r()})]),uo=n({name:r(),description:u(r()),type:Tt}),co=n({name:r(),description:u(r()),icon:u(ao),properties:u($(r(),uo),{})}),ve=n({version:o(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:o("emoji"),emoji:r()})),dataSources:u($(r(),co),{})});var Ie=T(["light","dark"]);var lo=r(),$e=n({code:lo,message:r(),isRetryable:g()}),je=class extends Error{constructor(t){super(t.message),this.name="CustomBlockInitializationError",this.code=t.code,this.isRetryable=t.isRetryable}code;isRetryable},Qe=v("status",[n({type:o("init"),initializationId:r(),status:o("success"),theme:Ie,contrastMode:be,blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),n({type:o("init"),initializationId:r(),status:o("error"),error:$e})]);var ar=n({type:o("invalidSandboxMessage"),reason:r()});var po=r(),fo=n({code:po,message:r(),isRetryable:g()}),ur=n({type:o("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(E())}),cr=v("status",[n({type:o("listUsersResult"),requestId:r(),status:o("success"),list:Jt}),n({type:o("listUsersResult"),requestId:r(),status:o("error"),error:fo})]);var mo=r(),yo=n({code:mo,message:r(),isRetryable:g()}),lr=n({type:o("openExternalUrl"),requestId:r(),url:r()}),pr=v("status",[n({type:o("openExternalUrlResult"),requestId:r(),status:o("success")}),n({type:o("openExternalUrlResult"),requestId:r(),status:o("error"),error:yo})]);var vo=T(["side_peek","center_peek"]),ho=r(),go=n({code:ho,message:r(),isRetryable:g()}),fr=n({type:o("openPage"),requestId:r(),pageId:N,mode:vo}),mr=v("status",[n({type:o("openPageResult"),requestId:r(),status:o("success"),pageId:N}),n({type:o("openPageResult"),requestId:r(),status:o("error"),error:go})]);var yr=n({type:o("pageChanged"),page:Se});var vr=n({type:o("parentChanged"),parent:se});var dr=b([r(),E(),g(),Vt,O(r()),O(He)]);var hr=n({id:N,is_archived:g(),in_trash:g(),propertiesById:$(r(),u(dr))});var bo=r(),gr=n({code:bo,message:r(),isRetryable:g()}),br=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(re),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]),Sr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(b([re,hr])),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]);var kr=n({type:o("themeChanged"),theme:Ie});var So=r(),Ir=n({code:So,message:r(),isRetryable:g()}),_r=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]),xr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]);var Cr=v("type",[Qe,kr,zt,vr,yr,Yt,er,sr,cr,mr,pr,ar]),Pr=v("type",[...Cr.options,br,nr,Kt,_r]),js=v("type",[...Cr.options,Sr,or,Zt,xr]);function Er(e){return{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([t,i])=>[t,{...i,collectionSchema:{...i.collectionSchema,propertiesById:{...i.collectionSchema?.propertiesById,...At}}}]))}}}var de=class extends Error{};function ft(e){try{return ko(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function ko(e){let{start:t,end:i,time_zone:s,reminder:c}=e;if(!t.split("T")[0])throw new de("Date values must include a date.");let l=t.includes("T")||s!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),y=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,m=s?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=m?(Number(m[2]??0)*60+Number(m[3]??0))*(m[1]==="-"?-1:1):y,_=h=>{if(!h.split("T")[0])throw new de("Date values must include a date.");if(!h.includes("T"))return{date:h,time:"00:00"};let q=h.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(q)return{date:q[1],time:q[2]};if(!s||m){let A=new Date(new Date(h).getTime()+x*6e4).toISOString();return{date:A.slice(0,10),time:A.slice(11,16)}}let R=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(h)),U=A=>R.find(te=>te.type===A)?.value;return{date:`${U("year")}-${U("month")}-${U("day")}`,time:`${U("hour")}:${U("minute")}`}},B=_(t),Q=i?_(i):void 0;if(!l){if(c&&!("time"in c)&&c.unit!=="none")throw new de("Hour and minute reminders require a date with a time.");return Q?{type:"daterange",start_date:B.date,end_date:Q.date,reminder:c}:{type:"date",start_date:B.date,reminder:c}}let H=s??(y===0?"UTC":`UTC${y<0?"-":"+"}${Math.floor(Math.abs(y)/60)}${Math.abs(y)%60===0?"":`:${String(Math.abs(y)%60).padStart(2,"0")}`}`);return Q?{type:"datetimerange",start_date:B.date,start_time:B.time,end_date:Q.date,end_time:Q.time,time_zone:H,reminder:c}:{type:"datetime",start_date:B.date,start_time:B.time,time_zone:H,reminder:c}}function ee(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function Rr(e){return{...e,properties:Object.fromEntries(Object.values(e.properties).flatMap(t=>t?[[t.id,t]]:[])),icon:e.icon??void 0,cover:e.cover??void 0,created_time:e.created_time??void 0,last_edited_time:e.last_edited_time??void 0,url:e.url??void 0,public_url:e.public_url??void 0}}function jr(e){let t={};for(let i of Object.values(e.properties))i&&(t[i.id]=Io(i));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:{...t,created_time:Me(e.created_time),last_edited_time:Me(e.last_edited_time),created_by:e.created_by?[e.created_by]:void 0,last_edited_by:e.last_edited_by?[e.last_edited_by]:void 0}}}function Or(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let i=t.text;return i&&typeof i=="object"&&"content"in i&&typeof i.content=="string"?i.content:""}).join("")}function Me(e){if(e==null||e==="")return;let t=new Date(e);if(Number.isFinite(t.getTime()))return{type:"datetime",start_date:t.toISOString().slice(0,10),start_time:t.toISOString().slice(11,16),time_zone:"UTC"}}function Io(e){switch(e.type){case"title":return Or(e.title);case"rich_text":return Or(e.rich_text);case"number":return e.number??void 0;case"checkbox":return e.checkbox;case"url":return e.url??"";case"email":return e.email??"";case"phone_number":return e.phone_number??"";case"select":return e.select?.name;case"status":return e.status?.name;case"multi_select":return e.multi_select.flatMap(t=>t.name??[]);case"date":return e.date?ft(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return Me(e.created_time);case"last_edited_time":return Me(e.last_edited_time);case"last_visited_time":return Me(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return ee(e)}}function Be(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,i])=>{switch(i?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];case"title":case"rich_text":case"number":case"url":case"email":case"phone_number":case"checkbox":case"select":case"status":case"multi_select":case"date":case"people":case"relation":case"files":case"place":case"created_time":case"last_edited_time":case"created_by":case"last_edited_by":case"last_visited_time":case void 0:return[t,i];default:return ee(i)}}))}}function Mr(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(jr)}:{...e,page:Rr(Be(e.page))}}function Br(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(Be)}:{...e,page:Be(e.page)}}function Dr(e,t){return e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged"?t<5?Er(e):e:e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"||e.status==="error"?e:t<6?Mr(e):t<7?Br(e):e}function wr(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}function We({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&wr(e)}function Tr(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function qr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function mt(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function yt(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:i}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${i}.`,isRetryable:!1}}function vt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Ar(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Nr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function Ur(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function Fr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function zr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Hr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Xe(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function dt(){return{code:"invalid_local_preview_url",message:"Local custom blocks require an HTTP(S) URL on localhost, a .localhost subdomain, or 127.0.0.1, without credentials and on a different origin from the host.",isRetryable:!1}}function ht(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Co=5e3,Po=5e3,Eo=5e3;function Lr(e){let{manifestSource:t,prepareInit:i,sendInitMessage:s,warn:c,flushPendingHostStateChanges:l,minBridgeProtocolVersion:p,noConnectTimeoutMs:y=Co,initialStateTimeoutMs:m=Po,noInitResultTimeoutMs:x=Eo,stopHostWithFailure:_,onInitResult:B,onInitSent:Q,onConnectionFailure:H}=e,h="waitingForConnect",q,R,U,A,te=!1,le=!1;function W(){q!==void 0&&(window.clearTimeout(q),q=void 0)}function F(){R!==void 0&&(window.clearTimeout(R),R=void 0)}function G(){U!==void 0&&(window.clearTimeout(U),U=void 0)}function L(k){let{initializationId:C,error:I,phase:oe,source:Ze}=k;switch(h){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"failed":case"stopped":return;default:return ee(h)}h="failed",A=C,W(),F(),s({type:"init",initializationId:C,status:"error",error:I}),H({...I,phase:oe,source:Ze})}async function ne(k){if(h==="waitingForConnect"){h="preparingInit",A=k.initializationId,W(),R=window.setTimeout(()=>{if(h!=="preparingInit")return;let C=Ar();c({...C,initializationId:k.initializationId}),L({initializationId:k.initializationId,error:C,phase:"init",source:"host"})},m);try{let C=await i(k);if(h!=="preparingInit")return;if(F(),C.status==="error"){L({initializationId:k.initializationId,error:C.error,phase:"init",source:"host"});return}h="waitingForInitResult";let I={type:"init",initializationId:k.initializationId,status:"success",theme:C.initialState.theme,contrastMode:C.initialState.contrastMode??Ft,blockId:C.initialState.blockId,parent:C.initialState.parent,page:C.initialState.page,currentUser:C.initialState.currentUser,manifest:C.initialState.manifest,dataSources:C.initialState.dataSources};if(s(I),h!=="waitingForInitResult"||(Q(),h!=="waitingForInitResult"))return;U=window.setTimeout(()=>{if(h!=="waitingForInitResult")return;h="failed";let oe=zr();H({...oe,phase:"initResult",source:"host"}),c({...oe,initializationId:k.initializationId})},x)}catch(C){if(h!=="preparingInit")return;c({message:"Failed to prepare custom block initialization",error:C}),L({initializationId:k.initializationId,error:Xe(),phase:"init",source:"host"})}}}function D(k){if(h!=="stopped"&&h==="waitingForConnect"){if(!ht(k.bridgeProtocolVersion)){let C=mt({currentBridgeProtocolVersion:k.bridgeProtocolVersion});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.bridgeProtocolVersion<p){let C=yt({currentBridgeProtocolVersion:k.bridgeProtocolVersion,minBridgeProtocolVersion:p});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.status==="error"&&(t==="sandbox"||k.error.code!=="manifest_invalid")){L({initializationId:k.initializationId,error:k.error,phase:"connect",source:"sandbox"});return}le=!0,ne(k)}}function Y(k){if(h==="stopped"||h!=="waitingForConnect")return"handled";let{initializationId:C,bridgeProtocolVersion:I}=k;if(C===void 0)return"nack";let oe=k.error;return I!==void 0&&(ht(I)?I<p&&(oe=yt({currentBridgeProtocolVersion:I,minBridgeProtocolVersion:p})):oe=mt({currentBridgeProtocolVersion:I})),L({initializationId:C,error:oe,phase:"connect",source:"host"}),"handled"}function pe(k){let{initializationId:C,error:I}=k;h!=="waitingForInitResult"||C===void 0||C!==A||(W(),G(),h="failed",c(I),H({...I,phase:"initResult",source:"host"}))}function Ae(){if(h!=="stopped"){if(te){_({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}te=!0,W(),h==="waitingForConnect"&&(q=window.setTimeout(()=>{if(h!=="waitingForConnect")return;h="failed";let k=Tr();c(k),H({...k,phase:"connect",source:"host"})},y))}}function _e(k){if(h!=="waitingForInitResult"||k.initializationId!==A){c({message:"Ignored stale or unexpected initResult",payload:k});return}G(),h=k.status==="success"?"initialized":"failed",k.status==="success"?l():H({...k.error,phase:"initResult",source:"sandbox"}),B(k)}function fe(){h="stopped",W(),F(),G()}return{get status(){return h},get hasConnectedSandbox(){return le},handleConnect:D,handleInitResult:_e,handleInvalidConnect:Y,handleInvalidInitResult:pe,onIframeLoad:Ae,stop:fe}}async function Vr(e){return e.manifestSource==="host"?e.hostManifest:e.connectManifest!==void 0?{status:"success",manifest:e.connectManifest}:{status:"error",error:{code:"manifest_unavailable",message:"The sandbox did not provide a manifest in connect.",isRetryable:!1}}}var Gr=v("status",[n({status:o("success"),manifest:ve}),n({status:o("error"),error:$e})]),gt=n({theme:Ie,contrastMode:u(be),blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),$r=v("status",[n({status:o("success"),initialState:Mt(gt,["manifest"])}),n({status:o("error"),error:$e})]);function Qr(e){if(e.length>2048||!URL.canParse(e))return;let t=new URL(e);if(!(t.protocol!=="http:"&&t.protocol!=="https:"||t.username!==""||t.password!==""||t.href.length>2048))return t.href}function Wr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Xr=n({code:r(),message:r(),isRetryable:g()});var Kr={type:o("connect"),initializationId:r(),bridgeProtocolVersion:E(),sdkVersion:r()},Zr=v("status",[n({status:o("success"),manifest:u(ve),...Kr}),n({status:o("error"),error:Xr,...Kr})]);var Oo=v("type",[n({type:o("start")}),n({type:o("end")}),n({type:o("before"),blockId:ue}),n({type:o("after"),blockId:ue})]),Ro=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K})]),Jr=n({type:o("createPage"),requestId:r(),parent:Ro,properties:Re,position:u(Oo)});var jo=r(),Mo=n({code:jo,message:r(),isRetryable:g()}),Yr=v("status",[n({type:o("initResult"),initializationId:r(),status:o("success"),initialHeight:u(V(E(),xe(),Pe(0)))}),n({type:o("initResult"),initializationId:r(),status:o("error"),error:Mo})]);var en=n({type:o("invalidHostMessage"),reason:r()});var tn=T(["ascending","descending"]);var rn=V(N,nt(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),ot(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),bt=b([f({contains:rn}),f({does_not_contain:rn})]),qe=b([f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Te=b([r(),O(r())]),nn=f({object:T(["user","group"]),id:V(r(),Ce(1))}),Bo=b([f({contains:nn}),f({does_not_contain:nn}),qe]),on=f({object:o("user"),id:V(r(),Ce(1),Ue(2e3))}),Do=b([f({contains:on}),f({does_not_contain:on}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),De=b([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),qe]),wo=b([f({equals:E()}),f({does_not_equal:E()}),f({greater_than:E()}),f({less_than:E()}),f({greater_than_or_equal_to:E()}),f({less_than_or_equal_to:E()}),qe]),To=b([f({equals:g()}),f({does_not_equal:g()})]),cn=b([f({equals:Te}),f({does_not_equal:Te}),qe]),sn=T(["To-do","In progress","Complete","Current","Future"]),an=b([sn,V(O(sn),Ce(1),Ue(5))]),qo=b([f({group_equals:an}),f({group_does_not_equal:an})]),Ao=b([cn,qo]),No=b([f({contains:Te}),f({contains_all:Te}),f({does_not_contain:Te}),qe]),J=T(["start_date","end_date"]),Uo=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),we=b([Uo,r()]),Fo=b([f({target:u(J),equals:we}),f({target:u(J),before:we}),f({target:u(J),after:we}),f({target:u(J),on_or_before:we}),f({target:u(J),on_or_after:we}),f({target:u(J),this_week:f({})}),f({target:u(J),past_week:f({})}),f({target:u(J),past_month:f({})}),f({target:u(J),past_year:f({})}),f({target:u(J),next_week:f({})}),f({target:u(J),next_month:f({})}),f({target:u(J),next_year:f({})}),f({target:u(J),is_empty:o(!0)}),f({target:u(J),is_not_empty:o(!0)})]),un=b([f({propertyId:r(),relation:bt}),f({propertyId:r(),created_by:Do}),f({propertyId:r(),title:De}),f({propertyId:r(),rich_text:De}),f({propertyId:r(),url:De}),f({propertyId:r(),email:De}),f({propertyId:r(),phone_number:De}),f({propertyId:r(),number:wo}),f({propertyId:r(),checkbox:To}),f({propertyId:r(),select:cn}),f({propertyId:r(),multi_select:No}),f({propertyId:r(),status:Ao}),f({propertyId:r(),date:Fo}),f({propertyId:r(),people:Bo})]),zo=b([un,f({and:O(un)})]),St=10,Ho=f({propertyId:r(),direction:tn}),ln=n({type:o("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:E(),filter:u(zo),sorts:u(O(Ho))});var pn=n({type:o("resize"),height:V(E(),xe(),Pe(0))});var fn=n({type:o("unsubscribeDataSourceQuery"),subscriptionId:r()});var mn=n({type:o("updatePage"),requestId:r(),pageId:N,dataSourceId:u(K),properties:u(Re),icon:u(Ve),cover:u(Ge),archived:u(g())});var yn=v("type",[Zr,Yr,ln,fn,Jr,rr,ir,ur,fr,lr,mn,pn,en]);function vn(e){return ge(yn,e)}function dn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function hn(e){let t=dn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:Lo(t)}}}function Lo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var gn=n({initializationId:r()}),Vo=n({bridgeProtocolVersion:b([E(),it()])});function bn(e){let{iframe:t,sandboxOrigin:i,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:B,onCreatePage:Q,onGetPage:H,onOpenPage:h,onOpenExternalUrl:q,onGetUser:R,onListUsers:U,onUpdatePage:A,onResize:te}=e;function le(W,F){c("warn",{message:"Ignored unsupported sandbox message",payload:kt(W),issues:F});let G=hn(W);if(G.incomingType==="connect"){let L=ge(gn,W),ne=ge(Vo,W);if(p({initializationId:L.success?L.output.initializationId:void 0,error:qr(),bridgeProtocolVersion:ne.success?ne.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let L=ge(gn,W);y({initializationId:L.success?L.output.initializationId:void 0,error:Hr()})}G.nack!==void 0&&s()!=="stopped"&&l(G.nack)}return function(F){let G=F.source===t.contentWindow,L=F.origin===i;if(!G||!L)return;let ne=vn(F.data);if(!ne.success){le(F.data,ne.issues);return}let D=ne.output;if(!Wr(D)&&s()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:kt(D)});return}switch(c("in",kt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":B(D);return;case"createPage":Q(D);return;case"openPage":h(D);return;case"openExternalUrl":q(D);return;case"getPage":H(D);return;case"getUser":R(D);return;case"listUsers":U(D);return;case"updatePage":A(D);return;case"resize":te(D);return;case"invalidHostMessage":return;default:ee(D)}}}function kt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ke=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let i={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:i,isRefreshing:!0,shouldRefreshAgain:!1}),i}isCurrent(t,i){return this.bySubscriptionId.get(t)?.token===i}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let i=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,i.push({message:c.message,token:c.token})}return s?i:void 0}finish(t,i){let s=this.bySubscriptionId.get(t);if(s?.token===i&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function Sn(e,t){if(e===void 0)return;let i="and"in e?e.and:[e];for(let s of i){let c=Go(s,t);if(c!==void 0)return c}}function Go(e,t){if(!Object.hasOwn(t.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let i=t.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==i.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${i.type}".`,isRetryable:!1};if("status"in e&&i.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,_=(Array.isArray(m)?m:[m]).find(B=>!i.groups.some(Q=>Q.name===B));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!jt(bt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=$o(e);if(c===void 0||i.type!==c.propertyType)return;let l=new Set(i.options.map(y=>y.name)),p=Qo(c.operator).find(y=>!l.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function $o(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let t=e.status;return"group_equals"in t||"group_does_not_equal"in t?void 0:{propertyType:"status",operator:t}}}function Qo(e){let t;if("equals"in e)t=e.equals;else if("does_not_equal"in e)t=e.does_not_equal;else if("contains"in e)t=e.contains;else if("contains_all"in e)t=e.contains_all;else if("does_not_contain"in e)t=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:ee(e);return Array.isArray(t)?t:[t]}var Wo=new Set(qt);function kn(e,t){if(e===void 0)return;if(e.length>St)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${St} entries.`,isRetryable:!1};let i=new Set;for(let s of e){if(i.has(s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${s.propertyId}".`,isRetryable:!1};if(i.add(s.propertyId),!Object.hasOwn(t.propertiesById,s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${s.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[s.propertyId];if(!Wo.has(c.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${c.type}".`,isRetryable:!1}}}var _n=5;function Ko(e){let{iframe:t,prepareInitialState:i,handlers:s,onStatusChange:c,onLog:l,onQueryUnsubscribed:p,minBridgeProtocolVersion:y,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_}=e,B=Zo(e.sandboxUrl,e.manifestSource),Q=B.origin,H=Math.max(y??3,3),h=new AbortController,q,R={},U=!1,A=new AbortController,te,le,W=8,F=new Ke(a=>{p?.(a)});function G(a,S){l?.(a,S)}function L(a){let S=I.status;switch(S){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"failed":break;case"stopped":return;default:return ee(S)}let P=Dr(a,W);G("out",P),t.contentWindow?.postMessage(P,Q)}function ne(a){L(ie(Qe,a))}function D(a){L(a)}function Y(a){let S=I.status;switch(S){case"initialized":L(ie(Pr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"failed":case"stopped":return;default:ee(S)}}async function pe(a,S){if(S===void 0)return;let P=await S(a);Y({type:`${a.type}Result`,requestId:a.requestId,...P})}function Ae(a){let S=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};Y(S)}async function _e(a,S=F.subscribe(a)){try{let P=Jo(le,a.dataSourceId),ye=Yo(a,P);if(ye!==void 0){F.isCurrent(a.subscriptionId,S)&&(F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:{status:"error",error:ye}}));return}let Ye=await s.queryDataSource(a);if(!F.isCurrent(a.subscriptionId,S))return;Ye.status==="error"&&!Ye.error.isRetryable&&F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:Ye})}finally{let P=F.finish(a.subscriptionId,S);P!==void 0&&_e(P.message,P.token)}}function fe(a){I.status==="stopped"||I.status==="failed"||(Object.assign(R,a),C())}async function k(a){if(s.openExternalUrl===void 0||h.signal.aborted||q===a.requestId)return;if(q!==void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};Y(P);return}let S=Qr(a.url);if(S===void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};Y(P);return}q=a.requestId;try{let P=await s.openExternalUrl({...a,url:S},{signal:h.signal});if(h.signal.aborted)return;let ye={type:"openExternalUrlResult",requestId:a.requestId,...P};Y(ye)}catch(P){if(!h.signal.aborted)throw P}finally{q===a.requestId&&(q=void 0)}}function C(){if(I.status!=="initialized")return;let a=R;R={},a.theme!==void 0&&Y({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&Y({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&Y({type:"parentChanged",parent:a.parent}),a.page!==void 0&&Y({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&Y({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&Y({type:"currentUserChanged",currentUser:a.currentUser})}let I=Lr({manifestSource:e.manifestSource,async prepareInit(a){let S=a.status==="success"?a.manifest:void 0;W=a.bridgeProtocolVersion,c({status:"preparingInit",localManifest:We({url:B,hostOrigin:window.location.origin})?S:void 0,bridgeProtocolVersion:a.bridgeProtocolVersion,sdkVersion:a.sdkVersion});let P=await(Cn??_t(S));return I.status!=="preparingInit"?P:oe(P)},sendInitMessage:ne,onInitSent:()=>c({status:"waitingForInitResult"}),warn:a=>G("warn",a),flushPendingHostStateChanges:C,minBridgeProtocolVersion:H,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_,stopHostWithFailure:Ct,onInitResult(a){a.status==="success"&&te!==void 0&&c({status:"initialized",resolvedManifest:te,initialHeight:a.initialHeight})},onConnectionFailure:a=>{A.abort(),c({status:"failed",error:a})}});function oe(a){if(a.status==="error")return a;let S=ie(gt,{...a.initialState,...R});if(te=S.manifest,R={},W<_n&&S.page.type==="unavailable")return{status:"error",error:vt()};let P=xn(S.manifest,S.dataSources);return P!==void 0?{status:"error",error:P}:(le=S.dataSources,U=!0,{status:"success",initialState:S})}let Ze=Pn().catch(It),Cn=e.manifestSource==="host"?_t(void 0).catch(It):void 0;async function Pn(){A.signal.throwIfAborted();let a=await e.getPersistedManifest({signal:A.signal});return A.signal.throwIfAborted(),ie(Gr,a)}function It(a){return A.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Xe()}}async function _t(a){A.signal.throwIfAborted();let S=await Vr({manifestSource:e.manifestSource,hostManifest:Ze,connectManifest:a});if(A.signal.throwIfAborted(),S.status==="error")return S;let P=ie($r,await i({manifest:S.manifest,signal:A.signal}));return P.status==="error"?P:{status:"success",initialState:{...P.initialState,manifest:S.manifest}}}let xt=bn({iframe:t,sandboxOrigin:Q,getInitStatus:()=>I.status,emit:G,sendNack:D,onInvalidConnect:I.handleInvalidConnect,onInvalidInitResult:I.handleInvalidInitResult,onConnect:I.handleConnect,onInitResult:I.handleInitResult,onQueryDataSource:_e,onUnsubscribeDataSourceQuery:a=>F.unsubscribe(a.subscriptionId),onOpenExternalUrl:k,onCreatePage:a=>pe(a,s.createPage),onGetPage:a=>pe(a,s.getPage),onOpenPage:a=>pe(a,s.openPage),onGetUser:a=>pe(a,s.getUser),onListUsers:a=>pe(a,s.listUsers),onUpdatePage:a=>pe(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",xt),t.addEventListener("load",I.onIframeLoad);function Je(){h.abort(),A.abort(),window.removeEventListener("message",xt),t.removeEventListener("load",I.onIframeLoad),I.stop(),F.unsubscribeAll()}function En(){let a=I.status;Je(),a!=="stopped"&&a!=="failed"&&c({status:"stopped"})}function Ct(a){if(I.status!=="stopped"){if(I.status==="failed"){Je();return}Je(),G("warn",a),c({status:"failed",error:a})}}return c({status:"waitingForConnect"}),{stop:En,setTheme(a){fe({theme:a})},setContrastMode(a){fe({contrastMode:a})},setParent(a){fe({parent:a})},setPage(a){if(a.type==="unavailable"&&W<_n&&(I.status==="preparingInit"&&U||I.status==="waitingForInitResult"||I.status==="initialized")){Ct({...vt(),phase:"runtime",source:"host"});return}fe({page:a})},setCurrentUser(a){fe({currentUser:a})},setDataSources(a){let S={bindings:ie(me,a.bindings)};if(I.hasConnectedSandbox&&te!==void 0&&xn(te,S)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:S});return}le=S,fe({dataSources:S})},refreshQuery({dataSourceId:a}){if(I.status!=="initialized")return;let S=ie(K,a),P=F.refresh(S);if(P===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ye of P)_e(ye.message,ye.token)}}}function Zo(e,t){let i;try{i=new URL(e)}catch(s){throw t==="host"?s:new je(dt())}if(t==="sandbox"&&!We({url:i,hostOrigin:window.location.origin}))throw new je(dt());return i}function Jo(e,t){return Object.values(e?.bindings??{}).find(i=>i.collectionPointer?.id===t)?.collectionSchema}function xn(e,t){for(let[i,s]of Object.entries(e.dataSources)){let c=t.bindings[i];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Nr();for(let[l,p]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return Ur();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return Fr()}}}function Yo(e,t){return t===void 0?e.filter===void 0&&(e.sorts?.length??0)===0?void 0:{code:"data_source_schema_unavailable",message:"You cannot query this data source with filters or sorts because its schema is unavailable.",isRetryable:!1}:Sn(e.filter,t)??kn(e.sorts,t)}function ei(e){return ie(N,e)}export{de as InvalidNotionDateError,Ko as createCustomBlockHost,On as getAutoBoundPropertyIdsByKey,We as isAllowedLocalPreviewUrl,ft as toNotionDateValue,ei as toNotionPageId};
1
+ function On(e){let{manifestProperties:t,propertySchemasById:i}=e,s=[];for(let[c,l]of Object.entries(t)){let p=Rn({propertyKey:c,manifestProperty:l,propertySchemasById:i});p!==void 0&&s.push([c,p])}return Object.fromEntries(s)}function Rn(e){let{propertyKey:t,manifestProperty:i,propertySchemasById:s}=e,c=Pt(i.name),l=Object.entries(s).filter(([p,y])=>y.type===i.type&&(p===t||Pt(y.name)===c));return l.length===1?l[0][0]:void 0}function Pt(e){return e.trim().toLowerCase()}var Ne,jn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function et(e){return!e&&!Ne?jn:{lang:e?.lang??Ne?.lang,message:e?.message,abortEarly:e?.abortEarly??Ne?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Ne?.abortPipeEarly}}var Mn;function Bn(e){return Mn?.get(e)}var Dn;function wn(e){return Dn?.get(e)}var Tn;function qn(e,t){return Tn?.get(e)?.get(t)}function he(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function w(e,t,i,s,c){let l=c&&"input"in c?c.input:i.value,p=c?.expected??e.expects??null,y=c?.received??he(l),m={kind:e.kind,type:e.type,input:l,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},x=e.kind==="schema",_=c?.message??e.message??qn(e.reference,m.lang)??(x?wn(m.lang):null)??s.message??Bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(i.typed=!1),i.issues?i.issues.push(m):i.issues=[m]}function An(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Nn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function tt(e,t){let i=[...new Set(e)];return i.length>1?`(${i.join(` ${t} `)})`:i[0]??"never"}function X(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},et())},e}var Un=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ae(e){return{kind:"transformation",type:"brand",reference:ae,async:!1,name:e,"~run"(t){return t}}}function xe(e){return{kind:"validation",type:"finite",reference:xe,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,i){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,i),t}}}function rt(e,t){let i=he(e);return{kind:"validation",type:"includes",reference:rt,async:!1,expects:i,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&w(this,"content",s,c,{received:`!${i}`}),s}}}function Ue(e,t){return{kind:"validation",type:"max_length",reference:Ue,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length>this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Ce(e,t){return{kind:"validation",type:"min_length",reference:Ce,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length<this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Pe(e,t){return{kind:"validation",type:"min_value",reference:Pe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!(i.value>=this.requirement)&&w(this,"value",i,s,{received:i.value instanceof Date?i.value.toJSON():he(i.value)}),i}}}function nt(e,t){return{kind:"validation",type:"regex",reference:nt,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!this.requirement.test(i.value)&&w(this,"format",i,s),i}}}function ot(e){return{kind:"transformation",type:"transform",reference:ot,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var Ot={abortEarly:!0};function Rt(e,t,i){return typeof e.fallback=="function"?e.fallback(t,i):e.fallback}function Fe(e,t,i){return typeof e.default=="function"?e.default(t,i):e.default}function jt(e,t){return!e["~run"]({value:t},Ot).issues}function O(e,t){return X({kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:t,"~run"(i,s){let c=i.value;if(Array.isArray(c)){i.typed=!0,i.value=[];for(let l=0;l<c.length;l++){let p=c[l],y=this.item["~run"]({value:p},s);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:p};for(let x of y.issues)x.path?x.path.unshift(m):x.path=[m],i.issues?.push(x);if(i.issues||(i.issues=y.issues),s.abortEarly){i.typed=!1;break}}y.typed||(i.typed=!1),i.value.push(y.value)}}else w(this,"type",i,s);return i}})}function g(e){return X({kind:"schema",type:"boolean",reference:g,expects:"boolean",async:!1,message:e,"~run"(t,i){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,i),t}})}function o(e,t){return X({kind:"schema",type:"literal",reference:o,expects:he(e),async:!1,literal:e,message:t,"~run"(i,s){return An(i.value,this.literal)?i.typed=!0:w(this,"type",i,s),i}})}function it(e){return X({kind:"schema",type:"nan",reference:it,expects:"NaN",async:!1,message:e,"~run"(t,i){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function z(e,t){return X({kind:"schema",type:"nullable",reference:z,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===null&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===null)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function E(e){return X({kind:"schema",type:"number",reference:E,expects:"number",async:!1,message:e,"~run"(t,i){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function n(e,t){return X({kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}}else w(this,"type",i,s);return i}})}function u(e,t){return X({kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===void 0&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===void 0)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function T(e,t){return X({kind:"schema",type:"picklist",reference:T,expects:tt(e.map(he),"|"),async:!1,options:e,message:t,"~run"(i,s){return this.options.includes(i.value)?i.typed=!0:w(this,"type",i,s),i}})}function $(e,t,i){return X({kind:"schema",type:"record",reference:$,expects:"Object",async:!1,key:e,value:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let p in l)if(Nn(l,p)){let y=l[p],m=this.key["~run"]({value:p},c);if(m.issues){let _={type:"object",origin:"key",input:l,key:p,value:y};for(let B of m.issues)B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=m.issues),c.abortEarly){s.typed=!1;break}}let x=this.value["~run"]({value:y},c);if(x.issues){let _={type:"object",origin:"value",input:l,key:p,value:y};for(let B of x.issues)B.path?B.path.unshift(_):B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=x.issues),c.abortEarly){s.typed=!1;break}}(!m.typed||!x.typed)&&(s.typed=!1),m.typed&&(s.value[m.value]=x.value)}}else w(this,"type",s,c);return s}})}function f(e,t){return X({kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!i.issues||!s.abortEarly){for(let l in c)if(!Object.prototype.hasOwnProperty.call(this.entries,l)){w(this,"key",i,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",i,s);return i}})}function r(e){return X({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,i){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,i),t}})}function Et(e){let t;if(e)for(let i of e)if(t)for(let s of i.issues)t.push(s);else t=i.issues;return t}function b(e,t){return X({kind:"schema",type:"union",reference:b,expects:tt(e.map(i=>i.expects),"|"),async:!1,options:e,message:t,"~run"(i,s){let c,l,p;for(let y of this.options){let m=y["~run"]({value:i.value},s);if(m.typed)if(m.issues)l?l.push(m):l=[m];else{c=m;break}else p?p.push(m):p=[m]}if(c)return c;if(l){if(l.length===1)return l[0];w(this,"type",i,s,{issues:Et(l)}),i.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",i,s,{issues:Et(p)})}return i}})}function Ee(){return X({kind:"schema",type:"unknown",reference:Ee,expects:"unknown",async:!1,"~run"(e){return e.typed=!0,e}})}function v(e,t,i){return X({kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(B,Q)=>{for(let H of B.options){if(H.type==="variant")_(H,new Set(Q).add(H.key));else{let h=!0,q=0;for(let R of Q){let U=H.entries[R];if(R in l?U["~run"]({typed:!1,value:l[R]},Ot).issues:U.type!=="exact_optional"&&U.type!=="optional"&&U.type!=="nullish"){h=!1,m!==R&&(y<q||y===q&&R in l&&!(m in l))&&(y=q,m=R,x=[]),m===R&&x.push(H.entries[R].expects);break}q++}if(h){let R=H["~run"]({value:l},c);(!p||!p.typed&&R.typed)&&(p=R)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",s,c,{input:l[m],expected:tt(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",s,c);return s}})}function Mt(e,t){let i={...e.entries};for(let s of t)delete i[s];return X({...e,entries:i})}function ie(e,t,i){let s=e["~run"]({value:t},et(i));if(s.issues)throw new Un(s.issues);return s.value}function V(...e){return X({...e[0],pipe:e,"~run"(t,i){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!i.abortEarly&&!i.abortPipeEarly)&&(t=s["~run"](t,i))}return t}})}function ge(e,t,i){let s=e["~run"]({value:t},et(i));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var ue=V(r(),ae("NotionBlockId")),K=V(r(),ae("NotionDataSourceId")),N=V(r(),ae("NotionPageId")),Bt=V(r(),ae("NotionAgentId")),Dt=V(r(),ae("NotionSpaceId"));var wt=T(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),st=n({id:r(),name:r(),color:u(wt),description:u(r())}),Fn=n({id:r(),name:r(),color:u(wt),option_ids:O(r())}),zn=n({synced_property_id:r(),synced_property_name:r()}),j=n({name:r(),description:u(r())}),Hn=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],Tt=T(Hn),qt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],at=v("type",[n({...j.entries,type:o("title")}),n({...j.entries,type:o("rich_text")}),n({...j.entries,type:o("number")}),n({...j.entries,type:o("checkbox")}),n({...j.entries,type:o("url")}),n({...j.entries,type:o("email")}),n({...j.entries,type:o("phone_number")}),n({...j.entries,type:o("select"),options:O(st)}),n({...j.entries,type:o("multi_select"),options:O(st)}),n({...j.entries,type:o("status"),options:O(st),groups:O(Fn)}),n({...j.entries,type:o("date")}),n({...j.entries,type:o("people")}),n({...j.entries,type:o("files")}),n({...j.entries,type:o("unique_id")}),n({...j.entries,type:o("relation"),data_source_id:u(r()),dual_property:u(zn)}),n({...j.entries,type:o("place")}),n({...j.entries,type:o("formula")}),n({...j.entries,type:o("rollup")}),n({...j.entries,type:o("button")}),n({...j.entries,type:o("verification")}),n({...j.entries,type:o("last_visited_time")}),n({...j.entries,type:o("location")}),n({...j.entries,type:o("created_time")}),n({...j.entries,type:o("last_edited_time")}),n({...j.entries,type:o("created_by")}),n({...j.entries,type:o("last_edited_by")})]);var At={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var Nt=n({id:K,table:r(),spaceId:u(Dt)}),Ut=n({id:u(K),propertiesById:$(r(),at)}),ai=n({key:r(),collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:$(r(),u(r())),propertySchemasById:$(r(),at)}),Ln=n({collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:u($(r(),u(r())))}),me=$(r(),Ln);var be=T(["standard","high"]),Ft="standard";var zt=n({type:o("contrastModeChanged"),contrastMode:be});var ze=n({unit:T(["year","month","week","day"]),value:E(),time:r(),defaultTimeZone:u(r())}),Vn=n({unit:T(["hour","minute"]),value:E()}),Oe=n({unit:o("none")}),ut=b([ze,Vn]),Ht=u(b([ze,Oe])),Lt=u(b([ut,Oe])),Gn=n({type:o("date"),start_date:r(),reminder:Ht}),$n=n({type:o("daterange"),start_date:r(),end_date:r(),reminder:Ht}),Qn=n({type:o("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:Lt}),Wn=n({type:o("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:Lt}),Vt=v("type",[Gn,$n,Qn,Wn]);var He=n({id:r(),table:r()});var se=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K}),n({type:o("workspace"),workspace:o(!0)}),n({type:o("block_id"),block_id:ue}),n({type:o("agent_id"),agent_id:Bt}),n({type:o("unavailable")})]);var Se=v("type",[n({type:o("unavailable")}),n({type:o("page"),id:N,parent:se})]),Xn=n({type:o("emoji"),emoji:r()}),Kn=n({type:o("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),$t=n({type:o("external"),external:n({url:r()})}),Qt=n({type:o("file"),file:n({url:r(),expiry_time:u(r())})}),Ve=v("type",[Xn,Kn,$t,Qt]),Ge=v("type",[$t,Qt]),Z=z(r()),Gt=$(r(),Ee()),ct=b([n({id:r(),name:u(r()),color:u(r()),description:u(Z)}),n({name:r(),id:u(r()),color:u(r()),description:u(Z)})]),lt={start:r(),end:u(Z),time_zone:u(Z),reminder:u(b([ut,Oe]))},Zn=b([n({...lt,start:V(r(),rt("T"))}),n({...lt,time_zone:r()}),n({...lt,reminder:u(b([ze,Oe]))})]),Jn=b([n({object:u(o("user")),id:r()}),n({object:o("group"),id:r(),name:u(Z)})]),Yn=n({id:r()}),eo=b([n({type:o("external"),name:r(),external:n({url:r()})}),n({type:o("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),to=n({lat:E(),lon:E(),name:u(Z),address:u(Z),aws_place_id:u(Z),google_place_id:u(Z)}),M={id:r()},Le=z(n({...He.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Wt=v("type",[n({...M,type:o("title"),title:O(Gt)}),n({...M,type:o("rich_text"),rich_text:O(Gt)}),n({...M,type:o("number"),number:z(E())}),n({...M,type:o("url"),url:Z}),n({...M,type:o("email"),email:Z}),n({...M,type:o("phone_number"),phone_number:Z}),n({...M,type:o("checkbox"),checkbox:g()}),n({...M,type:o("select"),select:z(ct)}),n({...M,type:o("status"),status:z(ct)}),n({...M,type:o("multi_select"),multi_select:O(ct)}),n({...M,type:o("date"),date:z(Zn)}),n({...M,type:o("people"),people:O(Jn)}),n({...M,type:o("relation"),has_more:u(g()),relation:O(Yn)}),n({...M,type:o("files"),files:O(eo)}),n({...M,type:o("place"),place:z(to)}),n({...M,type:o("created_time"),created_time:Z}),n({...M,type:o("last_edited_time"),last_edited_time:Z}),n({...M,type:o("created_by"),created_by:Le}),n({...M,type:o("last_edited_by"),last_edited_by:Le}),n({...M,type:o("last_visited_time"),last_visited_time:Z}),n({...M,type:o("unique_id"),unique_id:r()}),n({...M,type:o("button"),button:r()}),n({...M,type:o("formula"),formula:r()}),n({...M,type:o("location"),location:r()}),n({...M,type:o("rollup"),rollup:r()}),n({...M,type:o("verification"),verification:r()})]),Re=$(r(),Wt),ro=$(r(),z(Wt)),re=n({object:o("page"),id:N,parent:se,properties:ro,created_by:u(Le,null),last_edited_by:u(Le,null),last_visited_time:u(z(r()),null),created_time:u(z(r()),null),last_edited_time:u(z(r()),null),icon:u(z(Ve),null),cover:u(z(Ge),null),url:u(z(r()),null),public_url:u(z(r()),null),is_archived:g(),in_trash:g()}),ke=n({object:o("page"),id:N,parent:se,properties:Re,created_time:u(r()),last_edited_time:u(r()),icon:u(Ve),cover:u(Ge),url:u(r()),public_url:u(r()),is_archived:g(),in_trash:g()});var no=r(),Xt=n({code:no,message:r(),isRetryable:g()}),Kt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]),Zt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]);var pt=V(r(),ae("NotionUserId")),ce=n({object:o("user"),id:pt,name:u(r()),avatar_url:z(r()),type:o("person"),person:n({email:r()})}),Jt=n({object:o("list"),results:O(ce),next_cursor:z(r()),has_more:g(),type:o("user"),user:$(r(),Ee())});var Yt=n({type:o("currentUserChanged"),currentUser:ce});var er=n({type:o("dataSourcesChanged"),dataSources:n({bindings:me})});var oo=r(),tr=n({code:oo,message:r(),isRetryable:g()}),rr=n({type:o("getPage"),requestId:r(),pageId:N,dataSourceId:u(K)}),nr=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]),or=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]);var io=r(),so=n({code:io,message:r(),isRetryable:g()}),ir=n({type:o("getUser"),requestId:r(),userId:pt}),sr=v("status",[n({type:o("getUserResult"),requestId:r(),status:o("success"),user:ce}),n({type:o("getUserResult"),requestId:r(),status:o("error"),error:so})]);var ao=v("type",[n({type:o("emoji"),emoji:r()}),n({type:o("external"),url:r()})]),uo=n({name:r(),description:u(r()),type:Tt}),co=n({name:r(),description:u(r()),icon:u(ao),properties:u($(r(),uo),{})}),ve=n({version:o(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:o("emoji"),emoji:r()})),dataSources:u($(r(),co),{})});var Ie=T(["light","dark"]);var lo=r(),$e=n({code:lo,message:r(),isRetryable:g()}),je=class extends Error{constructor(t){super(t.message),this.name="CustomBlockInitializationError",this.code=t.code,this.isRetryable=t.isRetryable}code;isRetryable},Qe=v("status",[n({type:o("init"),initializationId:r(),status:o("success"),theme:Ie,contrastMode:be,blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),n({type:o("init"),initializationId:r(),status:o("error"),error:$e})]);var ar=n({type:o("invalidSandboxMessage"),reason:r()});var po=r(),fo=n({code:po,message:r(),isRetryable:g()}),ur=n({type:o("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(E())}),cr=v("status",[n({type:o("listUsersResult"),requestId:r(),status:o("success"),list:Jt}),n({type:o("listUsersResult"),requestId:r(),status:o("error"),error:fo})]);var mo=r(),yo=n({code:mo,message:r(),isRetryable:g()}),lr=n({type:o("openExternalUrl"),requestId:r(),url:r()}),pr=v("status",[n({type:o("openExternalUrlResult"),requestId:r(),status:o("success")}),n({type:o("openExternalUrlResult"),requestId:r(),status:o("error"),error:yo})]);var vo=T(["side_peek","center_peek"]),ho=r(),go=n({code:ho,message:r(),isRetryable:g()}),fr=n({type:o("openPage"),requestId:r(),pageId:N,mode:vo}),mr=v("status",[n({type:o("openPageResult"),requestId:r(),status:o("success"),pageId:N}),n({type:o("openPageResult"),requestId:r(),status:o("error"),error:go})]);var yr=n({type:o("pageChanged"),page:Se});var vr=n({type:o("parentChanged"),parent:se});var dr=b([r(),E(),g(),Vt,O(r()),O(He)]);var hr=n({id:N,is_archived:g(),in_trash:g(),propertiesById:$(r(),u(dr))});var bo=r(),gr=n({code:bo,message:r(),isRetryable:g()}),br=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(re),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]),Sr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(b([re,hr])),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]);var kr=n({type:o("themeChanged"),theme:Ie});var So=r(),Ir=n({code:So,message:r(),isRetryable:g()}),_r=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]),xr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]);var Cr=v("type",[Qe,kr,zt,vr,yr,Yt,er,sr,cr,mr,pr,ar]),Pr=v("type",[...Cr.options,br,nr,Kt,_r]),js=v("type",[...Cr.options,Sr,or,Zt,xr]);function Er(e){return{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([t,i])=>[t,{...i,collectionSchema:{...i.collectionSchema,propertiesById:{...i.collectionSchema?.propertiesById,...At}}}]))}}}var de=class extends Error{};function ft(e){try{return ko(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function ko(e){let{start:t,end:i,time_zone:s,reminder:c}=e;if(!t.split("T")[0])throw new de("Date values must include a date.");let l=t.includes("T")||s!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),y=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,m=s?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=m?(Number(m[2]??0)*60+Number(m[3]??0))*(m[1]==="-"?-1:1):y,_=h=>{if(!h.split("T")[0])throw new de("Date values must include a date.");if(!h.includes("T"))return{date:h,time:"00:00"};let q=h.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(q)return{date:q[1],time:q[2]};if(!s||m){let A=new Date(new Date(h).getTime()+x*6e4).toISOString();return{date:A.slice(0,10),time:A.slice(11,16)}}let R=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(h)),U=A=>R.find(te=>te.type===A)?.value;return{date:`${U("year")}-${U("month")}-${U("day")}`,time:`${U("hour")}:${U("minute")}`}},B=_(t),Q=i?_(i):void 0;if(!l){if(c&&!("time"in c)&&c.unit!=="none")throw new de("Hour and minute reminders require a date with a time.");return Q?{type:"daterange",start_date:B.date,end_date:Q.date,reminder:c}:{type:"date",start_date:B.date,reminder:c}}let H=s??(y===0?"UTC":`UTC${y<0?"-":"+"}${Math.floor(Math.abs(y)/60)}${Math.abs(y)%60===0?"":`:${String(Math.abs(y)%60).padStart(2,"0")}`}`);return Q?{type:"datetimerange",start_date:B.date,start_time:B.time,end_date:Q.date,end_time:Q.time,time_zone:H,reminder:c}:{type:"datetime",start_date:B.date,start_time:B.time,time_zone:H,reminder:c}}function ee(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function Rr(e){return{...e,properties:Object.fromEntries(Object.values(e.properties).flatMap(t=>t?[[t.id,t]]:[])),icon:e.icon??void 0,cover:e.cover??void 0,created_time:e.created_time??void 0,last_edited_time:e.last_edited_time??void 0,url:e.url??void 0,public_url:e.public_url??void 0}}function jr(e){let t={};for(let i of Object.values(e.properties))i&&(t[i.id]=Io(i));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:{...t,created_time:Me(e.created_time),last_edited_time:Me(e.last_edited_time),created_by:e.created_by?[e.created_by]:void 0,last_edited_by:e.last_edited_by?[e.last_edited_by]:void 0}}}function Or(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let i=t.text;return i&&typeof i=="object"&&"content"in i&&typeof i.content=="string"?i.content:""}).join("")}function Me(e){if(e==null||e==="")return;let t=new Date(e);if(Number.isFinite(t.getTime()))return{type:"datetime",start_date:t.toISOString().slice(0,10),start_time:t.toISOString().slice(11,16),time_zone:"UTC"}}function Io(e){switch(e.type){case"title":return Or(e.title);case"rich_text":return Or(e.rich_text);case"number":return e.number??void 0;case"checkbox":return e.checkbox;case"url":return e.url??"";case"email":return e.email??"";case"phone_number":return e.phone_number??"";case"select":return e.select?.name;case"status":return e.status?.name;case"multi_select":return e.multi_select.flatMap(t=>t.name??[]);case"date":return e.date?ft(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return Me(e.created_time);case"last_edited_time":return Me(e.last_edited_time);case"last_visited_time":return Me(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return ee(e)}}function Be(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,i])=>{switch(i?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];case"title":case"rich_text":case"number":case"url":case"email":case"phone_number":case"checkbox":case"select":case"status":case"multi_select":case"date":case"people":case"relation":case"files":case"place":case"created_time":case"last_edited_time":case"created_by":case"last_edited_by":case"last_visited_time":case void 0:return[t,i];default:return ee(i)}}))}}function Mr(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(jr)}:{...e,page:Rr(Be(e.page))}}function Br(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(Be)}:{...e,page:Be(e.page)}}function Dr(e,t){return e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged"?t<5?Er(e):e:e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"||e.status==="error"?e:t<6?Mr(e):t<7?Br(e):e}function wr(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}function We({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&wr(e)}function Tr(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function qr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function mt(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function yt(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:i}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${i}.`,isRetryable:!1}}function vt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Ar(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Nr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function Ur(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function Fr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function zr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Hr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Xe(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function dt(){return{code:"invalid_local_preview_url",message:"Local custom blocks require an HTTP(S) URL on localhost, a .localhost subdomain, or 127.0.0.1, without credentials and on a different origin from the host.",isRetryable:!1}}function ht(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Co=5e3,Po=5e3,Eo=5e3;function Lr(e){let{manifestSource:t,prepareInit:i,sendInitMessage:s,warn:c,flushPendingHostStateChanges:l,minBridgeProtocolVersion:p,noConnectTimeoutMs:y=Co,initialStateTimeoutMs:m=Po,noInitResultTimeoutMs:x=Eo,stopHostWithFailure:_,onInitResult:B,onInitSent:Q,onConnectionFailure:H}=e,h="waitingForConnect",q,R,U,A,te=!1,le=!1;function W(){q!==void 0&&(window.clearTimeout(q),q=void 0)}function F(){R!==void 0&&(window.clearTimeout(R),R=void 0)}function G(){U!==void 0&&(window.clearTimeout(U),U=void 0)}function L(k){let{initializationId:C,error:I,phase:oe,source:Ze}=k;switch(h){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"failed":case"stopped":return;default:return ee(h)}h="failed",A=C,W(),F(),s({type:"init",initializationId:C,status:"error",error:I}),H({...I,phase:oe,source:Ze})}async function ne(k){if(h==="waitingForConnect"){h="preparingInit",A=k.initializationId,W(),R=window.setTimeout(()=>{if(h!=="preparingInit")return;let C=Ar();c({...C,initializationId:k.initializationId}),L({initializationId:k.initializationId,error:C,phase:"init",source:"host"})},m);try{let C=await i(k);if(h!=="preparingInit")return;if(F(),C.status==="error"){L({initializationId:k.initializationId,error:C.error,phase:"init",source:"host"});return}h="waitingForInitResult";let I={type:"init",initializationId:k.initializationId,status:"success",theme:C.initialState.theme,contrastMode:C.initialState.contrastMode??Ft,blockId:C.initialState.blockId,parent:C.initialState.parent,page:C.initialState.page,currentUser:C.initialState.currentUser,manifest:C.initialState.manifest,dataSources:C.initialState.dataSources};if(s(I),h!=="waitingForInitResult"||(Q(),h!=="waitingForInitResult"))return;U=window.setTimeout(()=>{if(h!=="waitingForInitResult")return;h="failed";let oe=zr();H({...oe,phase:"initResult",source:"host"}),c({...oe,initializationId:k.initializationId})},x)}catch(C){if(h!=="preparingInit")return;c({message:"Failed to prepare custom block initialization",error:C}),L({initializationId:k.initializationId,error:Xe(),phase:"init",source:"host"})}}}function D(k){if(h!=="stopped"&&h==="waitingForConnect"){if(!ht(k.bridgeProtocolVersion)){let C=mt({currentBridgeProtocolVersion:k.bridgeProtocolVersion});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.bridgeProtocolVersion<p){let C=yt({currentBridgeProtocolVersion:k.bridgeProtocolVersion,minBridgeProtocolVersion:p});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.status==="error"&&(t==="sandbox"||k.error.code!=="manifest_invalid")){L({initializationId:k.initializationId,error:k.error,phase:"connect",source:"sandbox"});return}le=!0,ne(k)}}function Y(k){if(h==="stopped"||h!=="waitingForConnect")return"handled";let{initializationId:C,bridgeProtocolVersion:I}=k;if(C===void 0)return"nack";let oe=k.error;return I!==void 0&&(ht(I)?I<p&&(oe=yt({currentBridgeProtocolVersion:I,minBridgeProtocolVersion:p})):oe=mt({currentBridgeProtocolVersion:I})),L({initializationId:C,error:oe,phase:"connect",source:"host"}),"handled"}function pe(k){let{initializationId:C,error:I}=k;h!=="waitingForInitResult"||C===void 0||C!==A||(W(),G(),h="failed",c(I),H({...I,phase:"initResult",source:"host"}))}function Ae(){if(h!=="stopped"){if(te){_({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}te=!0,W(),h==="waitingForConnect"&&(q=window.setTimeout(()=>{if(h!=="waitingForConnect")return;h="failed";let k=Tr();c(k),H({...k,phase:"connect",source:"host"})},y))}}function _e(k){if(h!=="waitingForInitResult"||k.initializationId!==A){c({message:"Ignored stale or unexpected initResult",payload:k});return}G(),h=k.status==="success"?"initialized":"failed",k.status==="success"?l():H({...k.error,phase:"initResult",source:"sandbox"}),B(k)}function fe(){h="stopped",W(),F(),G()}return{get status(){return h},get hasConnectedSandbox(){return le},handleConnect:D,handleInitResult:_e,handleInvalidConnect:Y,handleInvalidInitResult:pe,onIframeLoad:Ae,stop:fe}}async function Vr(e){return e.manifestSource==="host"?e.hostManifest:e.connectManifest!==void 0?{status:"success",manifest:e.connectManifest}:{status:"error",error:{code:"manifest_unavailable",message:"The sandbox did not provide a manifest in connect.",isRetryable:!1}}}var Gr=v("status",[n({status:o("success"),manifest:ve}),n({status:o("error"),error:$e})]),gt=n({theme:Ie,contrastMode:u(be),blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),$r=v("status",[n({status:o("success"),initialState:Mt(gt,["manifest"])}),n({status:o("error"),error:$e})]);function Qr(e){if(e.length>2048||!URL.canParse(e))return;let t=new URL(e);if(!(t.protocol!=="http:"&&t.protocol!=="https:"||t.username!==""||t.password!==""||t.href.length>2048))return t.href}function Wr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Xr=n({code:r(),message:r(),isRetryable:g()});var Kr={type:o("connect"),initializationId:r(),bridgeProtocolVersion:E(),sdkVersion:r()},Zr=v("status",[n({status:o("success"),manifest:u(ve),...Kr}),n({status:o("error"),error:Xr,...Kr})]);var Oo=v("type",[n({type:o("start")}),n({type:o("end")}),n({type:o("before"),blockId:ue}),n({type:o("after"),blockId:ue})]),Ro=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K})]),Jr=n({type:o("createPage"),requestId:r(),parent:Ro,properties:Re,position:u(Oo)});var jo=r(),Mo=n({code:jo,message:r(),isRetryable:g()}),Yr=v("status",[n({type:o("initResult"),initializationId:r(),status:o("success"),initialHeight:u(V(E(),xe(),Pe(0)))}),n({type:o("initResult"),initializationId:r(),status:o("error"),error:Mo})]);var en=n({type:o("invalidHostMessage"),reason:r()});var tn=T(["ascending","descending"]);var rn=V(N,nt(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),ot(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),bt=b([f({contains:rn}),f({does_not_contain:rn}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),qe=b([f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Te=b([r(),O(r())]),nn=f({object:T(["user","group"]),id:V(r(),Ce(1))}),Bo=b([f({contains:nn}),f({does_not_contain:nn}),qe]),on=f({object:o("user"),id:V(r(),Ce(1),Ue(2e3))}),Do=b([f({contains:on}),f({does_not_contain:on}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),De=b([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),qe]),wo=b([f({equals:E()}),f({does_not_equal:E()}),f({greater_than:E()}),f({less_than:E()}),f({greater_than_or_equal_to:E()}),f({less_than_or_equal_to:E()}),qe]),To=b([f({equals:g()}),f({does_not_equal:g()})]),cn=b([f({equals:Te}),f({does_not_equal:Te}),qe]),sn=T(["To-do","In progress","Complete","Current","Future"]),an=b([sn,V(O(sn),Ce(1),Ue(5))]),qo=b([f({group_equals:an}),f({group_does_not_equal:an})]),Ao=b([cn,qo]),No=b([f({contains:Te}),f({contains_all:Te}),f({does_not_contain:Te}),qe]),J=T(["start_date","end_date"]),Uo=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),we=b([Uo,r()]),Fo=b([f({target:u(J),equals:we}),f({target:u(J),before:we}),f({target:u(J),after:we}),f({target:u(J),on_or_before:we}),f({target:u(J),on_or_after:we}),f({target:u(J),this_week:f({})}),f({target:u(J),past_week:f({})}),f({target:u(J),past_month:f({})}),f({target:u(J),past_year:f({})}),f({target:u(J),next_week:f({})}),f({target:u(J),next_month:f({})}),f({target:u(J),next_year:f({})}),f({target:u(J),is_empty:o(!0)}),f({target:u(J),is_not_empty:o(!0)})]),un=b([f({propertyId:r(),relation:bt}),f({propertyId:r(),created_by:Do}),f({propertyId:r(),title:De}),f({propertyId:r(),rich_text:De}),f({propertyId:r(),url:De}),f({propertyId:r(),email:De}),f({propertyId:r(),phone_number:De}),f({propertyId:r(),number:wo}),f({propertyId:r(),checkbox:To}),f({propertyId:r(),select:cn}),f({propertyId:r(),multi_select:No}),f({propertyId:r(),status:Ao}),f({propertyId:r(),date:Fo}),f({propertyId:r(),people:Bo})]),zo=b([un,f({and:O(un)})]),St=10,Ho=f({propertyId:r(),direction:tn}),ln=n({type:o("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:E(),filter:u(zo),sorts:u(O(Ho))});var pn=n({type:o("resize"),height:V(E(),xe(),Pe(0))});var fn=n({type:o("unsubscribeDataSourceQuery"),subscriptionId:r()});var mn=n({type:o("updatePage"),requestId:r(),pageId:N,dataSourceId:u(K),properties:u(Re),icon:u(Ve),cover:u(Ge),archived:u(g())});var yn=v("type",[Zr,Yr,ln,fn,Jr,rr,ir,ur,fr,lr,mn,pn,en]);function vn(e){return ge(yn,e)}function dn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function hn(e){let t=dn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:Lo(t)}}}function Lo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var gn=n({initializationId:r()}),Vo=n({bridgeProtocolVersion:b([E(),it()])});function bn(e){let{iframe:t,sandboxOrigin:i,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:B,onCreatePage:Q,onGetPage:H,onOpenPage:h,onOpenExternalUrl:q,onGetUser:R,onListUsers:U,onUpdatePage:A,onResize:te}=e;function le(W,F){c("warn",{message:"Ignored unsupported sandbox message",payload:kt(W),issues:F});let G=hn(W);if(G.incomingType==="connect"){let L=ge(gn,W),ne=ge(Vo,W);if(p({initializationId:L.success?L.output.initializationId:void 0,error:qr(),bridgeProtocolVersion:ne.success?ne.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let L=ge(gn,W);y({initializationId:L.success?L.output.initializationId:void 0,error:Hr()})}G.nack!==void 0&&s()!=="stopped"&&l(G.nack)}return function(F){let G=F.source===t.contentWindow,L=F.origin===i;if(!G||!L)return;let ne=vn(F.data);if(!ne.success){le(F.data,ne.issues);return}let D=ne.output;if(!Wr(D)&&s()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:kt(D)});return}switch(c("in",kt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":B(D);return;case"createPage":Q(D);return;case"openPage":h(D);return;case"openExternalUrl":q(D);return;case"getPage":H(D);return;case"getUser":R(D);return;case"listUsers":U(D);return;case"updatePage":A(D);return;case"resize":te(D);return;case"invalidHostMessage":return;default:ee(D)}}}function kt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ke=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let i={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:i,isRefreshing:!0,shouldRefreshAgain:!1}),i}isCurrent(t,i){return this.bySubscriptionId.get(t)?.token===i}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let i=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,i.push({message:c.message,token:c.token})}return s?i:void 0}finish(t,i){let s=this.bySubscriptionId.get(t);if(s?.token===i&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function Sn(e,t){if(e===void 0)return;let i="and"in e?e.and:[e];for(let s of i){let c=Go(s,t);if(c!==void 0)return c}}function Go(e,t){if(!Object.hasOwn(t.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let i=t.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==i.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${i.type}".`,isRetryable:!1};if("status"in e&&i.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,_=(Array.isArray(m)?m:[m]).find(B=>!i.groups.some(Q=>Q.name===B));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!jt(bt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=$o(e);if(c===void 0||i.type!==c.propertyType)return;let l=new Set(i.options.map(y=>y.name)),p=Qo(c.operator).find(y=>!l.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function $o(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let t=e.status;return"group_equals"in t||"group_does_not_equal"in t?void 0:{propertyType:"status",operator:t}}}function Qo(e){let t;if("equals"in e)t=e.equals;else if("does_not_equal"in e)t=e.does_not_equal;else if("contains"in e)t=e.contains;else if("contains_all"in e)t=e.contains_all;else if("does_not_contain"in e)t=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:ee(e);return Array.isArray(t)?t:[t]}var Wo=new Set(qt);function kn(e,t){if(e===void 0)return;if(e.length>St)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${St} entries.`,isRetryable:!1};let i=new Set;for(let s of e){if(i.has(s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${s.propertyId}".`,isRetryable:!1};if(i.add(s.propertyId),!Object.hasOwn(t.propertiesById,s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${s.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[s.propertyId];if(!Wo.has(c.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${c.type}".`,isRetryable:!1}}}var _n=5;function Ko(e){let{iframe:t,prepareInitialState:i,handlers:s,onStatusChange:c,onLog:l,onQueryUnsubscribed:p,minBridgeProtocolVersion:y,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_}=e,B=Zo(e.sandboxUrl,e.manifestSource),Q=B.origin,H=Math.max(y??3,3),h=new AbortController,q,R={},U=!1,A=new AbortController,te,le,W=8,F=new Ke(a=>{p?.(a)});function G(a,S){l?.(a,S)}function L(a){let S=I.status;switch(S){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"failed":break;case"stopped":return;default:return ee(S)}let P=Dr(a,W);G("out",P),t.contentWindow?.postMessage(P,Q)}function ne(a){L(ie(Qe,a))}function D(a){L(a)}function Y(a){let S=I.status;switch(S){case"initialized":L(ie(Pr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"failed":case"stopped":return;default:ee(S)}}async function pe(a,S){if(S===void 0)return;let P=await S(a);Y({type:`${a.type}Result`,requestId:a.requestId,...P})}function Ae(a){let S=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};Y(S)}async function _e(a,S=F.subscribe(a)){try{let P=Jo(le,a.dataSourceId),ye=Yo(a,P);if(ye!==void 0){F.isCurrent(a.subscriptionId,S)&&(F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:{status:"error",error:ye}}));return}let Ye=await s.queryDataSource(a);if(!F.isCurrent(a.subscriptionId,S))return;Ye.status==="error"&&!Ye.error.isRetryable&&F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:Ye})}finally{let P=F.finish(a.subscriptionId,S);P!==void 0&&_e(P.message,P.token)}}function fe(a){I.status==="stopped"||I.status==="failed"||(Object.assign(R,a),C())}async function k(a){if(s.openExternalUrl===void 0||h.signal.aborted||q===a.requestId)return;if(q!==void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};Y(P);return}let S=Qr(a.url);if(S===void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};Y(P);return}q=a.requestId;try{let P=await s.openExternalUrl({...a,url:S},{signal:h.signal});if(h.signal.aborted)return;let ye={type:"openExternalUrlResult",requestId:a.requestId,...P};Y(ye)}catch(P){if(!h.signal.aborted)throw P}finally{q===a.requestId&&(q=void 0)}}function C(){if(I.status!=="initialized")return;let a=R;R={},a.theme!==void 0&&Y({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&Y({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&Y({type:"parentChanged",parent:a.parent}),a.page!==void 0&&Y({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&Y({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&Y({type:"currentUserChanged",currentUser:a.currentUser})}let I=Lr({manifestSource:e.manifestSource,async prepareInit(a){let S=a.status==="success"?a.manifest:void 0;W=a.bridgeProtocolVersion,c({status:"preparingInit",localManifest:We({url:B,hostOrigin:window.location.origin})?S:void 0,bridgeProtocolVersion:a.bridgeProtocolVersion,sdkVersion:a.sdkVersion});let P=await(Cn??_t(S));return I.status!=="preparingInit"?P:oe(P)},sendInitMessage:ne,onInitSent:()=>c({status:"waitingForInitResult"}),warn:a=>G("warn",a),flushPendingHostStateChanges:C,minBridgeProtocolVersion:H,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_,stopHostWithFailure:Ct,onInitResult(a){a.status==="success"&&te!==void 0&&c({status:"initialized",resolvedManifest:te,initialHeight:a.initialHeight})},onConnectionFailure:a=>{A.abort(),c({status:"failed",error:a})}});function oe(a){if(a.status==="error")return a;let S=ie(gt,{...a.initialState,...R});if(te=S.manifest,R={},W<_n&&S.page.type==="unavailable")return{status:"error",error:vt()};let P=xn(S.manifest,S.dataSources);return P!==void 0?{status:"error",error:P}:(le=S.dataSources,U=!0,{status:"success",initialState:S})}let Ze=Pn().catch(It),Cn=e.manifestSource==="host"?_t(void 0).catch(It):void 0;async function Pn(){A.signal.throwIfAborted();let a=await e.getPersistedManifest({signal:A.signal});return A.signal.throwIfAborted(),ie(Gr,a)}function It(a){return A.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Xe()}}async function _t(a){A.signal.throwIfAborted();let S=await Vr({manifestSource:e.manifestSource,hostManifest:Ze,connectManifest:a});if(A.signal.throwIfAborted(),S.status==="error")return S;let P=ie($r,await i({manifest:S.manifest,signal:A.signal}));return P.status==="error"?P:{status:"success",initialState:{...P.initialState,manifest:S.manifest}}}let xt=bn({iframe:t,sandboxOrigin:Q,getInitStatus:()=>I.status,emit:G,sendNack:D,onInvalidConnect:I.handleInvalidConnect,onInvalidInitResult:I.handleInvalidInitResult,onConnect:I.handleConnect,onInitResult:I.handleInitResult,onQueryDataSource:_e,onUnsubscribeDataSourceQuery:a=>F.unsubscribe(a.subscriptionId),onOpenExternalUrl:k,onCreatePage:a=>pe(a,s.createPage),onGetPage:a=>pe(a,s.getPage),onOpenPage:a=>pe(a,s.openPage),onGetUser:a=>pe(a,s.getUser),onListUsers:a=>pe(a,s.listUsers),onUpdatePage:a=>pe(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",xt),t.addEventListener("load",I.onIframeLoad);function Je(){h.abort(),A.abort(),window.removeEventListener("message",xt),t.removeEventListener("load",I.onIframeLoad),I.stop(),F.unsubscribeAll()}function En(){let a=I.status;Je(),a!=="stopped"&&a!=="failed"&&c({status:"stopped"})}function Ct(a){if(I.status!=="stopped"){if(I.status==="failed"){Je();return}Je(),G("warn",a),c({status:"failed",error:a})}}return c({status:"waitingForConnect"}),{stop:En,setTheme(a){fe({theme:a})},setContrastMode(a){fe({contrastMode:a})},setParent(a){fe({parent:a})},setPage(a){if(a.type==="unavailable"&&W<_n&&(I.status==="preparingInit"&&U||I.status==="waitingForInitResult"||I.status==="initialized")){Ct({...vt(),phase:"runtime",source:"host"});return}fe({page:a})},setCurrentUser(a){fe({currentUser:a})},setDataSources(a){let S={bindings:ie(me,a.bindings)};if(I.hasConnectedSandbox&&te!==void 0&&xn(te,S)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:S});return}le=S,fe({dataSources:S})},refreshQuery({dataSourceId:a}){if(I.status!=="initialized")return;let S=ie(K,a),P=F.refresh(S);if(P===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ye of P)_e(ye.message,ye.token)}}}function Zo(e,t){let i;try{i=new URL(e)}catch(s){throw t==="host"?s:new je(dt())}if(t==="sandbox"&&!We({url:i,hostOrigin:window.location.origin}))throw new je(dt());return i}function Jo(e,t){return Object.values(e?.bindings??{}).find(i=>i.collectionPointer?.id===t)?.collectionSchema}function xn(e,t){for(let[i,s]of Object.entries(e.dataSources)){let c=t.bindings[i];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Nr();for(let[l,p]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return Ur();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return Fr()}}}function Yo(e,t){return t===void 0?e.filter===void 0&&(e.sorts?.length??0)===0?void 0:{code:"data_source_schema_unavailable",message:"You cannot query this data source with filters or sorts because its schema is unavailable.",isRetryable:!1}:Sn(e.filter,t)??kn(e.sorts,t)}function ei(e){return ie(N,e)}export{de as InvalidNotionDateError,Ko as createCustomBlockHost,On as getAutoBoundPropertyIdsByKey,We as isAllowedLocalPreviewUrl,ft as toNotionDateValue,ei as toNotionPageId};
@@ -71,6 +71,10 @@ export declare function normalizeSandboxToHostMessage(payload: unknown): v.SafeP
71
71
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
72
72
  }, undefined>, v.StrictObjectSchema<{
73
73
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
74
+ }, undefined>, v.StrictObjectSchema<{
75
+ readonly is_empty: v.LiteralSchema<true, undefined>;
76
+ }, undefined>, v.StrictObjectSchema<{
77
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
74
78
  }, undefined>], undefined>;
75
79
  }, undefined>, v.StrictObjectSchema<{
76
80
  readonly propertyId: v.StringSchema<undefined>;
@@ -318,6 +322,10 @@ export declare function normalizeSandboxToHostMessage(payload: unknown): v.SafeP
318
322
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
319
323
  }, undefined>, v.StrictObjectSchema<{
320
324
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
325
+ }, undefined>, v.StrictObjectSchema<{
326
+ readonly is_empty: v.LiteralSchema<true, undefined>;
327
+ }, undefined>, v.StrictObjectSchema<{
328
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
321
329
  }, undefined>], undefined>;
322
330
  }, undefined>, v.StrictObjectSchema<{
323
331
  readonly propertyId: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeSandboxToHostMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeSandboxToHostMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAE7D"}
1
+ {"version":3,"file":"normalizeSandboxToHostMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeSandboxToHostMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAE7D"}
@@ -1,4 +1,4 @@
1
- import type { NotionPageForProtocol3To5, notionPageDataSchema } from "../protocol/pages/page.js";
1
+ import type { bridgePageSchema, NotionPageForProtocol3To5 } from "../protocol/pages/page.js";
2
2
  import type { InferOutput } from "valibot";
3
3
  /**
4
4
  * Converts current page data to the page-operation format used by protocols 3–5.
@@ -8,7 +8,7 @@ import type { InferOutput } from "valibot";
8
8
  *
9
9
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
10
10
  */
11
- export declare function toPageForProtocol3To5(page: InferOutput<typeof notionPageDataSchema>): NotionPageForProtocol3To5;
11
+ export declare function toPageForProtocol3To5(page: InferOutput<typeof bridgePageSchema>): NotionPageForProtocol3To5;
12
12
  /**
13
13
  * Converts a current page to a protocol 3–5 query row, keeping its ID and archive
14
14
  * flags while flattening typed property objects into raw-ID-keyed values.
@@ -17,7 +17,7 @@ export declare function toPageForProtocol3To5(page: InferOutput<typeof notionPag
17
17
  *
18
18
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
19
19
  */
20
- export declare function toQueryPageForProtocol3To5(page: InferOutput<typeof notionPageDataSchema>): {
20
+ export declare function toQueryPageForProtocol3To5(page: InferOutput<typeof bridgePageSchema>): {
21
21
  id: string & import("valibot").Brand<"NotionPageId">;
22
22
  is_archived: boolean;
23
23
  in_trash: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"pageForProtocol3To5.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageForProtocol3To5.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,yBAAyB,EAEzB,oBAAoB,EACpB,MAAM,gDAAgD,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,GAC5C,yBAAyB,CAe3B;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsB9C"}
1
+ {"version":3,"file":"pageForProtocol3To5.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageForProtocol3To5.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAChB,yBAAyB,EAEzB,MAAM,gDAAgD,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,WAAW,CAAC,OAAO,gBAAgB,CAAC,GACxC,yBAAyB,CAe3B;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,WAAW,CAAC,OAAO,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsB1C"}
@@ -1,9 +1,9 @@
1
- import type { notionPageDataSchema } from "../protocol/pages/page.js";
1
+ import type { bridgePageSchema } from "../protocol/pages/page.js";
2
2
  import type { InferOutput } from "valibot";
3
3
  /**
4
4
  * Shared field conversion for receivers that cannot decode text fallback objects.
5
5
  *
6
6
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 7.
7
7
  */
8
- export declare function toPageWithNullTextFallbackProperties(page: InferOutput<typeof notionPageDataSchema>): InferOutput<typeof notionPageDataSchema>;
8
+ export declare function toPageWithNullTextFallbackProperties(page: InferOutput<typeof bridgePageSchema>): InferOutput<typeof bridgePageSchema>;
9
9
  //# sourceMappingURL=pageWithNullTextFallbackProperties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pageWithNullTextFallbackProperties.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageWithNullTextFallbackProperties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C;;;;GAIG;AACH,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,GAC5C,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAyC1C"}
1
+ {"version":3,"file":"pageWithNullTextFallbackProperties.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageWithNullTextFallbackProperties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C;;;;GAIG;AACH,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,WAAW,CAAC,OAAO,gBAAgB,CAAC,GACxC,WAAW,CAAC,OAAO,gBAAgB,CAAC,CAyCtC"}
@@ -1,5 +1,5 @@
1
1
  import * as v from "valibot";
2
- import { notionPageDataSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
2
+ import { bridgePageSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
3
3
  // The schema accepts any string code. The type lists known codes for
4
4
  // autocomplete, with an open string fallback for newer senders.
5
5
  export const customBlockCreatePageErrorCodeSchema = v.string();
@@ -17,7 +17,7 @@ export const createPageResultMessageSchema = v.variant("status", [
17
17
  requestId: v.string(),
18
18
  status: v.literal("success"),
19
19
  /** The newly created page. */
20
- page: notionPageDataSchema,
20
+ page: bridgePageSchema,
21
21
  }),
22
22
  v.object({
23
23
  type: v.literal("createPageResult"),
@@ -32,7 +32,7 @@ export const createPageResultMessageWithProtocol3To5CompatibilitySchema = v.vari
32
32
  requestId: v.string(),
33
33
  status: v.literal("success"),
34
34
  /** The newly created page. */
35
- page: v.union([notionPageDataSchema, notionPageForProtocol3To5Schema]),
35
+ page: v.union([bridgePageSchema, notionPageForProtocol3To5Schema]),
36
36
  }),
37
37
  v.object({
38
38
  type: v.literal("createPageResult"),
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { notionDataSourceIdSchema, notionPageIdSchema } from "../ids.js";
3
- import { notionPageDataSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
3
+ import { bridgePageSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
4
4
  // The schema accepts any string code. The type lists known codes for
5
5
  // autocomplete, with an open string fallback for newer senders.
6
6
  export const customBlockGetPageErrorCodeSchema = v.string();
@@ -23,7 +23,7 @@ export const getPageResultMessageSchema = v.variant("status", [
23
23
  type: v.literal("getPageResult"),
24
24
  requestId: v.string(),
25
25
  status: v.literal("success"),
26
- page: notionPageDataSchema,
26
+ page: bridgePageSchema,
27
27
  }),
28
28
  v.object({
29
29
  type: v.literal("getPageResult"),
@@ -37,7 +37,7 @@ export const getPageResultMessageWithProtocol3To5CompatibilitySchema = v.variant
37
37
  type: v.literal("getPageResult"),
38
38
  requestId: v.string(),
39
39
  status: v.literal("success"),
40
- page: v.union([notionPageDataSchema, notionPageForProtocol3To5Schema]),
40
+ page: v.union([bridgePageSchema, notionPageForProtocol3To5Schema]),
41
41
  }),
42
42
  v.object({
43
43
  type: v.literal("getPageResult"),
@@ -3,6 +3,10 @@ export declare const customBlockRelationFilterOperatorSchema: v.UnionSchema<[v.S
3
3
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
4
4
  }, undefined>, v.StrictObjectSchema<{
5
5
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
6
+ }, undefined>, v.StrictObjectSchema<{
7
+ readonly is_empty: v.LiteralSchema<true, undefined>;
8
+ }, undefined>, v.StrictObjectSchema<{
9
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
6
10
  }, undefined>], undefined>;
7
11
  export type CustomBlockRelationFilterOperator = v.InferOutput<typeof customBlockRelationFilterOperatorSchema>;
8
12
  declare const customBlockPersonFilterValueSchema: v.StrictObjectSchema<{
@@ -180,6 +184,10 @@ export declare const resolvedCustomBlockDataSourcePropertyFilterSchema: v.UnionS
180
184
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
181
185
  }, undefined>, v.StrictObjectSchema<{
182
186
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
187
+ }, undefined>, v.StrictObjectSchema<{
188
+ readonly is_empty: v.LiteralSchema<true, undefined>;
189
+ }, undefined>, v.StrictObjectSchema<{
190
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
183
191
  }, undefined>], undefined>;
184
192
  }, undefined>, v.StrictObjectSchema<{
185
193
  readonly propertyId: v.StringSchema<undefined>;
@@ -428,6 +436,10 @@ export declare const resolvedCustomBlockDataSourceFilterSchema: v.UnionSchema<[v
428
436
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
429
437
  }, undefined>, v.StrictObjectSchema<{
430
438
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
439
+ }, undefined>, v.StrictObjectSchema<{
440
+ readonly is_empty: v.LiteralSchema<true, undefined>;
441
+ }, undefined>, v.StrictObjectSchema<{
442
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
431
443
  }, undefined>], undefined>;
432
444
  }, undefined>, v.StrictObjectSchema<{
433
445
  readonly propertyId: v.StringSchema<undefined>;
@@ -675,6 +687,10 @@ export declare const resolvedCustomBlockDataSourceFilterSchema: v.UnionSchema<[v
675
687
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
676
688
  }, undefined>, v.StrictObjectSchema<{
677
689
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
690
+ }, undefined>, v.StrictObjectSchema<{
691
+ readonly is_empty: v.LiteralSchema<true, undefined>;
692
+ }, undefined>, v.StrictObjectSchema<{
693
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
678
694
  }, undefined>], undefined>;
679
695
  }, undefined>, v.StrictObjectSchema<{
680
696
  readonly propertyId: v.StringSchema<undefined>;
@@ -947,6 +963,10 @@ export declare const queryDataSourceMessageSchema: v.ObjectSchema<{
947
963
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
948
964
  }, undefined>, v.StrictObjectSchema<{
949
965
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
966
+ }, undefined>, v.StrictObjectSchema<{
967
+ readonly is_empty: v.LiteralSchema<true, undefined>;
968
+ }, undefined>, v.StrictObjectSchema<{
969
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
950
970
  }, undefined>], undefined>;
951
971
  }, undefined>, v.StrictObjectSchema<{
952
972
  readonly propertyId: v.StringSchema<undefined>;
@@ -1194,6 +1214,10 @@ export declare const queryDataSourceMessageSchema: v.ObjectSchema<{
1194
1214
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
1195
1215
  }, undefined>, v.StrictObjectSchema<{
1196
1216
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
1217
+ }, undefined>, v.StrictObjectSchema<{
1218
+ readonly is_empty: v.LiteralSchema<true, undefined>;
1219
+ }, undefined>, v.StrictObjectSchema<{
1220
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
1197
1221
  }, undefined>], undefined>;
1198
1222
  }, undefined>, v.StrictObjectSchema<{
1199
1223
  readonly propertyId: v.StringSchema<undefined>;
@@ -8,6 +8,8 @@ const relationPageIdSchema = v.pipe(notionPageIdSchema, v.regex(/^(?:[0-9a-f]{32
8
8
  export const customBlockRelationFilterOperatorSchema = v.union([
9
9
  v.strictObject({ contains: relationPageIdSchema }),
10
10
  v.strictObject({ does_not_contain: relationPageIdSchema }),
11
+ v.strictObject({ is_empty: v.literal(true) }),
12
+ v.strictObject({ is_not_empty: v.literal(true) }),
11
13
  ]);
12
14
  const emptyOperatorSchema = v.union([
13
15
  v.strictObject({ is_empty: v.literal(true) }),
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { notionDataSourcePageForProtocol3To5Schema } from "../dataSources/dataSourcePage.js";
3
- import { notionPageDataSchema } from "../pages/page.js";
3
+ import { bridgePageSchema } from "../pages/page.js";
4
4
  // The schema accepts any string code. The type lists known codes for
5
5
  // autocomplete, with an open string fallback for newer senders.
6
6
  export const customBlockQueryDataSourceErrorCodeSchema = v.string();
@@ -17,7 +17,7 @@ export const queryDataSourceResultMessageSchema = v.variant("status", [
17
17
  type: v.literal("queryDataSourceResult"),
18
18
  subscriptionId: v.string(),
19
19
  status: v.literal("success"),
20
- items: v.array(notionPageDataSchema),
20
+ items: v.array(bridgePageSchema),
21
21
  hasMore: v.boolean(),
22
22
  }),
23
23
  v.object({
@@ -32,10 +32,7 @@ export const queryDataSourceResultMessageWithProtocol3To5CompatibilitySchema = v
32
32
  type: v.literal("queryDataSourceResult"),
33
33
  subscriptionId: v.string(),
34
34
  status: v.literal("success"),
35
- items: v.array(v.union([
36
- notionPageDataSchema,
37
- notionDataSourcePageForProtocol3To5Schema,
38
- ])),
35
+ items: v.array(v.union([bridgePageSchema, notionDataSourcePageForProtocol3To5Schema])),
39
36
  hasMore: v.boolean(),
40
37
  }),
41
38
  v.object({
@@ -71,6 +71,10 @@ export declare const sandboxToHostMessageSchema: v.VariantSchema<"type", [v.Vari
71
71
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
72
72
  }, undefined>, v.StrictObjectSchema<{
73
73
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
74
+ }, undefined>, v.StrictObjectSchema<{
75
+ readonly is_empty: v.LiteralSchema<true, undefined>;
76
+ }, undefined>, v.StrictObjectSchema<{
77
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
74
78
  }, undefined>], undefined>;
75
79
  }, undefined>, v.StrictObjectSchema<{
76
80
  readonly propertyId: v.StringSchema<undefined>;
@@ -318,6 +322,10 @@ export declare const sandboxToHostMessageSchema: v.VariantSchema<"type", [v.Vari
318
322
  readonly contains: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
319
323
  }, undefined>, v.StrictObjectSchema<{
320
324
  readonly does_not_contain: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>, v.RegexAction<string & v.Brand<"NotionPageId">, undefined>, v.TransformAction<string & v.Brand<"NotionPageId">, string>]>;
325
+ }, undefined>, v.StrictObjectSchema<{
326
+ readonly is_empty: v.LiteralSchema<true, undefined>;
327
+ }, undefined>, v.StrictObjectSchema<{
328
+ readonly is_not_empty: v.LiteralSchema<true, undefined>;
321
329
  }, undefined>], undefined>;
322
330
  }, undefined>, v.StrictObjectSchema<{
323
331
  readonly propertyId: v.StringSchema<undefined>;
@@ -1,5 +1,5 @@
1
1
  import * as v from "valibot";
2
- import { notionPageDataSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
2
+ import { bridgePageSchema, notionPageForProtocol3To5Schema, } from "../pages/page.js";
3
3
  // The schema accepts any string code. The type lists known codes for
4
4
  // autocomplete, with an open string fallback for newer senders.
5
5
  export const customBlockUpdatePageErrorCodeSchema = v.string();
@@ -16,7 +16,7 @@ export const updatePageResultMessageSchema = v.variant("status", [
16
16
  type: v.literal("updatePageResult"),
17
17
  requestId: v.string(),
18
18
  status: v.literal("success"),
19
- page: notionPageDataSchema,
19
+ page: bridgePageSchema,
20
20
  }),
21
21
  v.object({
22
22
  type: v.literal("updatePageResult"),
@@ -30,7 +30,7 @@ export const updatePageResultMessageWithProtocol3To5CompatibilitySchema = v.vari
30
30
  type: v.literal("updatePageResult"),
31
31
  requestId: v.string(),
32
32
  status: v.literal("success"),
33
- page: v.union([notionPageDataSchema, notionPageForProtocol3To5Schema]),
33
+ page: v.union([bridgePageSchema, notionPageForProtocol3To5Schema]),
34
34
  }),
35
35
  v.object({
36
36
  type: v.literal("updatePageResult"),
@@ -848,7 +848,7 @@ export type NotionPagePropertyWriteMap = v.InferInput<typeof notionPagePropertyW
848
848
  /**
849
849
  * The `Page` object returned in `createPageResult` messages.
850
850
  */
851
- export declare const notionPageDataSchema: v.ObjectSchema<{
851
+ export declare const bridgePageSchema: v.ObjectSchema<{
852
852
  readonly object: v.LiteralSchema<"page", undefined>;
853
853
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
854
854
  readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
@@ -1138,7 +1138,7 @@ export declare const notionPageDataSchema: v.ObjectSchema<{
1138
1138
  /** Whether the page or an ancestor is in Trash. */
1139
1139
  readonly in_trash: v.BooleanSchema<undefined>;
1140
1140
  }, undefined>;
1141
- export type NotionPageData = v.InferInput<typeof notionPageDataSchema>;
1141
+ export type BridgePage = v.InferInput<typeof bridgePageSchema>;
1142
1142
  export declare const notionPageForProtocol3To5Schema: v.ObjectSchema<{
1143
1143
  readonly object: v.LiteralSchema<"page", undefined>;
1144
1144
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
@@ -281,7 +281,7 @@ export const notionPagePropertyReadMapSchema = v.record(v.string(), v.nullable(n
281
281
  /**
282
282
  * The `Page` object returned in `createPageResult` messages.
283
283
  */
284
- export const notionPageDataSchema = v.object({
284
+ export const bridgePageSchema = v.object({
285
285
  object: v.literal("page"),
286
286
  id: notionPageIdSchema,
287
287
  parent: notionParentSchema,
@@ -137,6 +137,13 @@ creators in exclusion results.
137
137
  Status filters support option operators and stored group names. Group operators accept one name or
138
138
  an array of 1–5 names. Hosts must validate each name against the bound Status property.
139
139
 
140
+ #### Relation filters
141
+
142
+ Relation filters require an actual `relation` property in the bound schema. `contains` and
143
+ `does_not_contain` accept one page ID. `is_empty` and `is_not_empty` accept only `true` and require
144
+ no page ID. Each relation filter accepts exactly one operator. Adapters must evaluate empty checks
145
+ against relation values, including XLDB row IDs where supported.
146
+
140
147
  #### Date filters
141
148
 
142
149
  Date comparisons accept ISO values and relative values such as `today`. The query schema defines the
@@ -168,10 +175,10 @@ must carry the same raw property ID in its `id` field.
168
175
 
169
176
  ## Page responses
170
177
 
171
- Host handlers return unified `NotionPageData` for queries and page operations. Properties use
172
- display names as keys and typed values that include their raw property IDs. Only actual schema
173
- properties are returned. Query results contain `items` and `hasMore`. `notionPageDataSchema` defines
174
- the page fields, including archive state and creation, edit, and visit metadata.
178
+ Host handlers return unified `BridgePage` for queries and page operations. Properties use display
179
+ names as keys and typed values that include their raw property IDs. Only actual schema properties
180
+ are returned. Query results contain `items` and `hasMore`. `bridgePageSchema` defines the page
181
+ fields, including archive state and creation, edit, and visit metadata.
175
182
 
176
183
  Page reads return string values for `unique_id`, `formula`, `rollup`, `button`, `verification`, and
177
184
  `location`, preserving each property's type. These properties are read-only. Values use stored text,
package/docs/handlers.md CHANGED
@@ -42,7 +42,7 @@ import type {
42
42
  CustomBlockHostDataSourcesPayload,
43
43
  CustomBlockHostHandlers,
44
44
  } from "@notionhq/custom-blocks-host"
45
- import type { CustomBlockManifest, NotionPageData } from "@notionhq/custom-blocks-host/protocol"
45
+ import type { CustomBlockManifest, BridgePage } from "@notionhq/custom-blocks-host/protocol"
46
46
 
47
47
  const tasksId = "44444444-4444-4444-8444-444444444444"
48
48
 
@@ -109,7 +109,7 @@ const handlers: CustomBlockHostHandlers = {
109
109
  }
110
110
  }
111
111
 
112
- const items: NotionPageData[] = [
112
+ const items: BridgePage[] = [
113
113
  {
114
114
  object: "page",
115
115
  id: "55555555-5555-4555-8555-555555555555",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-host",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Reusable host runtime for Notion custom blocks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,8 +1,8 @@
1
1
  import type { NotionDataSourceValue } from "@notionhq/custom-blocks-protocol/dataSources/dataSourceValue.js"
2
2
  import type {
3
+ bridgePageSchema,
3
4
  NotionPageForProtocol3To5,
4
5
  NotionPagePropertyValue,
5
- notionPageDataSchema,
6
6
  } from "@notionhq/custom-blocks-protocol/pages/page.js"
7
7
  import type { InferOutput } from "valibot"
8
8
  import { toNotionDateValue } from "../dateValue.js"
@@ -17,7 +17,7 @@ import { unreachable } from "../utils.js"
17
17
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
18
18
  */
19
19
  export function toPageForProtocol3To5(
20
- page: InferOutput<typeof notionPageDataSchema>,
20
+ page: InferOutput<typeof bridgePageSchema>,
21
21
  ): NotionPageForProtocol3To5 {
22
22
  return {
23
23
  ...page,
@@ -44,7 +44,7 @@ export function toPageForProtocol3To5(
44
44
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
45
45
  */
46
46
  export function toQueryPageForProtocol3To5(
47
- page: InferOutput<typeof notionPageDataSchema>,
47
+ page: InferOutput<typeof bridgePageSchema>,
48
48
  ) {
49
49
  const propertiesById: Record<string, NotionDataSourceValue | undefined> = {}
50
50
  for (const property of Object.values(page.properties)) {
@@ -1,4 +1,4 @@
1
- import type { notionPageDataSchema } from "@notionhq/custom-blocks-protocol/pages/page.js"
1
+ import type { bridgePageSchema } from "@notionhq/custom-blocks-protocol/pages/page.js"
2
2
  import type { InferOutput } from "valibot"
3
3
  import { unreachable } from "../utils.js"
4
4
 
@@ -8,8 +8,8 @@ import { unreachable } from "../utils.js"
8
8
  * Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 7.
9
9
  */
10
10
  export function toPageWithNullTextFallbackProperties(
11
- page: InferOutput<typeof notionPageDataSchema>,
12
- ): InferOutput<typeof notionPageDataSchema> {
11
+ page: InferOutput<typeof bridgePageSchema>,
12
+ ): InferOutput<typeof bridgePageSchema> {
13
13
  return {
14
14
  ...page,
15
15
  properties: Object.fromEntries(