@notionhq/custom-blocks-host 0.3.8 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,8 @@ prepares initialization, validates messages, routes requests, manages query subs
5
5
  cleans up the connection.
6
6
 
7
7
  The embedding application creates the iframe and supplies permissions, record access, bindings,
8
- persistence, analytics, and UI. Both Notion and the dev shell use this package.
8
+ persistence, analytics, and UI. Both Notion and the dev shell use this package. Block authors use
9
+ `@notionhq/custom-blocks` instead; they do not need to create a host.
9
10
 
10
11
  ## `createCustomBlockHost()`
11
12
 
@@ -63,8 +64,10 @@ manifest comes from:
63
64
  seconds. This source has no callback or persisted fallback. Local refers to the block server, not
64
65
  the host's environment.
65
66
 
66
- Hosts and SDKs use one [manifest schema](../protocol/README.md#manifests), including optional block
67
- metadata. The host validates and normalizes the manifest, then calls
67
+ A manifest declares data sources by semantic key, with property schemas and optional block metadata
68
+ (`name`, `description`, `slashCommand`, and emoji `icon`). If `dataSources` is omitted, it defaults
69
+ to `{}`. Each data source's `properties` also defaults to `{}` when omitted. Hosts and SDKs use the
70
+ same manifest shape. The host validates and normalizes the manifest, then calls
68
71
  `prepareInitialState({ manifest, signal })` once. The embedding application uses that manifest to
69
72
  prepare context and bindings, and returns them in `initialState`. The host includes the manifest
70
73
  with that state in `init`.
@@ -80,6 +83,16 @@ remain generic. Stopping the host cancels preparation without logging a cancella
80
83
  The embedding application can load saved definitions separately during local preview, for example to
81
84
  restore saved bindings after preview ends. Local initialization does not wait for those reads.
82
85
 
86
+ ### Property compatibility
87
+
88
+ The host selects page and query property shapes using `connect.bridgeProtocolVersion`. Protocol 7
89
+ receives unique ID, button, formula, location, rollup, and verification property objects with text
90
+ fallbacks. Protocol 6 receives `null` for those properties while retaining supported properties.
91
+ This also applies to recent SDKs that briefly supported the richer values while still reporting
92
+ protocol 6; those blocks must upgrade their SDK and rebuild to regain the values. Protocols 3–5
93
+ retain flat query values and omit unsupported property objects from page responses. The host
94
+ continues accepting older protocols; `sdkVersion` remains analytics metadata.
95
+
83
96
  ### Connection lifecycle
84
97
 
85
98
  Each host handles one handshake with one iframe:
@@ -174,9 +187,8 @@ The host validates inbound messages, correlates handshake IDs, and rejects malfo
174
187
  Malformed messages do not restart initialization. The host logs and ignores stale valid `initResult`
175
188
  messages.
176
189
 
177
- See the protocol's [initialization contract](../protocol/README.md#initialization) and
178
- [validation and error rules](../protocol/README.md#validation-and-errors) for message shapes and
179
- failure behavior.
190
+ The runtime owns the wire handshake and message validation. Integrators use the callbacks and
191
+ handlers above; they do not need to construct or validate bridge messages themselves.
180
192
 
181
193
  ## Updating live state
182
194
 
@@ -239,10 +251,9 @@ Content Security Policy.
239
251
 
240
252
  ## Wire protocol
241
253
 
242
- The host package bundles the shared [protocol](../protocol/README.md) and exposes its public types.
243
- Use the host APIs instead of posting bridge messages directly or importing protocol implementation
244
- files. Runtime source imports schemas from the workspace protocol package; the publish build bundles
245
- that dependency into the host package.
254
+ The host package bundles the wire protocol and exposes its public types. Use the host APIs instead
255
+ of posting bridge messages directly or importing protocol implementation files. The protocol is
256
+ included in the package; no separate protocol dependency is needed.
246
257
 
247
258
  ## Date conversion
248
259
 
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- var $e=6,Qe=6;function vn(e){let{manifestProperties:t,propertySchemasById:s}=e,i=[];for(let[c,l]of Object.entries(t)){let p=dn({propertyKey:c,manifestProperty:l,propertySchemasById:s});p!==void 0&&i.push([c,p])}return Object.fromEntries(i)}function dn(e){let{propertyKey:t,manifestProperty:s,propertySchemasById:i}=e,c=bt(s.name),l=Object.entries(i).filter(([p,y])=>y.type===s.type&&(p===t||bt(y.name)===c));return l.length===1?l[0][0]:void 0}function bt(e){return e.trim().toLowerCase()}var qe,hn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Xe(e){return!e&&!qe?hn:{lang:e?.lang??qe?.lang,message:e?.message,abortEarly:e?.abortEarly??qe?.abortEarly,abortPipeEarly:e?.abortPipeEarly??qe?.abortPipeEarly}}var gn;function bn(e){return gn?.get(e)}var Sn;function kn(e){return Sn?.get(e)}var In;function _n(e,t){return In?.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,s,i,c){let l=c&&"input"in c?c.input:s.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:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},x=e.kind==="schema",_=c?.message??e.message??_n(e.reference,m.lang)??(x?kn(m.lang):null)??i.message??bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(s.typed=!1),s.issues?s.issues.push(m):s.issues=[m]}var St=new WeakMap;function Q(e){let t=St.get(e);return t||(t={version:1,vendor:"valibot",validate(s){return e["~run"]({value:s},Xe())}},St.set(e,t)),t}function xn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function We(e,t){let s=[...new Set(e)];return s.length>1?`(${s.join(` ${t} `)})`:s[0]??"never"}var Cn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ce(e){return{kind:"transformation",type:"brand",reference:ce,async:!1,name:e,"~run"(t){return t}}}function Ie(e){return{kind:"validation",type:"finite",reference:Ie,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,s){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,s),t}}}function Je(e,t){let s=he(e);return{kind:"validation",type:"includes",reference:Je,async:!1,expects:s,requirement:e,message:t,"~run"(i,c){return i.typed&&!i.value.includes(this.requirement)&&w(this,"content",i,c,{received:`!${s}`}),i}}}function Te(e,t){return{kind:"validation",type:"max_length",reference:Te,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&s.value.length>this.requirement&&w(this,"length",s,i,{received:`${s.value.length}`}),s}}}function _e(e,t){return{kind:"validation",type:"min_length",reference:_e,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&s.value.length<this.requirement&&w(this,"length",s,i,{received:`${s.value.length}`}),s}}}function xe(e,t){return{kind:"validation",type:"min_value",reference:xe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(s,i){return s.typed&&!(s.value>=this.requirement)&&w(this,"value",s,i,{received:s.value instanceof Date?s.value.toJSON():he(s.value)}),s}}}function Ke(e,t){return{kind:"validation",type:"regex",reference:Ke,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&!this.requirement.test(s.value)&&w(this,"format",s,i),s}}}function Ze(e){return{kind:"transformation",type:"transform",reference:Ze,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var It={abortEarly:!0};function _t(e,t,s){return typeof e.fallback=="function"?e.fallback(t,s):e.fallback}function Ae(e,t,s){return typeof e.default=="function"?e.default(t,s):e.default}function xt(e,t){return!e["~run"]({value:t},It).issues}function E(e,t){return{kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(Array.isArray(c)){s.typed=!0,s.value=[];for(let l=0;l<c.length;l++){let p=c[l],y=this.item["~run"]({value:p},i);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],s.issues?.push(x);if(s.issues||(s.issues=y.issues),i.abortEarly){s.typed=!1;break}}y.typed||(s.typed=!1),s.value.push(y.value)}}else w(this,"type",s,i);return s}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,s),t}}}function o(e,t){return{kind:"schema",type:"literal",reference:o,expects:he(e),async:!1,literal:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===this.literal?s.typed=!0:w(this,"type",s,i),s}}}function Ye(e){return{kind:"schema",type:"nan",reference:Ye,expects:"NaN",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,s),t}}}function F(e,t){return{kind:"schema",type:"nullable",reference:F,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===null&&(this.default!==void 0&&(s.value=Ae(this,s,i)),s.value===null)?(s.typed=!0,s):this.wrapped["~run"](s,i)}}}function P(e){return{kind:"schema",type:"number",reference:P,expects:"number",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,s),t}}}function n(e,t){return{kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(c&&typeof c=="object"){s.typed=!0,s.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]:Ae(p),m=p["~run"]({value:y},i);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],s.issues?.push(_);if(s.issues||(s.issues=m.issues),i.abortEarly){s.typed=!1;break}}m.typed||(s.typed=!1),s.value[l]=m.value}else if(p.fallback!==void 0)s.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",s,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}}else w(this,"type",s,i);return s}}}function u(e,t){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===void 0&&(this.default!==void 0&&(s.value=Ae(this,s,i)),s.value===void 0)?(s.typed=!0,s):this.wrapped["~run"](s,i)}}}function T(e,t){return{kind:"schema",type:"picklist",reference:T,expects:We(e.map(he),"|"),async:!1,options:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){return this.options.includes(s.value)?s.typed=!0:w(this,"type",s,i),s}}}function V(e,t,s){return{kind:"schema",type:"record",reference:V,expects:"Object",async:!1,key:e,value:t,message:s,get"~standard"(){return Q(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){i.typed=!0,i.value={};for(let p in l)if(xn(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 C of m.issues)C.path=[_],i.issues?.push(C);if(i.issues||(i.issues=m.issues),c.abortEarly){i.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 C of x.issues)C.path?C.path.unshift(_):C.path=[_],i.issues?.push(C);if(i.issues||(i.issues=x.issues),c.abortEarly){i.typed=!1;break}}(!m.typed||!x.typed)&&(i.typed=!1),m.typed&&(i.value[m.value]=x.value)}}else w(this,"type",i,c);return i}}}function f(e,t){return{kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(c&&typeof c=="object"){s.typed=!0,s.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]:Ae(p),m=p["~run"]({value:y},i);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],s.issues?.push(_);if(s.issues||(s.issues=m.issues),i.abortEarly){s.typed=!1;break}}m.typed||(s.typed=!1),s.value[l]=m.value}else if(p.fallback!==void 0)s.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",s,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}if(!s.issues||!i.abortEarly){for(let l in c)if(!(l in this.entries)){w(this,"key",s,i,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",s,i);return s}}}function r(e){return{kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,s),t}}}function kt(e){let t;if(e)for(let s of e)if(t)for(let i of s.issues)t.push(i);else t=s.issues;return t}function g(e,t){return{kind:"schema",type:"union",reference:g,expects:We(e.map(s=>s.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c,l,p;for(let y of this.options){let m=y["~run"]({value:s.value},i);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",s,i,{issues:kt(l)}),s.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",s,i,{issues:kt(p)})}return s}}}function Ce(){return{kind:"schema",type:"unknown",reference:Ce,expects:"unknown",async:!1,get"~standard"(){return Q(this)},"~run"(e){return e.typed=!0,e}}}function v(e,t,s){return{kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:s,get"~standard"(){return Q(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(C,b)=>{for(let L of C.options){if(L.type==="variant")_(L,new Set(b).add(L.key));else{let q=!0,A=0;for(let O of b){let H=L.entries[O];if(O in l?H["~run"]({typed:!1,value:l[O]},It).issues:H.type!=="exact_optional"&&H.type!=="optional"&&H.type!=="nullish"){q=!1,m!==O&&(y<A||y===A&&O in l&&!(m in l))&&(y=A,m=O,x=[]),m===O&&x.push(L.entries[O].expects);break}A++}if(q){let O=L["~run"]({value:l},c);(!p||!p.typed&&O.typed)&&(p=O)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",i,c,{input:l[m],expected:We(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",i,c);return i}}}function ie(e,t,s){let i=e["~run"]({value:t},Xe(s));if(i.issues)throw new Cn(i.issues);return i.value}function z(...e){return{...e[0],pipe:e,get"~standard"(){return Q(this)},"~run"(t,s){for(let i of e)if(i.kind!=="metadata"){if(t.issues&&(i.kind==="schema"||i.kind==="transformation")){t.typed=!1;break}(!t.issues||!s.abortEarly&&!s.abortPipeEarly)&&(t=i["~run"](t,s))}return t}}}function Pe(e,t,s){let i=e["~run"]({value:t},Xe(s));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}var le=z(r(),ce("NotionBlockId")),K=z(r(),ce("NotionDataSourceId")),U=z(r(),ce("NotionPageId")),Ct=z(r(),ce("NotionAgentId")),Pt=z(r(),ce("NotionSpaceId"));var Et=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"]),et=n({id:r(),name:r(),color:u(Et),description:u(r())}),Pn=n({id:r(),name:r(),color:u(Et),option_ids:E(r())}),En=n({synced_property_id:r(),synced_property_name:r()}),R=n({name:r(),description:u(r())}),On=["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"],Ot=T(On),jt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],tt=v("type",[n({...R.entries,type:o("title")}),n({...R.entries,type:o("rich_text")}),n({...R.entries,type:o("number")}),n({...R.entries,type:o("checkbox")}),n({...R.entries,type:o("url")}),n({...R.entries,type:o("email")}),n({...R.entries,type:o("phone_number")}),n({...R.entries,type:o("select"),options:E(et)}),n({...R.entries,type:o("multi_select"),options:E(et)}),n({...R.entries,type:o("status"),options:E(et),groups:E(Pn)}),n({...R.entries,type:o("date")}),n({...R.entries,type:o("people")}),n({...R.entries,type:o("files")}),n({...R.entries,type:o("unique_id")}),n({...R.entries,type:o("relation"),data_source_id:u(r()),dual_property:u(En)}),n({...R.entries,type:o("place")}),n({...R.entries,type:o("formula")}),n({...R.entries,type:o("rollup")}),n({...R.entries,type:o("button")}),n({...R.entries,type:o("verification")}),n({...R.entries,type:o("last_visited_time")}),n({...R.entries,type:o("location")}),n({...R.entries,type:o("created_time")}),n({...R.entries,type:o("last_edited_time")}),n({...R.entries,type:o("created_by")}),n({...R.entries,type:o("last_edited_by")})]);var Rt=n({id:K,table:r(),spaceId:u(Pt)}),Mt=n({id:u(K),propertiesById:V(r(),tt)}),$o=n({key:r(),collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:V(r(),u(r())),propertySchemasById:V(r(),tt)}),jn=n({collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:u(V(r(),u(r())))}),me=V(r(),jn);var ge=T(["standard","high"]),Bt="standard";var Dt=n({type:o("contrastModeChanged"),contrastMode:ge});var Ne=n({unit:T(["year","month","week","day"]),value:P(),time:r(),defaultTimeZone:u(r())}),Rn=n({unit:T(["hour","minute"]),value:P()}),Ee=n({unit:o("none")}),rt=g([Ne,Rn]),wt=u(g([Ne,Ee])),qt=u(g([rt,Ee])),Mn=n({type:o("date"),start_date:r(),reminder:wt}),Bn=n({type:o("daterange"),start_date:r(),end_date:r(),reminder:wt}),Dn=n({type:o("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:qt}),wn=n({type:o("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:qt}),Tt=v("type",[Mn,Bn,Dn,wn]);var Ue=n({id:r(),table:r()});var ae=v("type",[n({type:o("page_id"),page_id:U}),n({type:o("data_source_id"),data_source_id:K}),n({type:o("workspace"),workspace:o(!0)}),n({type:o("block_id"),block_id:le}),n({type:o("agent_id"),agent_id:Ct}),n({type:o("unavailable")})]);var be=v("type",[n({type:o("unavailable")}),n({type:o("page"),id:U,parent:ae})]),qn=n({type:o("emoji"),emoji:r()}),Tn=n({type:o("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),Nt=n({type:o("external"),external:n({url:r()})}),Ut=n({type:o("file"),file:n({url:r(),expiry_time:u(r())})}),ze=v("type",[qn,Tn,Nt,Ut]),Le=v("type",[Nt,Ut]),Z=F(r()),At=V(r(),Ce()),nt=g([n({id:r(),name:u(r()),color:u(r()),description:u(Z)}),n({name:r(),id:u(r()),color:u(r()),description:u(Z)})]),ot={start:r(),end:u(Z),time_zone:u(Z),reminder:u(g([rt,Ee]))},An=g([n({...ot,start:z(r(),Je("T"))}),n({...ot,time_zone:r()}),n({...ot,reminder:u(g([Ne,Ee]))})]),Nn=g([n({object:u(o("user")),id:r()}),n({object:o("group"),id:r(),name:u(Z)})]),Un=n({id:r()}),Fn=g([n({type:o("external"),name:r(),external:n({url:r()})}),n({type:o("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),zn=n({lat:P(),lon:P(),name:u(Z),address:u(Z),aws_place_id:u(Z),google_place_id:u(Z)}),M={id:r()},Fe=F(n({...Ue.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Ft=v("type",[n({...M,type:o("title"),title:E(At)}),n({...M,type:o("rich_text"),rich_text:E(At)}),n({...M,type:o("number"),number:F(P())}),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:h()}),n({...M,type:o("select"),select:F(nt)}),n({...M,type:o("status"),status:F(nt)}),n({...M,type:o("multi_select"),multi_select:E(nt)}),n({...M,type:o("date"),date:F(An)}),n({...M,type:o("people"),people:E(Nn)}),n({...M,type:o("relation"),has_more:u(h()),relation:E(Un)}),n({...M,type:o("files"),files:E(Fn)}),n({...M,type:o("place"),place:F(zn)}),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:Fe}),n({...M,type:o("last_edited_by"),last_edited_by:Fe}),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()})]),Oe=V(r(),Ft),Ln=V(r(),F(Ft)),ne=n({object:o("page"),id:U,parent:ae,properties:Ln,created_by:u(Fe,null),last_edited_by:u(Fe,null),last_visited_time:u(F(r()),null),created_time:u(F(r()),null),last_edited_time:u(F(r()),null),icon:u(F(ze),null),cover:u(F(Le),null),url:u(F(r()),null),public_url:u(F(r()),null),is_archived:h(),in_trash:h()}),Se=n({object:o("page"),id:U,parent:ae,properties:Oe,created_time:u(r()),last_edited_time:u(r()),icon:u(ze),cover:u(Le),url:u(r()),public_url:u(r()),is_archived:h(),in_trash:h()});var Hn=r(),zt=n({code:Hn,message:r(),isRetryable:h()}),Lt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:zt})]),Ht=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:zt})]);var st=z(r(),ce("NotionUserId")),pe=n({object:o("user"),id:st,name:u(r()),avatar_url:F(r()),type:o("person"),person:n({email:r()})}),Vt=n({object:o("list"),results:E(pe),next_cursor:F(r()),has_more:h(),type:o("user"),user:V(r(),Ce())});var Gt=n({type:o("currentUserChanged"),currentUser:pe});var $t=n({type:o("dataSourcesChanged"),dataSources:n({bindings:me})});var Vn=r(),Qt=n({code:Vn,message:r(),isRetryable:h()}),Xt=n({type:o("getPage"),requestId:r(),pageId:U,dataSourceId:u(K)}),Wt=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:Qt})]),Jt=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:Qt})]);var Gn=r(),$n=n({code:Gn,message:r(),isRetryable:h()}),Kt=n({type:o("getUser"),requestId:r(),userId:st}),Zt=v("status",[n({type:o("getUserResult"),requestId:r(),status:o("success"),user:pe}),n({type:o("getUserResult"),requestId:r(),status:o("error"),error:$n})]);var Qn=v("type",[n({type:o("emoji"),emoji:r()}),n({type:o("external"),url:r()})]),Xn=n({name:r(),description:u(r()),type:Ot}),Wn=n({name:r(),description:u(r()),icon:u(Qn),properties:u(V(r(),Xn),{})}),ye=n({version:o(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:o("emoji"),emoji:r()})),dataSources:u(V(r(),Wn),{})});var ke=T(["light","dark"]);var Jn=r(),Kn=n({code:Jn,message:r(),isRetryable:h()});var He=v("status",[n({type:o("init"),initializationId:r(),status:o("success"),theme:ke,contrastMode:ge,blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe}),n({type:o("init"),initializationId:r(),status:o("error"),error:Kn})]);var Yt=n({type:o("invalidSandboxMessage"),reason:r()});var Zn=r(),Yn=n({code:Zn,message:r(),isRetryable:h()}),er=n({type:o("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(P())}),tr=v("status",[n({type:o("listUsersResult"),requestId:r(),status:o("success"),list:Vt}),n({type:o("listUsersResult"),requestId:r(),status:o("error"),error:Yn})]);var eo=r(),to=n({code:eo,message:r(),isRetryable:h()}),rr=n({type:o("openExternalUrl"),requestId:r(),url:r()}),nr=v("status",[n({type:o("openExternalUrlResult"),requestId:r(),status:o("success")}),n({type:o("openExternalUrlResult"),requestId:r(),status:o("error"),error:to})]);var ro=T(["side_peek","center_peek"]),no=r(),oo=n({code:no,message:r(),isRetryable:h()}),or=n({type:o("openPage"),requestId:r(),pageId:U,mode:ro}),sr=v("status",[n({type:o("openPageResult"),requestId:r(),status:o("success"),pageId:U}),n({type:o("openPageResult"),requestId:r(),status:o("error"),error:oo})]);var ir=n({type:o("pageChanged"),page:be});var ar=n({type:o("parentChanged"),parent:ae});var ur=g([r(),P(),h(),Tt,E(r()),E(Ue)]);var cr=n({id:U,is_archived:h(),in_trash:h(),propertiesById:V(r(),u(ur))});var so=r(),lr=n({code:so,message:r(),isRetryable:h()}),pr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:E(ne),hasMore:h()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:lr})]),fr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:E(g([ne,cr])),hasMore:h()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:lr})]);var mr=n({type:o("themeChanged"),theme:ke});var io=r(),yr=n({code:io,message:r(),isRetryable:h()}),vr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:yr})]),dr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:yr})]);var hr=v("type",[He,mr,Dt,ar,ir,Gt,$t,Zt,tr,sr,nr,Yt]),gr=v("type",[...hr.options,pr,Wt,Lt,vr]),vi=v("type",[...hr.options,fr,Jt,Ht,dr]);function br(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function Sr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function it(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function at(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:s}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${s}.`,isRetryable:!1}}function ut(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function kr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Ir(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function _r(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function xr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function Cr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Pr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function je(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function re(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function ct(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var ao=5e3,uo=5e3,co=5e3;function Er(e){let{prepareInit:t,sendInitMessage:s,warn:i,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:p=ao,initialStateTimeoutMs:y=uo,noInitResultTimeoutMs:m=co,stopHostWithFailure:x,onInitResult:_,onConnectionFailure:C}=e,b="waitingForConnect",L,q,A,O,H=!1,$=!1;function X(){L!==void 0&&(window.clearTimeout(L),L=void 0)}function ue(){q!==void 0&&(window.clearTimeout(q),q=void 0)}function W(){A!==void 0&&(window.clearTimeout(A),A=void 0)}function B(S){let{initializationId:I,error:J,phase:oe,source:N}=S;switch(b){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return re(b)}b="error",O=I,X(),ue(),s({type:"init",initializationId:I,status:"error",error:J}),C?.({...J,phase:oe,source:N})}async function G(S){if(b==="waitingForConnect"){b="preparingInit",O=S.initializationId,X(),q=window.setTimeout(()=>{if(b!=="preparingInit")return;let I=kr();i({...I,initializationId:S.initializationId}),B({initializationId:S.initializationId,error:I,phase:"init",source:"host"})},y);try{let I=await t(S);if(b!=="preparingInit")return;if(ue(),I.status==="error"){B({initializationId:S.initializationId,error:I.error,phase:"init",source:"host"});return}b="waitingForInitResult";let J={type:"init",initializationId:S.initializationId,status:"success",theme:I.initialState.theme,contrastMode:I.initialState.contrastMode??Bt,blockId:I.initialState.blockId,parent:I.initialState.parent,page:I.initialState.page,currentUser:I.initialState.currentUser,manifest:I.initialState.manifest,dataSources:I.initialState.dataSources};s(J),A=window.setTimeout(()=>{if(b!=="waitingForInitResult")return;b="error";let oe=Cr();C?.({...oe,phase:"initResult",source:"host"}),i({...oe,initializationId:S.initializationId})},m)}catch(I){if(b!=="preparingInit")return;i({message:"Failed to prepare custom block initialization",error:I}),B({initializationId:S.initializationId,error:je(),phase:"init",source:"host"})}}}function ee(S){if(b!=="stopped"&&b==="waitingForConnect"){if(!ct(S.bridgeProtocolVersion)){let I=it({currentBridgeProtocolVersion:S.bridgeProtocolVersion});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.bridgeProtocolVersion<l){let I=at({currentBridgeProtocolVersion:S.bridgeProtocolVersion,minBridgeProtocolVersion:l});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.status==="error"){B({initializationId:S.initializationId,error:S.error,phase:"connect",source:"sandbox"});return}$=!0,G(S)}}function se(S){if(b==="stopped"||b!=="waitingForConnect")return"handled";let{initializationId:I,bridgeProtocolVersion:J}=S;if(I===void 0)return"nack";let oe=S.error;return J!==void 0&&(ct(J)?J<l&&(oe=at({currentBridgeProtocolVersion:J,minBridgeProtocolVersion:l})):oe=it({currentBridgeProtocolVersion:J})),B({initializationId:I,error:oe,phase:"connect",source:"host"}),"handled"}function D(S){let{initializationId:I,error:J}=S;b!=="waitingForInitResult"||I===void 0||I!==O||(X(),W(),b="error",i(J),C?.({...J,phase:"initResult",source:"host"}))}function te(){if(b!=="stopped"){if(H){x({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}H=!0,X(),b==="waitingForConnect"&&(L=window.setTimeout(()=>{if(b!=="waitingForConnect")return;b="error";let S=br();i(S),C?.({...S,phase:"connect",source:"host"})},p))}}function fe(S){if(b!=="waitingForInitResult"||S.initializationId!==O){i({message:"Ignored stale or unexpected initResult",payload:S});return}W(),b=S.status==="success"?"initialized":"error",S.status==="success"?c():C?.({...S.error,phase:"initResult",source:"sandbox"}),_?.(S)}function we(){b="stopped",X(),ue(),W()}return{get status(){return b},get hasConnectedSandbox(){return $},handleConnect:ee,handleInitResult:fe,handleInvalidConnect:se,handleInvalidInitResult:D,onIframeLoad:te,stop:we}}function lt({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function Or(e){let t=new AbortController,s=()=>t.abort();e.signal.addEventListener("abort",s,{once:!0});let i=new Promise((l,p)=>{t.signal.addEventListener("abort",()=>p(t.signal.reason),{once:!0})});e.signal.aborted&&t.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{t.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?lo(e.sandboxOrigin,t.signal):e.getPersistedManifest({signal:t.signal}),i]);if(t.signal.aborted)throw new Error("Manifest loading was cancelled.");return{status:"success",manifest:ie(ye,l)}}catch(l){return e.signal.aborted||e.onError(l),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(c),e.signal.removeEventListener("abort",s)}}async function lo(e,t){let s=new URL(e);if(!lt({url:s,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let i=await fetch(new URL("/manifest",s),{credentials:"omit",redirect:"error",cache:"no-store",signal:t});if(!i.ok)throw new Error(`Manifest request failed: HTTP ${i.status}.`);return i.json()}var de=class extends Error{};function pt(e){try{return po(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function po(e){let{start:t,end:s,time_zone:i,reminder:c}=e;if(!t.split("T")[0])throw new de("Date values must include a date.");let l=t.includes("T")||i!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),y=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,m=i?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=m?(Number(m[2]??0)*60+Number(m[3]??0))*(m[1]==="-"?-1:1):y,_=q=>{if(!q.split("T")[0])throw new de("Date values must include a date.");if(!q.includes("T"))return{date:q,time:"00:00"};let A=q.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(A)return{date:A[1],time:A[2]};if(!i||m){let $=new Date(new Date(q).getTime()+x*6e4).toISOString();return{date:$.slice(0,10),time:$.slice(11,16)}}let O=new Intl.DateTimeFormat("en-CA",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(q)),H=$=>O.find(X=>X.type===$)?.value;return{date:`${H("year")}-${H("month")}-${H("day")}`,time:`${H("hour")}:${H("minute")}`}},C=_(t),b=s?_(s):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 b?{type:"daterange",start_date:C.date,end_date:b.date,reminder:c}:{type:"date",start_date:C.date,reminder:c}}let L=i??(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 b?{type:"datetimerange",start_date:C.date,start_time:C.time,end_date:b.date,end_time:b.time,time_zone:L,reminder:c}:{type:"datetime",start_date:C.date,start_time:C.time,time_zone:L,reminder:c}}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 Mr(e){let t={};for(let s of Object.values(e.properties))s&&(t[s.id]=fo(s));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:t}}function jr(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let s=t.text;return s&&typeof s=="object"&&"content"in s&&typeof s.content=="string"?s.content:""}).join("")}function ft(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 fo(e){switch(e.type){case"title":return jr(e.title);case"rich_text":return jr(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?pt(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 ft(e.created_time);case"last_edited_time":return ft(e.last_edited_time);case"last_visited_time":return ft(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 re(e)}}function Br(e,t){if(t>=6||e.status==="error")return e;switch(e.type){case"queryDataSourceResult":return{...e,items:e.items.map(Mr)};case"getPageResult":case"createPageResult":case"updatePageResult":return{...e,page:Rr(e.page)};default:return re(e)}}function Dr(e,t){return e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"?e:Br(e,t)}var wr=n({theme:ke,contrastMode:u(ge),blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe});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 Tr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Ar=n({code:r(),message:r(),isRetryable:h()});var Nr={type:o("connect"),initializationId:r(),bridgeProtocolVersion:P(),sdkVersion:r()},Ur=v("status",[n({status:o("success"),manifest:u(ye),...Nr}),n({status:o("error"),error:Ar,...Nr})]);var mo=v("type",[n({type:o("start")}),n({type:o("end")}),n({type:o("before"),blockId:le}),n({type:o("after"),blockId:le})]),yo=v("type",[n({type:o("page_id"),page_id:U}),n({type:o("data_source_id"),data_source_id:K})]),Fr=n({type:o("createPage"),requestId:r(),parent:yo,properties:Oe,position:u(mo)});var vo=r(),ho=n({code:vo,message:r(),isRetryable:h()}),zr=v("status",[n({type:o("initResult"),initializationId:r(),status:o("success"),initialHeight:u(z(P(),Ie(),xe(0)))}),n({type:o("initResult"),initializationId:r(),status:o("error"),error:ho})]);var Lr=n({type:o("invalidHostMessage"),reason:r()});var Hr=T(["ascending","descending"]);var Vr=z(U,Ke(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Ze(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),mt=g([f({contains:Vr}),f({does_not_contain:Vr})]),De=g([f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Be=g([r(),E(r())]),Gr=f({object:T(["user","group"]),id:z(r(),_e(1))}),go=g([f({contains:Gr}),f({does_not_contain:Gr}),De]),$r=f({object:o("user"),id:z(r(),_e(1),Te(2e3))}),bo=g([f({contains:$r}),f({does_not_contain:$r}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Re=g([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),De]),So=g([f({equals:P()}),f({does_not_equal:P()}),f({greater_than:P()}),f({less_than:P()}),f({greater_than_or_equal_to:P()}),f({less_than_or_equal_to:P()}),De]),ko=g([f({equals:h()}),f({does_not_equal:h()})]),Jr=g([f({equals:Be}),f({does_not_equal:Be}),De]),Qr=T(["To-do","In progress","Complete","Current","Future"]),Xr=g([Qr,z(E(Qr),_e(1),Te(5))]),Io=g([f({group_equals:Xr}),f({group_does_not_equal:Xr})]),_o=g([Jr,Io]),xo=g([f({contains:Be}),f({contains_all:Be}),f({does_not_contain:Be}),De]),Y=T(["start_date","end_date"]),Co=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Me=g([Co,r()]),Po=g([f({target:u(Y),equals:Me}),f({target:u(Y),before:Me}),f({target:u(Y),after:Me}),f({target:u(Y),on_or_before:Me}),f({target:u(Y),on_or_after:Me}),f({target:u(Y),this_week:f({})}),f({target:u(Y),past_week:f({})}),f({target:u(Y),past_month:f({})}),f({target:u(Y),past_year:f({})}),f({target:u(Y),next_week:f({})}),f({target:u(Y),next_month:f({})}),f({target:u(Y),next_year:f({})}),f({target:u(Y),is_empty:o(!0)}),f({target:u(Y),is_not_empty:o(!0)})]),Wr=g([f({propertyId:r(),relation:mt}),f({propertyId:r(),created_by:bo}),f({propertyId:r(),title:Re}),f({propertyId:r(),rich_text:Re}),f({propertyId:r(),url:Re}),f({propertyId:r(),email:Re}),f({propertyId:r(),phone_number:Re}),f({propertyId:r(),number:So}),f({propertyId:r(),checkbox:ko}),f({propertyId:r(),select:Jr}),f({propertyId:r(),multi_select:xo}),f({propertyId:r(),status:_o}),f({propertyId:r(),date:Po}),f({propertyId:r(),people:go})]),Eo=g([Wr,f({and:E(Wr)})]),yt=10,Oo=f({propertyId:r(),direction:Hr}),Kr=n({type:o("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:P(),filter:u(Eo),sorts:u(E(Oo))});var Zr=n({type:o("resize"),height:z(P(),Ie(),xe(0))});var Yr=n({type:o("unsubscribeDataSourceQuery"),subscriptionId:r()});var en=n({type:o("updatePage"),requestId:r(),pageId:U,dataSourceId:u(K),properties:u(Oe),icon:u(ze),cover:u(Le),archived:u(h())});var tn=v("type",[Ur,zr,Kr,Yr,Fr,Xt,Kt,er,or,rr,en,Zr,Lr]);function rn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function nn(e){let t=rn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:jo(t)}}}function jo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var on=n({initializationId:r()}),Ro=n({bridgeProtocolVersion:g([P(),Ye()])});function sn(e){let{iframe:t,sandboxOrigin:s,getInitStatus:i,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:C,onCreatePage:b,onGetPage:L,onOpenPage:q,onOpenExternalUrl:A,onGetUser:O,onListUsers:H,onUpdatePage:$,onResize:X}=e;function ue(W,B){c("warn",{message:"Ignored unsupported sandbox message",payload:vt(W),issues:B});let G=nn(W);if(G.incomingType==="connect"){let ee=Pe(on,W),se=Pe(Ro,W);if(p({initializationId:ee.success?ee.output.initializationId:void 0,error:Sr(),bridgeProtocolVersion:se.success?se.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let ee=Pe(on,W);y({initializationId:ee.success?ee.output.initializationId:void 0,error:Pr()})}G.nack!==void 0&&i()!=="stopped"&&l(G.nack)}return function(B){let G=B.source===t.contentWindow,ee=B.origin===s;if(!G||!ee)return;let se=Pe(tn,B.data);if(!se.success){ue(B.data,se.issues);return}let D=se.output;if(!Tr(D)&&i()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:vt(D)});return}switch(c("in",vt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":C(D);return;case"createPage":b(D);return;case"openPage":q(D);return;case"openExternalUrl":A(D);return;case"getPage":L(D);return;case"getUser":O(D);return;case"listUsers":H(D);return;case"updatePage":$(D);return;case"resize":X(D);return;case"invalidHostMessage":return;default:re(D)}}}function vt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ve=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let s={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:s,isRefreshing:!0,shouldRefreshAgain:!1}),s}isCurrent(t,s){return this.bySubscriptionId.get(t)?.token===s}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let s=[],i=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(i=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,s.push({message:c.message,token:c.token})}return i?s:void 0}finish(t,s){let i=this.bySubscriptionId.get(t);if(i?.token===s&&(i.isRefreshing=!1,!!i.shouldRefreshAgain))return i.shouldRefreshAgain=!1,i.isRefreshing=!0,{message:i.message,token:i.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function an(e,t){if(e===void 0)return;let s="and"in e?e.and:[e];for(let i of s){let c=Mo(i,t);if(c!==void 0)return c}}function Mo(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 s=t.propertiesById[e.propertyId],i=Object.keys(e).find(y=>y!=="propertyId");if(i!==s.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${i}" does not match property type "${s.type}".`,isRetryable:!1};if("status"in e&&s.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(C=>!s.groups.some(b=>b.name===C));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!xt(mt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=Bo(e);if(c===void 0||s.type!==c.propertyType)return;let l=new Set(s.options.map(y=>y.name)),p=Do(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 Bo(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 Do(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?[]:re(e);return Array.isArray(t)?t:[t]}var wo=new Set(jt);function un(e,t){if(e===void 0)return;if(e.length>yt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${yt} entries.`,isRetryable:!1};let s=new Set;for(let i of e){if(s.has(i.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${i.propertyId}".`,isRetryable:!1};if(s.add(i.propertyId),!Object.hasOwn(t.propertiesById,i.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${i.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[i.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 ln=5;function qo(e){let{iframe:t,prepareInitialState:s,handlers:i,onInitialized:c,onConnectionFailure:l,onLog:p,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:x,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b}=e,L=Math.max(x??3,3),q=new AbortController,A,O={},H=!1,$=new AbortController,X,ue,W=6,B=new Ve(a=>{y?.(a)});function G(a,k){p?.(a,k)}function ee(a){let k=N.status;switch(k){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return re(k)}let j=Dr(a,W);G("out",j),t.contentWindow?.postMessage(j,m)}function se(a){ee(ie(He,a))}function D(a){ee(a)}function te(a){let k=N.status;switch(k){case"initialized":ee(ie(gr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:re(k)}}async function fe(a,k){if(k===void 0)return;let j=await k(a);te({type:`${a.type}Result`,requestId:a.requestId,...j})}function we(a){let k=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};te(k)}async function S(a,k=B.subscribe(a)){try{let j=To(ue,a.dataSourceId),ve=Ao(a,j);if(ve!==void 0){B.isCurrent(a.subscriptionId,k)&&(B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:{status:"error",error:ve}}));return}let Ge=await i.queryDataSource(a);if(!B.isCurrent(a.subscriptionId,k))return;Ge.status==="error"&&!Ge.error.isRetryable&&B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:Ge})}finally{let j=B.finish(a.subscriptionId,k);j!==void 0&&S(j.message,j.token)}}function I(a){N.status==="stopped"||N.status==="error"||(Object.assign(O,a),oe())}async function J(a){if(i.openExternalUrl===void 0||q.signal.aborted||A===a.requestId)return;if(A!==void 0){let j={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};te(j);return}let k=qr(a.url);if(k===void 0){let j={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}};te(j);return}A=a.requestId;try{let j=await i.openExternalUrl({...a,url:k},{signal:q.signal});if(q.signal.aborted)return;let ve={type:"openExternalUrlResult",requestId:a.requestId,...j};te(ve)}catch(j){if(!q.signal.aborted)throw j}finally{A===a.requestId&&(A=void 0)}}function oe(){if(N.status!=="initialized")return;let a=O;O={},a.theme!==void 0&&te({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&te({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&te({type:"parentChanged",parent:a.parent}),a.page!==void 0&&te({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&te({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&te({type:"currentUserChanged",currentUser:a.currentUser})}let N=Er({async prepareInit(a){W=a.bridgeProtocolVersion;let k=await mn;return N.status!=="preparingInit"?k:fn(k)},sendInitMessage:se,warn:a=>G("warn",a),flushPendingHostStateChanges:oe,minBridgeProtocolVersion:L,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b,stopHostWithFailure:gt,onInitResult(a){a.status==="success"&&X!==void 0&&c?.({manifest:X,initialHeight:a.initialHeight})},onConnectionFailure:a=>{$.abort(),l?.(a)}});function fn(a){if(a.status==="error")return a;let k=ie(wr,{...a.initialState,...O});if(X=k.manifest,O={},W<ln&&k.page.type==="unavailable")return{status:"error",error:ut()};let j=pn(k.manifest,k.dataSources);return j!==void 0?{status:"error",error:j}:(ue=k.dataSources,H=!0,{status:"success",initialState:k})}let mn=yn().catch(a=>($.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:je()}));async function yn(){let a=await Or({...e,sandboxOrigin:m,signal:$.signal,onError:j=>{G("warn",{message:"Failed to load custom block manifest",error:j})}});if(a.status==="error")return a;if($.signal.aborted)return{status:"error",error:je()};let k=await s({manifest:a.manifest,signal:$.signal});return k.status==="error"?k:{status:"success",initialState:{...k.initialState,manifest:a.manifest}}}let dt=sn({iframe:t,sandboxOrigin:m,getInitStatus:()=>N.status,emit:G,sendNack:D,onInvalidConnect:N.handleInvalidConnect,onInvalidInitResult:N.handleInvalidInitResult,onConnect:N.handleConnect,onInitResult:N.handleInitResult,onQueryDataSource:S,onUnsubscribeDataSourceQuery:a=>B.unsubscribe(a.subscriptionId),onOpenExternalUrl:J,onCreatePage:a=>fe(a,i.createPage),onGetPage:a=>fe(a,i.getPage),onOpenPage:a=>fe(a,i.openPage),onGetUser:a=>fe(a,i.getUser),onListUsers:a=>fe(a,i.listUsers),onUpdatePage:a=>fe(a,i.updatePage),onResize:a=>i.resize?.(a)});window.addEventListener("message",dt),t.addEventListener("load",N.onIframeLoad);function ht(){q.abort(),$.abort(),window.removeEventListener("message",dt),t.removeEventListener("load",N.onIframeLoad),N.stop(),B.unsubscribeAll()}function gt(a){ht(),G("warn",a),l?.(a)}return{stop:ht,setTheme(a){I({theme:a})},setContrastMode(a){I({contrastMode:a})},setParent(a){I({parent:a})},setPage(a){if(a.type==="unavailable"&&W<ln&&(N.status==="preparingInit"&&H||N.status==="waitingForInitResult"||N.status==="initialized")){gt({...ut(),phase:"runtime",source:"host"});return}I({page:a})},setCurrentUser(a){I({currentUser:a})},setDataSources(a){let k={bindings:ie(me,a.bindings)};if(N.hasConnectedSandbox&&X!==void 0&&pn(X,k)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:k});return}ue=k,I({dataSources:k})},refreshQuery({dataSourceId:a}){if(N.status!=="initialized")return;let k=ie(K,a),j=B.refresh(k);if(j===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ve of j)S(ve.message,ve.token)}}}function To(e,t){return Object.values(e?.bindings??{}).find(s=>s.collectionPointer?.id===t)?.collectionSchema}function pn(e,t){for(let[s,i]of Object.entries(e.dataSources)){let c=t.bindings[s];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Ir();for(let[l,p]of Object.entries(i.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return _r();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return xr()}}}function Ao(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}:an(e.filter,t)??un(e.sorts,t)}function No(e){return ie(U,e)}export{de as InvalidNotionDateError,$e as LATEST_BRIDGE_PROTOCOL_VERSION,Qe as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,qo as createCustomBlockHost,vn as getAutoBoundPropertyIdsByKey,lt as isLocalCustomBlockUrl,pt as toNotionDateValue,No as toNotionPageId};
1
+ var Qe=7,Te=6;function vn(e){let{manifestProperties:t,propertySchemasById:o}=e,s=[];for(let[c,l]of Object.entries(t)){let p=dn({propertyKey:c,manifestProperty:l,propertySchemasById:o});p!==void 0&&s.push([c,p])}return Object.fromEntries(s)}function dn(e){let{propertyKey:t,manifestProperty:o,propertySchemasById:s}=e,c=St(o.name),l=Object.entries(s).filter(([p,y])=>y.type===o.type&&(p===t||St(y.name)===c));return l.length===1?l[0][0]:void 0}function St(e){return e.trim().toLowerCase()}var qe,hn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Xe(e){return!e&&!qe?hn:{lang:e?.lang??qe?.lang,message:e?.message,abortEarly:e?.abortEarly??qe?.abortEarly,abortPipeEarly:e?.abortPipeEarly??qe?.abortPipeEarly}}var gn;function bn(e){return gn?.get(e)}var Sn;function kn(e){return Sn?.get(e)}var In;function _n(e,t){return In?.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,o,s,c){let l=c&&"input"in c?c.input:o.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??_n(e.reference,m.lang)??(x?kn(m.lang):null)??s.message??bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(o.typed=!1),o.issues?o.issues.push(m):o.issues=[m]}function xn(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Cn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function We(e,t){let o=[...new Set(e)];return o.length>1?`(${o.join(` ${t} `)})`:o[0]??"never"}function Q(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},Xe())},e}var Pn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ce(e){return{kind:"transformation",type:"brand",reference:ce,async:!1,name:e,"~run"(t){return t}}}function Ie(e){return{kind:"validation",type:"finite",reference:Ie,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,o){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,o),t}}}function Ke(e,t){let o=he(e);return{kind:"validation",type:"includes",reference:Ke,async:!1,expects:o,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&w(this,"content",s,c,{received:`!${o}`}),s}}}function Ae(e,t){return{kind:"validation",type:"max_length",reference:Ae,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&o.value.length>this.requirement&&w(this,"length",o,s,{received:`${o.value.length}`}),o}}}function _e(e,t){return{kind:"validation",type:"min_length",reference:_e,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&o.value.length<this.requirement&&w(this,"length",o,s,{received:`${o.value.length}`}),o}}}function xe(e,t){return{kind:"validation",type:"min_value",reference:xe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(o,s){return o.typed&&!(o.value>=this.requirement)&&w(this,"value",o,s,{received:o.value instanceof Date?o.value.toJSON():he(o.value)}),o}}}function Ze(e,t){return{kind:"validation",type:"regex",reference:Ze,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&!this.requirement.test(o.value)&&w(this,"format",o,s),o}}}function Je(e){return{kind:"transformation",type:"transform",reference:Je,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var It={abortEarly:!0};function _t(e,t,o){return typeof e.fallback=="function"?e.fallback(t,o):e.fallback}function Ne(e,t,o){return typeof e.default=="function"?e.default(t,o):e.default}function xt(e,t){return!e["~run"]({value:t},It).issues}function E(e,t){return Q({kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:t,"~run"(o,s){let c=o.value;if(Array.isArray(c)){o.typed=!0,o.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],o.issues?.push(x);if(o.issues||(o.issues=y.issues),s.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value.push(y.value)}}else w(this,"type",o,s);return o}})}function h(e){return Q({kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,"~run"(t,o){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,o),t}})}function i(e,t){return Q({kind:"schema",type:"literal",reference:i,expects:he(e),async:!1,literal:e,message:t,"~run"(o,s){return xn(o.value,this.literal)?o.typed=!0:w(this,"type",o,s),o}})}function Ye(e){return Q({kind:"schema",type:"nan",reference:Ye,expects:"NaN",async:!1,message:e,"~run"(t,o){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,o),t}})}function F(e,t){return Q({kind:"schema",type:"nullable",reference:F,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(o,s){return o.value===null&&(this.default!==void 0&&(o.value=Ne(this,o,s)),o.value===null)?(o.typed=!0,o):this.wrapped["~run"](o,s)}})}function P(e){return Q({kind:"schema",type:"number",reference:P,expects:"number",async:!1,message:e,"~run"(t,o){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,o),t}})}function n(e,t){return Q({kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,"~run"(o,s){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.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]:Ne(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],o.issues?.push(_);if(o.issues||(o.issues=m.issues),s.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[l]=m.value}else if(p.fallback!==void 0)o.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",o,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",o,s);return o}})}function u(e,t){return Q({kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(o,s){return o.value===void 0&&(this.default!==void 0&&(o.value=Ne(this,o,s)),o.value===void 0)?(o.typed=!0,o):this.wrapped["~run"](o,s)}})}function q(e,t){return Q({kind:"schema",type:"picklist",reference:q,expects:We(e.map(he),"|"),async:!1,options:e,message:t,"~run"(o,s){return this.options.includes(o.value)?o.typed=!0:w(this,"type",o,s),o}})}function V(e,t,o){return Q({kind:"schema",type:"record",reference:V,expects:"Object",async:!1,key:e,value:t,message:o,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let p in l)if(Cn(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 C of m.issues)C.path=[_],s.issues?.push(C);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 C of x.issues)C.path?C.path.unshift(_):C.path=[_],s.issues?.push(C);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 Q({kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,"~run"(o,s){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.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]:Ne(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],o.issues?.push(_);if(o.issues||(o.issues=m.issues),s.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[l]=m.value}else if(p.fallback!==void 0)o.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",o,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!o.issues||!s.abortEarly){for(let l in c)if(!Object.prototype.hasOwnProperty.call(this.entries,l)){w(this,"key",o,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",o,s);return o}})}function r(e){return Q({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,o){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,o),t}})}function kt(e){let t;if(e)for(let o of e)if(t)for(let s of o.issues)t.push(s);else t=o.issues;return t}function g(e,t){return Q({kind:"schema",type:"union",reference:g,expects:We(e.map(o=>o.expects),"|"),async:!1,options:e,message:t,"~run"(o,s){let c,l,p;for(let y of this.options){let m=y["~run"]({value:o.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",o,s,{issues:kt(l)}),o.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",o,s,{issues:kt(p)})}return o}})}function Ce(){return Q({kind:"schema",type:"unknown",reference:Ce,expects:"unknown",async:!1,"~run"(e){return e.typed=!0,e}})}function v(e,t,o){return Q({kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:o,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(C,b)=>{for(let L of C.options){if(L.type==="variant")_(L,new Set(b).add(L.key));else{let T=!0,A=0;for(let O of b){let H=L.entries[O];if(O in l?H["~run"]({typed:!1,value:l[O]},It).issues:H.type!=="exact_optional"&&H.type!=="optional"&&H.type!=="nullish"){T=!1,m!==O&&(y<A||y===A&&O in l&&!(m in l))&&(y=A,m=O,x=[]),m===O&&x.push(L.entries[O].expects);break}A++}if(T){let O=L["~run"]({value:l},c);(!p||!p.typed&&O.typed)&&(p=O)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",s,c,{input:l[m],expected:We(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",s,c);return s}})}function se(e,t,o){let s=e["~run"]({value:t},Xe(o));if(s.issues)throw new Pn(s.issues);return s.value}function z(...e){return Q({...e[0],pipe:e,"~run"(t,o){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!o.abortEarly&&!o.abortPipeEarly)&&(t=s["~run"](t,o))}return t}})}function Pe(e,t,o){let s=e["~run"]({value:t},Xe(o));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var le=z(r(),ce("NotionBlockId")),Z=z(r(),ce("NotionDataSourceId")),U=z(r(),ce("NotionPageId")),Ct=z(r(),ce("NotionAgentId")),Pt=z(r(),ce("NotionSpaceId"));var Et=q(["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"]),et=n({id:r(),name:r(),color:u(Et),description:u(r())}),En=n({id:r(),name:r(),color:u(Et),option_ids:E(r())}),On=n({synced_property_id:r(),synced_property_name:r()}),R=n({name:r(),description:u(r())}),jn=["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"],Ot=q(jn),jt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],tt=v("type",[n({...R.entries,type:i("title")}),n({...R.entries,type:i("rich_text")}),n({...R.entries,type:i("number")}),n({...R.entries,type:i("checkbox")}),n({...R.entries,type:i("url")}),n({...R.entries,type:i("email")}),n({...R.entries,type:i("phone_number")}),n({...R.entries,type:i("select"),options:E(et)}),n({...R.entries,type:i("multi_select"),options:E(et)}),n({...R.entries,type:i("status"),options:E(et),groups:E(En)}),n({...R.entries,type:i("date")}),n({...R.entries,type:i("people")}),n({...R.entries,type:i("files")}),n({...R.entries,type:i("unique_id")}),n({...R.entries,type:i("relation"),data_source_id:u(r()),dual_property:u(On)}),n({...R.entries,type:i("place")}),n({...R.entries,type:i("formula")}),n({...R.entries,type:i("rollup")}),n({...R.entries,type:i("button")}),n({...R.entries,type:i("verification")}),n({...R.entries,type:i("last_visited_time")}),n({...R.entries,type:i("location")}),n({...R.entries,type:i("created_time")}),n({...R.entries,type:i("last_edited_time")}),n({...R.entries,type:i("created_by")}),n({...R.entries,type:i("last_edited_by")})]);var Rt=n({id:Z,table:r(),spaceId:u(Pt)}),Mt=n({id:u(Z),propertiesById:V(r(),tt)}),Xo=n({key:r(),collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:V(r(),u(r())),propertySchemasById:V(r(),tt)}),Rn=n({collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:u(V(r(),u(r())))}),me=V(r(),Rn);var ge=q(["standard","high"]),Bt="standard";var Dt=n({type:i("contrastModeChanged"),contrastMode:ge});var Ue=n({unit:q(["year","month","week","day"]),value:P(),time:r(),defaultTimeZone:u(r())}),Mn=n({unit:q(["hour","minute"]),value:P()}),Ee=n({unit:i("none")}),rt=g([Ue,Mn]),wt=u(g([Ue,Ee])),Tt=u(g([rt,Ee])),Bn=n({type:i("date"),start_date:r(),reminder:wt}),Dn=n({type:i("daterange"),start_date:r(),end_date:r(),reminder:wt}),wn=n({type:i("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:Tt}),Tn=n({type:i("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:Tt}),qt=v("type",[Bn,Dn,wn,Tn]);var Fe=n({id:r(),table:r()});var ae=v("type",[n({type:i("page_id"),page_id:U}),n({type:i("data_source_id"),data_source_id:Z}),n({type:i("workspace"),workspace:i(!0)}),n({type:i("block_id"),block_id:le}),n({type:i("agent_id"),agent_id:Ct}),n({type:i("unavailable")})]);var be=v("type",[n({type:i("unavailable")}),n({type:i("page"),id:U,parent:ae})]),qn=n({type:i("emoji"),emoji:r()}),An=n({type:i("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),Nt=n({type:i("external"),external:n({url:r()})}),Ut=n({type:i("file"),file:n({url:r(),expiry_time:u(r())})}),Le=v("type",[qn,An,Nt,Ut]),He=v("type",[Nt,Ut]),J=F(r()),At=V(r(),Ce()),nt=g([n({id:r(),name:u(r()),color:u(r()),description:u(J)}),n({name:r(),id:u(r()),color:u(r()),description:u(J)})]),ot={start:r(),end:u(J),time_zone:u(J),reminder:u(g([rt,Ee]))},Nn=g([n({...ot,start:z(r(),Ke("T"))}),n({...ot,time_zone:r()}),n({...ot,reminder:u(g([Ue,Ee]))})]),Un=g([n({object:u(i("user")),id:r()}),n({object:i("group"),id:r(),name:u(J)})]),Fn=n({id:r()}),zn=g([n({type:i("external"),name:r(),external:n({url:r()})}),n({type:i("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),Ln=n({lat:P(),lon:P(),name:u(J),address:u(J),aws_place_id:u(J),google_place_id:u(J)}),M={id:r()},ze=F(n({...Fe.entries,table:q(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Ft=v("type",[n({...M,type:i("title"),title:E(At)}),n({...M,type:i("rich_text"),rich_text:E(At)}),n({...M,type:i("number"),number:F(P())}),n({...M,type:i("url"),url:J}),n({...M,type:i("email"),email:J}),n({...M,type:i("phone_number"),phone_number:J}),n({...M,type:i("checkbox"),checkbox:h()}),n({...M,type:i("select"),select:F(nt)}),n({...M,type:i("status"),status:F(nt)}),n({...M,type:i("multi_select"),multi_select:E(nt)}),n({...M,type:i("date"),date:F(Nn)}),n({...M,type:i("people"),people:E(Un)}),n({...M,type:i("relation"),has_more:u(h()),relation:E(Fn)}),n({...M,type:i("files"),files:E(zn)}),n({...M,type:i("place"),place:F(Ln)}),n({...M,type:i("created_time"),created_time:J}),n({...M,type:i("last_edited_time"),last_edited_time:J}),n({...M,type:i("created_by"),created_by:ze}),n({...M,type:i("last_edited_by"),last_edited_by:ze}),n({...M,type:i("last_visited_time"),last_visited_time:J}),n({...M,type:i("unique_id"),unique_id:r()}),n({...M,type:i("button"),button:r()}),n({...M,type:i("formula"),formula:r()}),n({...M,type:i("location"),location:r()}),n({...M,type:i("rollup"),rollup:r()}),n({...M,type:i("verification"),verification:r()})]),Oe=V(r(),Ft),Hn=V(r(),F(Ft)),ne=n({object:i("page"),id:U,parent:ae,properties:Hn,created_by:u(ze,null),last_edited_by:u(ze,null),last_visited_time:u(F(r()),null),created_time:u(F(r()),null),last_edited_time:u(F(r()),null),icon:u(F(Le),null),cover:u(F(He),null),url:u(F(r()),null),public_url:u(F(r()),null),is_archived:h(),in_trash:h()}),Se=n({object:i("page"),id:U,parent:ae,properties:Oe,created_time:u(r()),last_edited_time:u(r()),icon:u(Le),cover:u(He),url:u(r()),public_url:u(r()),is_archived:h(),in_trash:h()});var Vn=r(),zt=n({code:Vn,message:r(),isRetryable:h()}),Lt=v("status",[n({type:i("createPageResult"),requestId:r(),status:i("success"),page:ne}),n({type:i("createPageResult"),requestId:r(),status:i("error"),error:zt})]),Ht=v("status",[n({type:i("createPageResult"),requestId:r(),status:i("success"),page:g([ne,Se])}),n({type:i("createPageResult"),requestId:r(),status:i("error"),error:zt})]);var it=z(r(),ce("NotionUserId")),pe=n({object:i("user"),id:it,name:u(r()),avatar_url:F(r()),type:i("person"),person:n({email:r()})}),Vt=n({object:i("list"),results:E(pe),next_cursor:F(r()),has_more:h(),type:i("user"),user:V(r(),Ce())});var Gt=n({type:i("currentUserChanged"),currentUser:pe});var $t=n({type:i("dataSourcesChanged"),dataSources:n({bindings:me})});var Gn=r(),Qt=n({code:Gn,message:r(),isRetryable:h()}),Xt=n({type:i("getPage"),requestId:r(),pageId:U,dataSourceId:u(Z)}),Wt=v("status",[n({type:i("getPageResult"),requestId:r(),status:i("success"),page:ne}),n({type:i("getPageResult"),requestId:r(),status:i("error"),error:Qt})]),Kt=v("status",[n({type:i("getPageResult"),requestId:r(),status:i("success"),page:g([ne,Se])}),n({type:i("getPageResult"),requestId:r(),status:i("error"),error:Qt})]);var $n=r(),Qn=n({code:$n,message:r(),isRetryable:h()}),Zt=n({type:i("getUser"),requestId:r(),userId:it}),Jt=v("status",[n({type:i("getUserResult"),requestId:r(),status:i("success"),user:pe}),n({type:i("getUserResult"),requestId:r(),status:i("error"),error:Qn})]);var Xn=v("type",[n({type:i("emoji"),emoji:r()}),n({type:i("external"),url:r()})]),Wn=n({name:r(),description:u(r()),type:Ot}),Kn=n({name:r(),description:u(r()),icon:u(Xn),properties:u(V(r(),Wn),{})}),ye=n({version:i(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:i("emoji"),emoji:r()})),dataSources:u(V(r(),Kn),{})});var ke=q(["light","dark"]);var Zn=r(),Jn=n({code:Zn,message:r(),isRetryable:h()});var Ve=v("status",[n({type:i("init"),initializationId:r(),status:i("success"),theme:ke,contrastMode:ge,blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe}),n({type:i("init"),initializationId:r(),status:i("error"),error:Jn})]);var Yt=n({type:i("invalidSandboxMessage"),reason:r()});var Yn=r(),eo=n({code:Yn,message:r(),isRetryable:h()}),er=n({type:i("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(P())}),tr=v("status",[n({type:i("listUsersResult"),requestId:r(),status:i("success"),list:Vt}),n({type:i("listUsersResult"),requestId:r(),status:i("error"),error:eo})]);var to=r(),ro=n({code:to,message:r(),isRetryable:h()}),rr=n({type:i("openExternalUrl"),requestId:r(),url:r()}),nr=v("status",[n({type:i("openExternalUrlResult"),requestId:r(),status:i("success")}),n({type:i("openExternalUrlResult"),requestId:r(),status:i("error"),error:ro})]);var no=q(["side_peek","center_peek"]),oo=r(),io=n({code:oo,message:r(),isRetryable:h()}),or=n({type:i("openPage"),requestId:r(),pageId:U,mode:no}),ir=v("status",[n({type:i("openPageResult"),requestId:r(),status:i("success"),pageId:U}),n({type:i("openPageResult"),requestId:r(),status:i("error"),error:io})]);var sr=n({type:i("pageChanged"),page:be});var ar=n({type:i("parentChanged"),parent:ae});var ur=g([r(),P(),h(),qt,E(r()),E(Fe)]);var cr=n({id:U,is_archived:h(),in_trash:h(),propertiesById:V(r(),u(ur))});var so=r(),lr=n({code:so,message:r(),isRetryable:h()}),pr=v("status",[n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:E(ne),hasMore:h()}),n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:lr})]),fr=v("status",[n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:E(g([ne,cr])),hasMore:h()}),n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:lr})]);var mr=n({type:i("themeChanged"),theme:ke});var ao=r(),yr=n({code:ao,message:r(),isRetryable:h()}),vr=v("status",[n({type:i("updatePageResult"),requestId:r(),status:i("success"),page:ne}),n({type:i("updatePageResult"),requestId:r(),status:i("error"),error:yr})]),dr=v("status",[n({type:i("updatePageResult"),requestId:r(),status:i("success"),page:g([ne,Se])}),n({type:i("updatePageResult"),requestId:r(),status:i("error"),error:yr})]);var hr=v("type",[Ve,mr,Dt,ar,sr,Gt,$t,Jt,tr,ir,nr,Yt]),gr=v("type",[...hr.options,pr,Wt,Lt,vr]),hs=v("type",[...hr.options,fr,Kt,Ht,dr]);function br(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function Sr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function st(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function at(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:o}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${o}.`,isRetryable:!1}}function ut(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function kr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Ir(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function _r(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function xr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function Cr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Pr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function je(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function re(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function ct(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var uo=5e3,co=5e3,lo=5e3;function Er(e){let{prepareInit:t,sendInitMessage:o,warn:s,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:p=uo,initialStateTimeoutMs:y=co,noInitResultTimeoutMs:m=lo,stopHostWithFailure:x,onInitResult:_,onConnectionFailure:C}=e,b="waitingForConnect",L,T,A,O,H=!1,$=!1;function X(){L!==void 0&&(window.clearTimeout(L),L=void 0)}function ue(){T!==void 0&&(window.clearTimeout(T),T=void 0)}function W(){A!==void 0&&(window.clearTimeout(A),A=void 0)}function B(S){let{initializationId:I,error:K,phase:oe,source:N}=S;switch(b){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return re(b)}b="error",O=I,X(),ue(),o({type:"init",initializationId:I,status:"error",error:K}),C?.({...K,phase:oe,source:N})}async function G(S){if(b==="waitingForConnect"){b="preparingInit",O=S.initializationId,X(),T=window.setTimeout(()=>{if(b!=="preparingInit")return;let I=kr();s({...I,initializationId:S.initializationId}),B({initializationId:S.initializationId,error:I,phase:"init",source:"host"})},y);try{let I=await t(S);if(b!=="preparingInit")return;if(ue(),I.status==="error"){B({initializationId:S.initializationId,error:I.error,phase:"init",source:"host"});return}b="waitingForInitResult";let K={type:"init",initializationId:S.initializationId,status:"success",theme:I.initialState.theme,contrastMode:I.initialState.contrastMode??Bt,blockId:I.initialState.blockId,parent:I.initialState.parent,page:I.initialState.page,currentUser:I.initialState.currentUser,manifest:I.initialState.manifest,dataSources:I.initialState.dataSources};o(K),A=window.setTimeout(()=>{if(b!=="waitingForInitResult")return;b="error";let oe=Cr();C?.({...oe,phase:"initResult",source:"host"}),s({...oe,initializationId:S.initializationId})},m)}catch(I){if(b!=="preparingInit")return;s({message:"Failed to prepare custom block initialization",error:I}),B({initializationId:S.initializationId,error:je(),phase:"init",source:"host"})}}}function ee(S){if(b!=="stopped"&&b==="waitingForConnect"){if(!ct(S.bridgeProtocolVersion)){let I=st({currentBridgeProtocolVersion:S.bridgeProtocolVersion});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.bridgeProtocolVersion<l){let I=at({currentBridgeProtocolVersion:S.bridgeProtocolVersion,minBridgeProtocolVersion:l});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.status==="error"){B({initializationId:S.initializationId,error:S.error,phase:"connect",source:"sandbox"});return}$=!0,G(S)}}function ie(S){if(b==="stopped"||b!=="waitingForConnect")return"handled";let{initializationId:I,bridgeProtocolVersion:K}=S;if(I===void 0)return"nack";let oe=S.error;return K!==void 0&&(ct(K)?K<l&&(oe=at({currentBridgeProtocolVersion:K,minBridgeProtocolVersion:l})):oe=st({currentBridgeProtocolVersion:K})),B({initializationId:I,error:oe,phase:"connect",source:"host"}),"handled"}function D(S){let{initializationId:I,error:K}=S;b!=="waitingForInitResult"||I===void 0||I!==O||(X(),W(),b="error",s(K),C?.({...K,phase:"initResult",source:"host"}))}function te(){if(b!=="stopped"){if(H){x({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}H=!0,X(),b==="waitingForConnect"&&(L=window.setTimeout(()=>{if(b!=="waitingForConnect")return;b="error";let S=br();s(S),C?.({...S,phase:"connect",source:"host"})},p))}}function fe(S){if(b!=="waitingForInitResult"||S.initializationId!==O){s({message:"Ignored stale or unexpected initResult",payload:S});return}W(),b=S.status==="success"?"initialized":"error",S.status==="success"?c():C?.({...S.error,phase:"initResult",source:"sandbox"}),_?.(S)}function we(){b="stopped",X(),ue(),W()}return{get status(){return b},get hasConnectedSandbox(){return $},handleConnect:ee,handleInitResult:fe,handleInvalidConnect:ie,handleInvalidInitResult:D,onIframeLoad:te,stop:we}}function lt({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function Or(e){let t=new AbortController,o=()=>t.abort();e.signal.addEventListener("abort",o,{once:!0});let s=new Promise((l,p)=>{t.signal.addEventListener("abort",()=>p(t.signal.reason),{once:!0})});e.signal.aborted&&t.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{t.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?po(e.sandboxOrigin,t.signal):e.getPersistedManifest({signal:t.signal}),s]);if(t.signal.aborted)throw new Error("Manifest loading was cancelled.");return{status:"success",manifest:se(ye,l)}}catch(l){return e.signal.aborted||e.onError(l),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(c),e.signal.removeEventListener("abort",o)}}async function po(e,t){let o=new URL(e);if(!lt({url:o,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let s=await fetch(new URL("/manifest",o),{credentials:"omit",redirect:"error",cache:"no-store",signal:t});if(!s.ok)throw new Error(`Manifest request failed: HTTP ${s.status}.`);return s.json()}var de=class extends Error{};function pt(e){try{return fo(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function fo(e){let{start:t,end:o,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,_=T=>{if(!T.split("T")[0])throw new de("Date values must include a date.");if(!T.includes("T"))return{date:T,time:"00:00"};let A=T.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(A)return{date:A[1],time:A[2]};if(!s||m){let $=new Date(new Date(T).getTime()+x*6e4).toISOString();return{date:$.slice(0,10),time:$.slice(11,16)}}let O=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(T)),H=$=>O.find(X=>X.type===$)?.value;return{date:`${H("year")}-${H("month")}-${H("day")}`,time:`${H("hour")}:${H("minute")}`}},C=_(t),b=o?_(o):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 b?{type:"daterange",start_date:C.date,end_date:b.date,reminder:c}:{type:"date",start_date:C.date,reminder:c}}let L=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 b?{type:"datetimerange",start_date:C.date,start_time:C.time,end_date:b.date,end_time:b.time,time_zone:L,reminder:c}:{type:"datetime",start_date:C.date,start_time:C.time,time_zone:L,reminder:c}}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 Mr(e){let t={};for(let o of Object.values(e.properties))o&&(t[o.id]=mo(o));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:t}}function jr(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let o=t.text;return o&&typeof o=="object"&&"content"in o&&typeof o.content=="string"?o.content:""}).join("")}function ft(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 mo(e){switch(e.type){case"title":return jr(e.title);case"rich_text":return jr(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?pt(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 ft(e.created_time);case"last_edited_time":return ft(e.last_edited_time);case"last_visited_time":return ft(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 re(e)}}function Br(e,t){if(t>=7||e.status==="error")return e;switch(e.type){case"queryDataSourceResult":return t>=6?{...e,items:e.items.map(mt)}:{...e,items:e.items.map(Mr)};case"getPageResult":case"createPageResult":case"updatePageResult":return{...e,page:t>=6?mt(e.page):Rr(mt(e.page))};default:return re(e)}}function mt(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,o])=>{switch(o?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];default:return[t,o]}}))}}function Dr(e,t){return e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"?e:Br(e,t)}var wr=n({theme:ke,contrastMode:u(ge),blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe});function Tr(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 qr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Ar=n({code:r(),message:r(),isRetryable:h()});var Nr={type:i("connect"),initializationId:r(),bridgeProtocolVersion:P(),sdkVersion:r()},Ur=v("status",[n({status:i("success"),manifest:u(ye),...Nr}),n({status:i("error"),error:Ar,...Nr})]);var vo=v("type",[n({type:i("start")}),n({type:i("end")}),n({type:i("before"),blockId:le}),n({type:i("after"),blockId:le})]),ho=v("type",[n({type:i("page_id"),page_id:U}),n({type:i("data_source_id"),data_source_id:Z})]),Fr=n({type:i("createPage"),requestId:r(),parent:ho,properties:Oe,position:u(vo)});var go=r(),bo=n({code:go,message:r(),isRetryable:h()}),zr=v("status",[n({type:i("initResult"),initializationId:r(),status:i("success"),initialHeight:u(z(P(),Ie(),xe(0)))}),n({type:i("initResult"),initializationId:r(),status:i("error"),error:bo})]);var Lr=n({type:i("invalidHostMessage"),reason:r()});var Hr=q(["ascending","descending"]);var Vr=z(U,Ze(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Je(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),yt=g([f({contains:Vr}),f({does_not_contain:Vr})]),De=g([f({is_empty:i(!0)}),f({is_not_empty:i(!0)})]),Be=g([r(),E(r())]),Gr=f({object:q(["user","group"]),id:z(r(),_e(1))}),So=g([f({contains:Gr}),f({does_not_contain:Gr}),De]),$r=f({object:i("user"),id:z(r(),_e(1),Ae(2e3))}),ko=g([f({contains:$r}),f({does_not_contain:$r}),f({is_empty:i(!0)}),f({is_not_empty:i(!0)})]),Re=g([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),De]),Io=g([f({equals:P()}),f({does_not_equal:P()}),f({greater_than:P()}),f({less_than:P()}),f({greater_than_or_equal_to:P()}),f({less_than_or_equal_to:P()}),De]),_o=g([f({equals:h()}),f({does_not_equal:h()})]),Kr=g([f({equals:Be}),f({does_not_equal:Be}),De]),Qr=q(["To-do","In progress","Complete","Current","Future"]),Xr=g([Qr,z(E(Qr),_e(1),Ae(5))]),xo=g([f({group_equals:Xr}),f({group_does_not_equal:Xr})]),Co=g([Kr,xo]),Po=g([f({contains:Be}),f({contains_all:Be}),f({does_not_contain:Be}),De]),Y=q(["start_date","end_date"]),Eo=q(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Me=g([Eo,r()]),Oo=g([f({target:u(Y),equals:Me}),f({target:u(Y),before:Me}),f({target:u(Y),after:Me}),f({target:u(Y),on_or_before:Me}),f({target:u(Y),on_or_after:Me}),f({target:u(Y),this_week:f({})}),f({target:u(Y),past_week:f({})}),f({target:u(Y),past_month:f({})}),f({target:u(Y),past_year:f({})}),f({target:u(Y),next_week:f({})}),f({target:u(Y),next_month:f({})}),f({target:u(Y),next_year:f({})}),f({target:u(Y),is_empty:i(!0)}),f({target:u(Y),is_not_empty:i(!0)})]),Wr=g([f({propertyId:r(),relation:yt}),f({propertyId:r(),created_by:ko}),f({propertyId:r(),title:Re}),f({propertyId:r(),rich_text:Re}),f({propertyId:r(),url:Re}),f({propertyId:r(),email:Re}),f({propertyId:r(),phone_number:Re}),f({propertyId:r(),number:Io}),f({propertyId:r(),checkbox:_o}),f({propertyId:r(),select:Kr}),f({propertyId:r(),multi_select:Po}),f({propertyId:r(),status:Co}),f({propertyId:r(),date:Oo}),f({propertyId:r(),people:So})]),jo=g([Wr,f({and:E(Wr)})]),vt=10,Ro=f({propertyId:r(),direction:Hr}),Zr=n({type:i("queryDataSource"),subscriptionId:r(),dataSourceId:Z,limit:P(),filter:u(jo),sorts:u(E(Ro))});var Jr=n({type:i("resize"),height:z(P(),Ie(),xe(0))});var Yr=n({type:i("unsubscribeDataSourceQuery"),subscriptionId:r()});var en=n({type:i("updatePage"),requestId:r(),pageId:U,dataSourceId:u(Z),properties:u(Oe),icon:u(Le),cover:u(He),archived:u(h())});var tn=v("type",[Ur,zr,Zr,Yr,Fr,Xt,Zt,er,or,rr,en,Jr,Lr]);function rn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function nn(e){let t=rn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:Mo(t)}}}function Mo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var on=n({initializationId:r()}),Bo=n({bridgeProtocolVersion:g([P(),Ye()])});function sn(e){let{iframe:t,sandboxOrigin:o,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:C,onCreatePage:b,onGetPage:L,onOpenPage:T,onOpenExternalUrl:A,onGetUser:O,onListUsers:H,onUpdatePage:$,onResize:X}=e;function ue(W,B){c("warn",{message:"Ignored unsupported sandbox message",payload:dt(W),issues:B});let G=nn(W);if(G.incomingType==="connect"){let ee=Pe(on,W),ie=Pe(Bo,W);if(p({initializationId:ee.success?ee.output.initializationId:void 0,error:Sr(),bridgeProtocolVersion:ie.success?ie.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let ee=Pe(on,W);y({initializationId:ee.success?ee.output.initializationId:void 0,error:Pr()})}G.nack!==void 0&&s()!=="stopped"&&l(G.nack)}return function(B){let G=B.source===t.contentWindow,ee=B.origin===o;if(!G||!ee)return;let ie=Pe(tn,B.data);if(!ie.success){ue(B.data,ie.issues);return}let D=ie.output;if(!qr(D)&&s()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:dt(D)});return}switch(c("in",dt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":C(D);return;case"createPage":b(D);return;case"openPage":T(D);return;case"openExternalUrl":A(D);return;case"getPage":L(D);return;case"getUser":O(D);return;case"listUsers":H(D);return;case"updatePage":$(D);return;case"resize":X(D);return;case"invalidHostMessage":return;default:re(D)}}}function dt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ge=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let o={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:o,isRefreshing:!0,shouldRefreshAgain:!1}),o}isCurrent(t,o){return this.bySubscriptionId.get(t)?.token===o}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let o=[],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,o.push({message:c.message,token:c.token})}return s?o:void 0}finish(t,o){let s=this.bySubscriptionId.get(t);if(s?.token===o&&(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 an(e,t){if(e===void 0)return;let o="and"in e?e.and:[e];for(let s of o){let c=Do(s,t);if(c!==void 0)return c}}function Do(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 o=t.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==o.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${o.type}".`,isRetryable:!1};if("status"in e&&o.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(C=>!o.groups.some(b=>b.name===C));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!xt(yt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=wo(e);if(c===void 0||o.type!==c.propertyType)return;let l=new Set(o.options.map(y=>y.name)),p=To(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 wo(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 To(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?[]:re(e);return Array.isArray(t)?t:[t]}var qo=new Set(jt);function un(e,t){if(e===void 0)return;if(e.length>vt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${vt} entries.`,isRetryable:!1};let o=new Set;for(let s of e){if(o.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(o.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(!qo.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 ln=5;function Ao(e){let{iframe:t,prepareInitialState:o,handlers:s,onInitialized:c,onConnectionFailure:l,onLog:p,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:x,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b}=e,L=Math.max(x??3,3),T=new AbortController,A,O={},H=!1,$=new AbortController,X,ue,W=7,B=new Ge(a=>{y?.(a)});function G(a,k){p?.(a,k)}function ee(a){let k=N.status;switch(k){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return re(k)}let j=Dr(a,W);G("out",j),t.contentWindow?.postMessage(j,m)}function ie(a){ee(se(Ve,a))}function D(a){ee(a)}function te(a){let k=N.status;switch(k){case"initialized":ee(se(gr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:re(k)}}async function fe(a,k){if(k===void 0)return;let j=await k(a);te({type:`${a.type}Result`,requestId:a.requestId,...j})}function we(a){let k=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};te(k)}async function S(a,k=B.subscribe(a)){try{let j=No(ue,a.dataSourceId),ve=Uo(a,j);if(ve!==void 0){B.isCurrent(a.subscriptionId,k)&&(B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:{status:"error",error:ve}}));return}let $e=await s.queryDataSource(a);if(!B.isCurrent(a.subscriptionId,k))return;$e.status==="error"&&!$e.error.isRetryable&&B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:$e})}finally{let j=B.finish(a.subscriptionId,k);j!==void 0&&S(j.message,j.token)}}function I(a){N.status==="stopped"||N.status==="error"||(Object.assign(O,a),oe())}async function K(a){if(s.openExternalUrl===void 0||T.signal.aborted||A===a.requestId)return;if(A!==void 0){let j={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};te(j);return}let k=Tr(a.url);if(k===void 0){let j={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}};te(j);return}A=a.requestId;try{let j=await s.openExternalUrl({...a,url:k},{signal:T.signal});if(T.signal.aborted)return;let ve={type:"openExternalUrlResult",requestId:a.requestId,...j};te(ve)}catch(j){if(!T.signal.aborted)throw j}finally{A===a.requestId&&(A=void 0)}}function oe(){if(N.status!=="initialized")return;let a=O;O={},a.theme!==void 0&&te({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&te({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&te({type:"parentChanged",parent:a.parent}),a.page!==void 0&&te({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&te({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&te({type:"currentUserChanged",currentUser:a.currentUser})}let N=Er({async prepareInit(a){W=a.bridgeProtocolVersion;let k=await mn;return N.status!=="preparingInit"?k:fn(k)},sendInitMessage:ie,warn:a=>G("warn",a),flushPendingHostStateChanges:oe,minBridgeProtocolVersion:L,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b,stopHostWithFailure:bt,onInitResult(a){a.status==="success"&&X!==void 0&&c?.({manifest:X,initialHeight:a.initialHeight})},onConnectionFailure:a=>{$.abort(),l?.(a)}});function fn(a){if(a.status==="error")return a;let k=se(wr,{...a.initialState,...O});if(X=k.manifest,O={},W<ln&&k.page.type==="unavailable")return{status:"error",error:ut()};let j=pn(k.manifest,k.dataSources);return j!==void 0?{status:"error",error:j}:(ue=k.dataSources,H=!0,{status:"success",initialState:k})}let mn=yn().catch(a=>($.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:je()}));async function yn(){let a=await Or({...e,sandboxOrigin:m,signal:$.signal,onError:j=>{G("warn",{message:"Failed to load custom block manifest",error:j})}});if(a.status==="error")return a;if($.signal.aborted)return{status:"error",error:je()};let k=await o({manifest:a.manifest,signal:$.signal});return k.status==="error"?k:{status:"success",initialState:{...k.initialState,manifest:a.manifest}}}let ht=sn({iframe:t,sandboxOrigin:m,getInitStatus:()=>N.status,emit:G,sendNack:D,onInvalidConnect:N.handleInvalidConnect,onInvalidInitResult:N.handleInvalidInitResult,onConnect:N.handleConnect,onInitResult:N.handleInitResult,onQueryDataSource:S,onUnsubscribeDataSourceQuery:a=>B.unsubscribe(a.subscriptionId),onOpenExternalUrl:K,onCreatePage:a=>fe(a,s.createPage),onGetPage:a=>fe(a,s.getPage),onOpenPage:a=>fe(a,s.openPage),onGetUser:a=>fe(a,s.getUser),onListUsers:a=>fe(a,s.listUsers),onUpdatePage:a=>fe(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",ht),t.addEventListener("load",N.onIframeLoad);function gt(){T.abort(),$.abort(),window.removeEventListener("message",ht),t.removeEventListener("load",N.onIframeLoad),N.stop(),B.unsubscribeAll()}function bt(a){gt(),G("warn",a),l?.(a)}return{stop:gt,setTheme(a){I({theme:a})},setContrastMode(a){I({contrastMode:a})},setParent(a){I({parent:a})},setPage(a){if(a.type==="unavailable"&&W<ln&&(N.status==="preparingInit"&&H||N.status==="waitingForInitResult"||N.status==="initialized")){bt({...ut(),phase:"runtime",source:"host"});return}I({page:a})},setCurrentUser(a){I({currentUser:a})},setDataSources(a){let k={bindings:se(me,a.bindings)};if(N.hasConnectedSandbox&&X!==void 0&&pn(X,k)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:k});return}ue=k,I({dataSources:k})},refreshQuery({dataSourceId:a}){if(N.status!=="initialized")return;let k=se(Z,a),j=B.refresh(k);if(j===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ve of j)S(ve.message,ve.token)}}}function No(e,t){return Object.values(e?.bindings??{}).find(o=>o.collectionPointer?.id===t)?.collectionSchema}function pn(e,t){for(let[o,s]of Object.entries(e.dataSources)){let c=t.bindings[o];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Ir();for(let[l,p]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return _r();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return xr()}}}function Uo(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}:an(e.filter,t)??un(e.sorts,t)}function Fo(e){return se(U,e)}export{de as InvalidNotionDateError,Qe as LATEST_BRIDGE_PROTOCOL_VERSION,Te as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,Ao as createCustomBlockHost,vn as getAutoBoundPropertyIdsByKey,lt as isLocalCustomBlockUrl,pt as toNotionDateValue,Fo as toNotionPageId};
@@ -1,6 +1,6 @@
1
1
  import type { HostToSandboxMessage, HostToSandboxMessageLegacy } from "../protocol/messages/hostToSandbox.js";
2
2
  /**
3
- * Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
3
+ * Normalizes outgoing page shapes for the sandbox's bridge protocol version.
4
4
  */
5
5
  export declare function normalizeHostToSandboxMessage(message: HostToSandboxMessage, bridgeProtocolVersion: number): HostToSandboxMessageLegacy;
6
6
  //# sourceMappingURL=normalizeHostToSandboxMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,MAAM,4DAA4D,CAAA;AAGnE;;GAEG;AAGH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CAc5B"}
1
+ {"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,MAAM,4DAA4D,CAAA;AAGnE;;GAEG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CAc5B"}
@@ -1,9 +1,7 @@
1
1
  import { normalizeToLegacyPage } from "./normalizePage.js";
2
2
  /**
3
- * Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
3
+ * Normalizes outgoing page shapes for the sandbox's bridge protocol version.
4
4
  */
5
- // TODO(custom-blocks): Remove this function when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION
6
- // reaches 6.
7
5
  export function normalizeHostToSandboxMessage(message, bridgeProtocolVersion) {
8
6
  if (message.type !== "queryDataSourceResult" &&
9
7
  message.type !== "getPageResult" &&
@@ -1 +1 @@
1
- {"version":3,"file":"normalizePage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAA;AAC5G,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oEAAoE,CAAA;AACtH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAK5G,wBAAgB,qBAAqB,CACpC,OAAO,EACJ,uBAAuB,GACvB,oBAAoB,GACpB,uBAAuB,GACvB,4BAA4B,EAC/B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CAkB5B"}
1
+ {"version":3,"file":"normalizePage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAA;AAC5G,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oEAAoE,CAAA;AACtH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAU5G,wBAAgB,qBAAqB,CACpC,OAAO,EACJ,uBAAuB,GACvB,oBAAoB,GACpB,uBAAuB,GACvB,4BAA4B,EAC/B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CA0B5B"}
@@ -1,9 +1,8 @@
1
- import { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION } from "../protocol/protocolVersion.js";
1
+ import { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, } from "../protocol/protocolVersion.js";
2
2
  import { unreachable } from "../utils.js";
3
3
  import { toLegacyPage, toLegacyQueryPage } from "./legacyPage.js";
4
4
  export function normalizeToLegacyPage(message, bridgeProtocolVersion) {
5
- // Forward up to date messages
6
- if (bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION) {
5
+ if (bridgeProtocolVersion >= TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION) {
7
6
  return message;
8
7
  }
9
8
  if (message.status === "error") {
@@ -11,12 +10,38 @@ export function normalizeToLegacyPage(message, bridgeProtocolVersion) {
11
10
  }
12
11
  switch (message.type) {
13
12
  case "queryDataSourceResult":
13
+ if (bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION) {
14
+ return { ...message, items: message.items.map(toPreFallbackPage) };
15
+ }
14
16
  return { ...message, items: message.items.map(toLegacyQueryPage) };
15
17
  case "getPageResult":
16
18
  case "createPageResult":
17
19
  case "updatePageResult":
18
- return { ...message, page: toLegacyPage(message.page) };
20
+ return {
21
+ ...message,
22
+ page: bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION
23
+ ? toPreFallbackPage(message.page)
24
+ : toLegacyPage(toPreFallbackPage(message.page)),
25
+ };
19
26
  default:
20
27
  return unreachable(message);
21
28
  }
22
29
  }
30
+ function toPreFallbackPage(page) {
31
+ return {
32
+ ...page,
33
+ properties: Object.fromEntries(Object.entries(page.properties).map(([name, property]) => {
34
+ switch (property?.type) {
35
+ case "unique_id":
36
+ case "button":
37
+ case "formula":
38
+ case "location":
39
+ case "rollup":
40
+ case "verification":
41
+ return [name, null];
42
+ default:
43
+ return [name, property];
44
+ }
45
+ })),
46
+ };
47
+ }
@@ -3,5 +3,6 @@
3
3
  * Increase this value for breaking wire changes. Hosts can continue to accept
4
4
  * older versions, so this value does not set the minimum or maximum they accept.
5
5
  */
6
- export declare const LATEST_BRIDGE_PROTOCOL_VERSION = 6;
6
+ export declare const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
7
  export declare const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
8
+ export declare const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
@@ -3,7 +3,9 @@
3
3
  * Increase this value for breaking wire changes. Hosts can continue to accept
4
4
  * older versions, so this value does not set the minimum or maximum they accept.
5
5
  */
6
- export const LATEST_BRIDGE_PROTOCOL_VERSION = 6;
6
+ export const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
7
  // Protocol 6 introduces unified pages with name-keyed property objects.
8
8
  // Keep this cutoff fixed when the latest protocol version increases.
9
9
  export const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
10
+ // Protocol 7 adds typed text fallbacks for previously unsupported page properties.
11
+ export const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-host",
3
- "version": "0.3.8",
3
+ "version": "0.3.11",
4
4
  "description": "Reusable host runtime for Notion custom blocks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "valibot": "^1.4.2"
20
+ "valibot": "^1.5.0"
21
21
  },
22
22
  "files": [
23
23
  "src",
@@ -5,10 +5,8 @@ import type {
5
5
  import { normalizeToLegacyPage } from "./normalizePage.js"
6
6
 
7
7
  /**
8
- * Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
8
+ * Normalizes outgoing page shapes for the sandbox's bridge protocol version.
9
9
  */
10
- // TODO(custom-blocks): Remove this function when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION
11
- // reaches 6.
12
10
  export function normalizeHostToSandboxMessage(
13
11
  message: HostToSandboxMessage,
14
12
  bridgeProtocolVersion: number,
@@ -3,7 +3,12 @@ import type { GetPageResultMessage } from "@notionhq/custom-blocks-protocol/mess
3
3
  import type { HostToSandboxMessageLegacy } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
4
4
  import type { QueryDataSourceResultMessage } from "@notionhq/custom-blocks-protocol/messages/queryDataSourceResult.js"
5
5
  import type { UpdatePageResultMessage } from "@notionhq/custom-blocks-protocol/messages/updatePageResult.js"
6
- import { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION } from "@notionhq/custom-blocks-protocol/protocolVersion.js"
6
+ import type { notionPageDataSchema } from "@notionhq/custom-blocks-protocol/pages/page.js"
7
+ import {
8
+ LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,
9
+ TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION,
10
+ } from "@notionhq/custom-blocks-protocol/protocolVersion.js"
11
+ import type { InferOutput } from "valibot"
7
12
  import { unreachable } from "../utils.js"
8
13
  import { toLegacyPage, toLegacyQueryPage } from "./legacyPage.js"
9
14
 
@@ -15,8 +20,7 @@ export function normalizeToLegacyPage(
15
20
  | QueryDataSourceResultMessage,
16
21
  bridgeProtocolVersion: number,
17
22
  ): HostToSandboxMessageLegacy {
18
- // Forward up to date messages
19
- if (bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION) {
23
+ if (bridgeProtocolVersion >= TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION) {
20
24
  return message
21
25
  }
22
26
  if (message.status === "error") {
@@ -24,12 +28,44 @@ export function normalizeToLegacyPage(
24
28
  }
25
29
  switch (message.type) {
26
30
  case "queryDataSourceResult":
31
+ if (bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION) {
32
+ return { ...message, items: message.items.map(toPreFallbackPage) }
33
+ }
27
34
  return { ...message, items: message.items.map(toLegacyQueryPage) }
28
35
  case "getPageResult":
29
36
  case "createPageResult":
30
37
  case "updatePageResult":
31
- return { ...message, page: toLegacyPage(message.page) }
38
+ return {
39
+ ...message,
40
+ page:
41
+ bridgeProtocolVersion >= LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION
42
+ ? toPreFallbackPage(message.page)
43
+ : toLegacyPage(toPreFallbackPage(message.page)),
44
+ }
32
45
  default:
33
46
  return unreachable(message)
34
47
  }
35
48
  }
49
+
50
+ function toPreFallbackPage(
51
+ page: InferOutput<typeof notionPageDataSchema>,
52
+ ): InferOutput<typeof notionPageDataSchema> {
53
+ return {
54
+ ...page,
55
+ properties: Object.fromEntries(
56
+ Object.entries(page.properties).map(([name, property]) => {
57
+ switch (property?.type) {
58
+ case "unique_id":
59
+ case "button":
60
+ case "formula":
61
+ case "location":
62
+ case "rollup":
63
+ case "verification":
64
+ return [name, null]
65
+ default:
66
+ return [name, property]
67
+ }
68
+ }),
69
+ ),
70
+ }
71
+ }