@notionhq/custom-blocks-host 0.3.3 → 0.3.5

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.
Files changed (44) hide show
  1. package/README.md +11 -4
  2. package/dist/browser.js +1 -1
  3. package/dist/createCustomBlockHost.d.ts.map +1 -1
  4. package/dist/createCustomBlockHost.js +68 -0
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/lifecycle/legacyPage.d.ts +68 -0
  8. package/dist/lifecycle/legacyPage.d.ts.map +1 -0
  9. package/dist/lifecycle/legacyPage.js +159 -0
  10. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +2 -2
  11. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +1 -1
  12. package/dist/lifecycle/normalizeHostToSandboxMessage.js +4 -32
  13. package/dist/lifecycle/normalizeQueryPage.d.ts +3 -0
  14. package/dist/lifecycle/normalizeQueryPage.d.ts.map +1 -0
  15. package/dist/lifecycle/normalizeQueryPage.js +13 -0
  16. package/dist/messages/parseExternalUrl.d.ts +3 -0
  17. package/dist/messages/parseExternalUrl.d.ts.map +1 -0
  18. package/dist/messages/parseExternalUrl.js +15 -0
  19. package/dist/messages/sandboxMessageRouter.d.ts +2 -0
  20. package/dist/messages/sandboxMessageRouter.d.ts.map +1 -1
  21. package/dist/messages/sandboxMessageRouter.js +19 -4
  22. package/dist/messages/types.d.ts +7 -0
  23. package/dist/messages/types.d.ts.map +1 -1
  24. package/dist/protocol/dataSources/dataSourcePage.d.ts +1 -2
  25. package/dist/protocol/dataSources/dataSourcePage.js +1 -2
  26. package/dist/protocol/index.d.ts +1 -0
  27. package/dist/protocol/index.js +1 -0
  28. package/dist/protocol/messages/hostToSandbox.d.ts +1649 -241
  29. package/dist/protocol/messages/hostToSandbox.js +15 -6
  30. package/dist/protocol/messages/openExternalUrl.d.ts +32 -0
  31. package/dist/protocol/messages/openExternalUrl.js +26 -0
  32. package/dist/protocol/messages/queryDataSourceResult.d.ts +174 -0
  33. package/dist/protocol/messages/queryDataSourceResult.js +15 -0
  34. package/dist/protocol/messages/sandboxToHost.d.ts +4 -0
  35. package/dist/protocol/messages/sandboxToHost.js +2 -0
  36. package/package.json +1 -1
  37. package/src/createCustomBlockHost.ts +79 -1
  38. package/src/index.ts +4 -0
  39. package/src/lifecycle/legacyPage.ts +183 -0
  40. package/src/lifecycle/normalizeHostToSandboxMessage.ts +9 -37
  41. package/src/lifecycle/normalizeQueryPage.ts +25 -0
  42. package/src/messages/parseExternalUrl.ts +18 -0
  43. package/src/messages/sandboxMessageRouter.ts +24 -3
  44. package/src/messages/types.ts +23 -0
package/README.md CHANGED
@@ -156,10 +156,17 @@ validates filters and sorts against actual database properties in `collectionSch
156
156
  before invoking `queryDataSource`. Status group names and option names must match the bound schema.
157
157
  Sorts retain their order and contain at most ten unique properties.
158
158
 
159
- The SDK exposes synthetic metadata through its separate `propertySchemasById` read map. For
160
- protocols 3 and 4, the host adds synthetic metadata to outgoing `collectionSchema` payloads.
161
- Protocol 5 SDKs add those read schemas themselves. Host query validation always uses the actual
162
- database schema.
159
+ ### External navigation
160
+
161
+ The `openExternalUrl` handler receives an `AbortSignal` and a normalized, absolute HTTP or HTTPS URL
162
+ without credentials, limited to 2,048 JavaScript code units before and after normalization. Adapters
163
+ display the exact URL, obtain approval, and navigate only after approval. They may apply additional
164
+ URL restrictions and should dismiss confirmation UI when the signal aborts on stop or iframe reload.
165
+
166
+ Each iframe permits one pending external-navigation request. A different request receives
167
+ `pending_navigation`; a duplicate of the active request is ignored. Every completed request is
168
+ forgotten, so a subsequent request requires fresh approval. Results are suppressed after stop. The
169
+ runtime redacts `openExternalUrl.url` from `onLog` payloads.
163
170
 
164
171
  ### Initialization and malformed messages
165
172
 
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- var Fe=6,Hr=6;function Lr(e){let{manifestProperties:n,propertySchemasById:o}=e,s=[];for(let[c,l]of Object.entries(n)){let f=Vr({propertyKey:c,manifestProperty:l,propertySchemasById:o});f!==void 0&&s.push([c,f])}return Object.fromEntries(s)}function Vr(e){let{propertyKey:n,manifestProperty:o,propertySchemasById:s}=e,c=ut(o.name),l=Object.entries(s).filter(([f,y])=>y.type===o.type&&(f===n||ut(y.name)===c));return l.length===1?l[0][0]:void 0}function ut(e){return e.trim().toLowerCase()}var Re,Gr={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Ue(e){return!e&&!Re?Gr:{lang:e?.lang??Re?.lang,message:e?.message,abortEarly:e?.abortEarly??Re?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Re?.abortPipeEarly}}var $r;function Qr(e){return $r?.get(e)}var Xr;function Wr(e){return Xr?.get(e)}var Jr;function Kr(e,n){return Jr?.get(e)?.get(n)}function ge(e){let n=typeof e;return n==="string"?`"${e}"`:n==="number"||n==="bigint"||n==="boolean"?`${e}`:n==="object"||n==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":n}function B(e,n,o,s,c){let l=c&&"input"in c?c.input:o.value,f=c?.expected??e.expects??null,y=c?.received??ge(l),m={kind:e.kind,type:e.type,input:l,expected:f,received:y,message:`Invalid ${n}: ${f?`Expected ${f} 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??Kr(e.reference,m.lang)??(x?Wr(m.lang):null)??s.message??Qr(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(o.typed=!1),o.issues?o.issues.push(m):o.issues=[m]}var ct=new WeakMap;function z(e){let n=ct.get(e);return n||(n={version:1,vendor:"valibot",validate(o){return e["~run"]({value:o},Ue())}},ct.set(e,n)),n}function Yr(e,n){return Object.prototype.hasOwnProperty.call(e,n)&&n!=="__proto__"&&n!=="prototype"&&n!=="constructor"}function ze(e,n){let o=[...new Set(e)];return o.length>1?`(${o.join(` ${n} `)})`:o[0]??"never"}var Zr=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function re(e){return{kind:"transformation",type:"brand",reference:re,async:!1,name:e,"~run"(n){return n}}}function be(e){return{kind:"validation",type:"finite",reference:be,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(n,o){return n.typed&&!this.requirement(n.value)&&B(this,"finite",n,o),n}}}function Me(e,n){return{kind:"validation",type:"max_length",reference:Me,async:!1,expects:`<=${e}`,requirement:e,message:n,"~run"(o,s){return o.typed&&o.value.length>this.requirement&&B(this,"length",o,s,{received:`${o.value.length}`}),o}}}function ke(e,n){return{kind:"validation",type:"min_length",reference:ke,async:!1,expects:`>=${e}`,requirement:e,message:n,"~run"(o,s){return o.typed&&o.value.length<this.requirement&&B(this,"length",o,s,{received:`${o.value.length}`}),o}}}function Se(e,n){return{kind:"validation",type:"min_value",reference:Se,async:!1,expects:`>=${e instanceof Date?e.toJSON():ge(e)}`,requirement:e,message:n,"~run"(o,s){return o.typed&&!(o.value>=this.requirement)&&B(this,"value",o,s,{received:o.value instanceof Date?o.value.toJSON():ge(o.value)}),o}}}function He(e,n){return{kind:"validation",type:"regex",reference:He,async:!1,expects:`${e}`,requirement:e,message:n,"~run"(o,s){return o.typed&&!this.requirement.test(o.value)&&B(this,"format",o,s),o}}}function Le(e){return{kind:"transformation",type:"transform",reference:Le,async:!1,operation:e,"~run"(n){return n.value=this.operation(n.value),n}}}var pt={abortEarly:!0};function ft(e,n,o){return typeof e.fallback=="function"?e.fallback(n,o):e.fallback}function De(e,n,o){return typeof e.default=="function"?e.default(n,o):e.default}function mt(e,n){return!e["~run"]({value:n},pt).issues}function O(e,n){return{kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:n,get"~standard"(){return z(this)},"~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 f=c[l],y=this.item["~run"]({value:f},s);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:f};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 B(this,"type",o,s);return o}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return z(this)},"~run"(n,o){return typeof n.value=="boolean"?n.typed=!0:B(this,"type",n,o),n}}}function i(e,n){return{kind:"schema",type:"literal",reference:i,expects:ge(e),async:!1,literal:e,message:n,get"~standard"(){return z(this)},"~run"(o,s){return o.value===this.literal?o.typed=!0:B(this,"type",o,s),o}}}function Ve(e){return{kind:"schema",type:"nan",reference:Ve,expects:"NaN",async:!1,message:e,get"~standard"(){return z(this)},"~run"(n,o){return Number.isNaN(n.value)?n.typed=!0:B(this,"type",n,o),n}}}function J(e,n){return{kind:"schema",type:"nullable",reference:J,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:n,get"~standard"(){return z(this)},"~run"(o,s){return o.value===null&&(this.default!==void 0&&(o.value=De(this,o,s)),o.value===null)?(o.typed=!0,o):this.wrapped["~run"](o,s)}}}function P(e){return{kind:"schema",type:"number",reference:P,expects:"number",async:!1,message:e,get"~standard"(){return z(this)},"~run"(n,o){return typeof n.value=="number"&&!isNaN(n.value)?n.typed=!0:B(this,"type",n,o),n}}}function r(e,n){return{kind:"schema",type:"object",reference:r,expects:"Object",async:!1,entries:e,message:n,get"~standard"(){return z(this)},"~run"(o,s){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.value={};for(let l in this.entries){let f=this.entries[l];if(l in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let y=l in c?c[l]:De(f),m=f["~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(f.fallback!==void 0)o.value[l]=ft(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(B(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 B(this,"type",o,s);return o}}}function u(e,n){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:n,get"~standard"(){return z(this)},"~run"(o,s){return o.value===void 0&&(this.default!==void 0&&(o.value=De(this,o,s)),o.value===void 0)?(o.typed=!0,o):this.wrapped["~run"](o,s)}}}function R(e,n){return{kind:"schema",type:"picklist",reference:R,expects:ze(e.map(ge),"|"),async:!1,options:e,message:n,get"~standard"(){return z(this)},"~run"(o,s){return this.options.includes(o.value)?o.typed=!0:B(this,"type",o,s),o}}}function F(e,n,o){return{kind:"schema",type:"record",reference:F,expects:"Object",async:!1,key:e,value:n,message:o,get"~standard"(){return z(this)},"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let f in l)if(Yr(l,f)){let y=l[f],m=this.key["~run"]({value:f},c);if(m.issues){let _={type:"object",origin:"key",input:l,key:f,value:y};for(let M of m.issues)M.path=[_],s.issues?.push(M);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:f,value:y};for(let M of x.issues)M.path?M.path.unshift(_):M.path=[_],s.issues?.push(M);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 B(this,"type",s,c);return s}}}function p(e,n){return{kind:"schema",type:"strict_object",reference:p,expects:"Object",async:!1,entries:e,message:n,get"~standard"(){return z(this)},"~run"(o,s){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.value={};for(let l in this.entries){let f=this.entries[l];if(l in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let y=l in c?c[l]:De(f),m=f["~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(f.fallback!==void 0)o.value[l]=ft(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(B(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(!(l in this.entries)){B(this,"key",o,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else B(this,"type",o,s);return o}}}function t(e){return{kind:"schema",type:"string",reference:t,expects:"string",async:!1,message:e,get"~standard"(){return z(this)},"~run"(n,o){return typeof n.value=="string"?n.typed=!0:B(this,"type",n,o),n}}}function lt(e){let n;if(e)for(let o of e)if(n)for(let s of o.issues)n.push(s);else n=o.issues;return n}function I(e,n){return{kind:"schema",type:"union",reference:I,expects:ze(e.map(o=>o.expects),"|"),async:!1,options:e,message:n,get"~standard"(){return z(this)},"~run"(o,s){let c,l,f;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 f?f.push(m):f=[m]}if(c)return c;if(l){if(l.length===1)return l[0];B(this,"type",o,s,{issues:lt(l)}),o.typed=!0}else{if(f?.length===1)return f[0];B(this,"type",o,s,{issues:lt(f)})}return o}}}function Ie(){return{kind:"schema",type:"unknown",reference:Ie,expects:"unknown",async:!1,get"~standard"(){return z(this)},"~run"(e){return e.typed=!0,e}}}function g(e,n,o){return{kind:"schema",type:"variant",reference:g,expects:"Object",async:!1,key:e,options:n,message:o,get"~standard"(){return z(this)},"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let f,y=0,m=this.key,x=[],_=(M,S)=>{for(let H of M.options){if(H.type==="variant")_(H,new Set(S).add(H.key));else{let L=!0,Q=0;for(let j of S){let V=H.entries[j];if(j in l?V["~run"]({typed:!1,value:l[j]},pt).issues:V.type!=="exact_optional"&&V.type!=="optional"&&V.type!=="nullish"){L=!1,m!==j&&(y<Q||y===Q&&j in l&&!(m in l))&&(y=Q,m=j,x=[]),m===j&&x.push(H.entries[j].expects);break}Q++}if(L){let j=H["~run"]({value:l},c);(!f||!f.typed&&j.typed)&&(f=j)}}if(f&&!f.issues)break}};if(_(this,new Set([this.key])),f)return f;B(this,"type",s,c,{input:l[m],expected:ze(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else B(this,"type",s,c);return s}}}function te(e,n,o){let s=e["~run"]({value:n},Ue(o));if(s.issues)throw new Zr(s.issues);return s.value}function U(...e){return{...e[0],pipe:e,get"~standard"(){return z(this)},"~run"(n,o){for(let s of e)if(s.kind!=="metadata"){if(n.issues&&(s.kind==="schema"||s.kind==="transformation")){n.typed=!1;break}(!n.issues||!o.abortEarly&&!o.abortPipeEarly)&&(n=s["~run"](n,o))}return n}}}function _e(e,n,o){let s=e["~run"]({value:n},Ue(o));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var ne=U(t(),re("NotionBlockId")),Y=U(t(),re("NotionDataSourceId")),D=U(t(),re("NotionPageId")),yt=U(t(),re("NotionAgentId")),vt=U(t(),re("NotionSpaceId"));var dt=R(["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"]),Ge=r({id:t(),name:t(),color:u(dt),description:u(t())}),en=r({id:t(),name:t(),color:u(dt),option_ids:O(t())}),tn=r({synced_property_id:t(),synced_property_name:t()}),E=r({name:t(),description:u(t())}),rn=["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"],ht=R(rn),gt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],$e=g("type",[r({...E.entries,type:i("title")}),r({...E.entries,type:i("rich_text")}),r({...E.entries,type:i("number")}),r({...E.entries,type:i("checkbox")}),r({...E.entries,type:i("url")}),r({...E.entries,type:i("email")}),r({...E.entries,type:i("phone_number")}),r({...E.entries,type:i("select"),options:O(Ge)}),r({...E.entries,type:i("multi_select"),options:O(Ge)}),r({...E.entries,type:i("status"),options:O(Ge),groups:O(en)}),r({...E.entries,type:i("date")}),r({...E.entries,type:i("people")}),r({...E.entries,type:i("files")}),r({...E.entries,type:i("unique_id")}),r({...E.entries,type:i("relation"),data_source_id:u(t()),dual_property:u(tn)}),r({...E.entries,type:i("place")}),r({...E.entries,type:i("formula")}),r({...E.entries,type:i("rollup")}),r({...E.entries,type:i("button")}),r({...E.entries,type:i("verification")}),r({...E.entries,type:i("last_visited_time")}),r({...E.entries,type:i("location")}),r({...E.entries,type:i("created_time")}),r({...E.entries,type:i("last_edited_time")}),r({...E.entries,type:i("created_by")}),r({...E.entries,type:i("last_edited_by")})]);var bt={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var kt=r({id:Y,table:t(),spaceId:u(vt)}),St=r({id:u(Y),propertiesById:F(t(),$e)}),So=r({key:t(),collectionPointer:u(kt),collectionSchema:u(St),propertyIdsByKey:F(t(),u(t())),propertySchemasById:F(t(),$e)}),nn=r({collectionPointer:u(kt),collectionSchema:u(St),propertyIdsByKey:u(F(t(),u(t())))}),le=F(t(),nn);var fe=R(["standard","high"]),It="standard";var _t=r({type:i("contrastModeChanged"),contrastMode:fe});var we=r({id:t(),table:t()});var oe=g("type",[r({type:i("page_id"),page_id:D}),r({type:i("data_source_id"),data_source_id:Y}),r({type:i("workspace"),workspace:i(!0)}),r({type:i("block_id"),block_id:ne}),r({type:i("agent_id"),agent_id:yt}),r({type:i("unavailable")})]);var me=g("type",[r({type:i("unavailable")}),r({type:i("page"),id:D,parent:oe})]),on=r({type:i("emoji"),emoji:t()}),sn=r({type:i("custom_emoji"),custom_emoji:r({id:t(),name:u(t()),url:u(t())})}),Pt=r({type:i("external"),external:r({url:t()})}),Ot=r({type:i("file"),file:r({url:t(),expiry_time:u(t())})}),Xe=g("type",[on,sn,Pt,Ot]),We=g("type",[Pt,Ot]),$=J(t()),xt=F(t(),Ie()),Qe=I([r({id:t(),name:u(t()),color:u(t()),description:u($)}),r({name:t(),id:u(t()),color:u(t()),description:u($)})]),an=r({start:t(),end:u($),time_zone:u($)}),un=I([r({object:u(i("user")),id:t()}),r({object:i("group"),id:t(),name:u($)})]),cn=r({id:t()}),ln=I([r({type:i("external"),name:t(),external:r({url:t()})}),r({type:i("file"),name:t(),file:r({url:t(),expiry_time:u(t())})})]),pn=r({lat:P(),lon:P(),name:u($),address:u($),aws_place_id:u($),google_place_id:u($)}),A={id:t()},Ct=J(r({...we.entries,table:R(["notion_user","bot","organization_bot"]),spaceId:u(t())})),Je=g("type",[r({...A,type:i("title"),title:O(xt)}),r({...A,type:i("rich_text"),rich_text:O(xt)}),r({...A,type:i("number"),number:J(P())}),r({...A,type:i("url"),url:$}),r({...A,type:i("email"),email:$}),r({...A,type:i("phone_number"),phone_number:$}),r({...A,type:i("checkbox"),checkbox:h()}),r({...A,type:i("select"),select:J(Qe)}),r({...A,type:i("status"),status:J(Qe)}),r({...A,type:i("multi_select"),multi_select:O(Qe)}),r({...A,type:i("date"),date:J(an)}),r({...A,type:i("people"),people:O(un)}),r({...A,type:i("relation"),has_more:u(h()),relation:O(cn)}),r({...A,type:i("files"),files:O(ln)}),r({...A,type:i("place"),place:J(pn)}),r({...A,type:i("created_time"),created_time:$}),r({...A,type:i("last_edited_time"),last_edited_time:$}),r({...A,type:i("created_by"),created_by:Ct}),r({...A,type:i("last_edited_by"),last_edited_by:Ct}),r({...A,type:i("last_visited_time"),last_visited_time:$})]),xe=F(t(),Je),ye=r({object:i("page"),id:D,parent:oe,properties:xe,created_time:u(t()),last_edited_time:u(t()),icon:u(Xe),cover:u(We),url:u(t()),public_url:u(t()),is_archived:h(),in_trash:h()});var fn=t(),mn=r({code:fn,message:t(),isRetryable:h()}),Et=g("status",[r({type:i("createPageResult"),requestId:t(),status:i("success"),page:ye}),r({type:i("createPageResult"),requestId:t(),status:i("error"),error:mn})]);var Ke=U(t(),re("NotionUserId")),ie=r({object:i("user"),id:Ke,name:u(t()),avatar_url:J(t()),type:i("person"),person:r({email:t()})}),jt=r({object:i("list"),results:O(ie),next_cursor:J(t()),has_more:h(),type:i("user"),user:F(t(),Ie())});var Bt=r({type:i("currentUserChanged"),currentUser:ie});var Rt=r({type:i("dataSourcesChanged"),dataSources:r({bindings:le})});var yn=t(),vn=r({code:yn,message:t(),isRetryable:h()}),Mt=r({type:i("getPage"),requestId:t(),pageId:D}),Dt=g("status",[r({type:i("getPageResult"),requestId:t(),status:i("success"),page:ye}),r({type:i("getPageResult"),requestId:t(),status:i("error"),error:vn})]);var dn=t(),hn=r({code:dn,message:t(),isRetryable:h()}),wt=r({type:i("getUser"),requestId:t(),userId:Ke}),At=g("status",[r({type:i("getUserResult"),requestId:t(),status:i("success"),user:ie}),r({type:i("getUserResult"),requestId:t(),status:i("error"),error:hn})]);var gn=g("type",[r({type:i("emoji"),emoji:t()}),r({type:i("external"),url:t()})]),bn=r({name:t(),description:u(t()),type:ht}),kn=r({name:t(),description:u(t()),icon:u(gn),properties:u(F(t(),bn),{})}),pe=r({version:i(1),name:u(t()),description:u(t()),slashCommand:u(t()),icon:u(r({type:i("emoji"),emoji:t()})),dataSources:u(F(t(),kn),{})});var ve=R(["light","dark"]);var Sn=t(),In=r({code:Sn,message:t(),isRetryable:h()});var Ae=g("status",[r({type:i("init"),initializationId:t(),status:i("success"),theme:ve,contrastMode:fe,blockId:ne,parent:oe,page:me,manifest:pe,dataSources:r({bindings:le}),currentUser:ie}),r({type:i("init"),initializationId:t(),status:i("error"),error:In})]);var Tt=r({type:i("invalidSandboxMessage"),reason:t()});var _n=t(),xn=r({code:_n,message:t(),isRetryable:h()}),qt=r({type:i("listUsers"),requestId:t(),startCursor:u(t()),pageSize:u(P())}),Nt=g("status",[r({type:i("listUsersResult"),requestId:t(),status:i("success"),list:jt}),r({type:i("listUsersResult"),requestId:t(),status:i("error"),error:xn})]);var Cn=R(["side_peek","center_peek"]),Pn=t(),On=r({code:Pn,message:t(),isRetryable:h()}),Ft=r({type:i("openPage"),requestId:t(),pageId:D,mode:Cn}),Ut=g("status",[r({type:i("openPageResult"),requestId:t(),status:i("success"),pageId:D}),r({type:i("openPageResult"),requestId:t(),status:i("error"),error:On})]);var zt=r({type:i("pageChanged"),page:me});var Ht=r({type:i("parentChanged"),parent:oe});var Lt=r({unit:R(["year","month","week","day"]),value:P(),time:t(),defaultTimeZone:u(t())}),En=r({unit:R(["hour","minute"]),value:P()}),Vt=r({unit:i("none")}),jn=I([Lt,En]),Gt=u(I([Lt,Vt])),$t=u(I([jn,Vt])),Bn=r({type:i("date"),start_date:t(),reminder:Gt}),Rn=r({type:i("daterange"),start_date:t(),end_date:t(),reminder:Gt}),Mn=r({type:i("datetime"),start_date:t(),start_time:t(),time_zone:u(t()),reminder:$t}),Dn=r({type:i("datetimerange"),start_date:t(),start_time:t(),end_date:t(),end_time:t(),time_zone:u(t()),reminder:$t}),Qt=g("type",[Bn,Rn,Mn,Dn]);var Xt=I([t(),P(),h(),Qt,O(t()),O(we)]);var Wt=r({id:D,is_archived:h(),in_trash:h(),propertiesById:F(t(),u(Xt))}),Jt=r({id:D,is_archived:h(),in_trash:h(),properties:F(t(),u(Je))});var wn=t(),An=r({code:wn,message:t(),isRetryable:h()}),Kt=g("status",[r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("success"),items:O(I([Jt,Wt])),hasMore:h()}),r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("error"),error:An})]);var Yt=r({type:i("themeChanged"),theme:ve});var Tn=t(),qn=r({code:Tn,message:t(),isRetryable:h()}),Zt=g("status",[r({type:i("updatePageResult"),requestId:t(),status:i("success"),page:ye}),r({type:i("updatePageResult"),requestId:t(),status:i("error"),error:qn})]);var er=g("type",[Ae,Yt,_t,Ht,zt,Bt,Rt,Kt,Et,Dt,At,Nt,Ut,Zt,Tt]);function tr(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function rr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function Ye(e){let{currentBridgeProtocolVersion:n}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${n}`,isRetryable:!1}}function Ze(e){let{currentBridgeProtocolVersion:n,minBridgeProtocolVersion:o}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${n} is not supported. Minimum supported version is ${o}.`,isRetryable:!1}}function et(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function nr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function or(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function ir(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function sr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function ar(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function ur(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Ce(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function se(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function tt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Nn=5e3,Fn=5e3,Un=5e3;function cr(e){let{prepareInit:n,sendInitMessage:o,warn:s,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:f=Nn,initialStateTimeoutMs:y=Fn,noInitResultTimeoutMs:m=Un,stopHostWithFailure:x,onInitResult:_,onConnectionFailure:M}=e,S="waitingForConnect",H,L,Q,j,V=!1,ae=!1;function W(){H!==void 0&&(window.clearTimeout(H),H=void 0)}function w(){L!==void 0&&(window.clearTimeout(L),L=void 0)}function T(){Q!==void 0&&(window.clearTimeout(Q),Q=void 0)}function q(b){let{initializationId:v,error:G,phase:ee,source:qe}=b;switch(S){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return se(S)}S="error",j=v,W(),w(),o({type:"init",initializationId:v,status:"error",error:G}),M?.({...G,phase:ee,source:qe})}async function K(b){if(S==="waitingForConnect"){S="preparingInit",j=b.initializationId,W(),L=window.setTimeout(()=>{if(S!=="preparingInit")return;let v=nr();s({...v,initializationId:b.initializationId}),q({initializationId:b.initializationId,error:v,phase:"init",source:"host"})},y);try{let v=await n(b);if(S!=="preparingInit")return;if(w(),v.status==="error"){q({initializationId:b.initializationId,error:v.error,phase:"init",source:"host"});return}S="waitingForInitResult";let G={type:"init",initializationId:b.initializationId,status:"success",theme:v.initialState.theme,contrastMode:v.initialState.contrastMode??It,blockId:v.initialState.blockId,parent:v.initialState.parent,page:v.initialState.page,currentUser:v.initialState.currentUser,manifest:v.initialState.manifest,dataSources:v.initialState.dataSources};o(G),Q=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let ee=ar();M?.({...ee,phase:"initResult",source:"host"}),s({...ee,initializationId:b.initializationId})},m)}catch(v){if(S!=="preparingInit")return;s({message:"Failed to prepare custom block initialization",error:v}),q({initializationId:b.initializationId,error:Ce(),phase:"init",source:"host"})}}}function Z(b){if(S!=="stopped"&&S==="waitingForConnect"){if(!tt(b.bridgeProtocolVersion)){let v=Ye({currentBridgeProtocolVersion:b.bridgeProtocolVersion});q({initializationId:b.initializationId,error:v,phase:"connect",source:"host"});return}if(b.bridgeProtocolVersion<l){let v=Ze({currentBridgeProtocolVersion:b.bridgeProtocolVersion,minBridgeProtocolVersion:l});q({initializationId:b.initializationId,error:v,phase:"connect",source:"host"});return}if(b.status==="error"){q({initializationId:b.initializationId,error:b.error,phase:"connect",source:"sandbox"});return}ae=!0,K(b)}}function C(b){if(S==="stopped"||S!=="waitingForConnect")return"handled";let{initializationId:v,bridgeProtocolVersion:G}=b;if(v===void 0)return"nack";let ee=b.error;return G!==void 0&&(tt(G)?G<l&&(ee=Ze({currentBridgeProtocolVersion:G,minBridgeProtocolVersion:l})):ee=Ye({currentBridgeProtocolVersion:G})),q({initializationId:v,error:ee,phase:"connect",source:"host"}),"handled"}function ue(b){let{initializationId:v,error:G}=b;S!=="waitingForInitResult"||v===void 0||v!==j||(W(),T(),S="error",s(G),M?.({...G,phase:"initResult",source:"host"}))}function Be(){if(S!=="stopped"){if(V){x({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}V=!0,W(),S==="waitingForConnect"&&(H=window.setTimeout(()=>{if(S!=="waitingForConnect")return;S="error";let b=tr();s(b),M?.({...b,phase:"connect",source:"host"})},f))}}function de(b){if(S!=="waitingForInitResult"||b.initializationId!==j){s({message:"Ignored stale or unexpected initResult",payload:b});return}T(),S=b.status==="success"?"initialized":"error",b.status==="success"?c():M?.({...b.error,phase:"initResult",source:"sandbox"}),_?.(b)}function ce(){S="stopped",W(),w(),T()}return{get status(){return S},get hasConnectedSandbox(){return ae},handleConnect:Z,handleInitResult:de,handleInvalidConnect:C,handleInvalidInitResult:ue,onIframeLoad:Be,stop:ce}}function rt({url:e,hostOrigin:n}){return typeof n=="string"&&n!==""&&e.origin!==n&&(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 lr(e){let n=new AbortController,o=()=>n.abort();e.signal.addEventListener("abort",o,{once:!0});let s=new Promise((l,f)=>{n.signal.addEventListener("abort",()=>f(n.signal.reason),{once:!0})});e.signal.aborted&&n.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{n.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?zn(e.sandboxOrigin,n.signal):e.getPersistedManifest({signal:n.signal}),s]);if(n.signal.aborted)throw new Error("Manifest loading was cancelled.");return{status:"success",manifest:te(pe,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 zn(e,n){let o=new URL(e);if(!rt({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:n});if(!s.ok)throw new Error(`Manifest request failed: HTTP ${s.status}.`);return s.json()}function pr(e,n){return n>=5||!(e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged")?e:{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([s,c])=>[s,{...c,collectionSchema:{...c.collectionSchema,propertiesById:{...c.collectionSchema?.propertiesById,...bt}}}]))}}}var fr=r({theme:ve,contrastMode:u(fe),blockId:ne,parent:oe,page:me,manifest:pe,dataSources:r({bindings:le}),currentUser:ie});function mr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var yr=r({code:t(),message:t(),isRetryable:h()});var vr={type:i("connect"),initializationId:t(),bridgeProtocolVersion:P(),sdkVersion:t()},dr=g("status",[r({status:i("success"),manifest:u(pe),...vr}),r({status:i("error"),error:yr,...vr})]);var Hn=g("type",[r({type:i("start")}),r({type:i("end")}),r({type:i("before"),blockId:ne}),r({type:i("after"),blockId:ne})]),Ln=g("type",[r({type:i("page_id"),page_id:D}),r({type:i("data_source_id"),data_source_id:Y})]),hr=r({type:i("createPage"),requestId:t(),parent:Ln,properties:xe,position:u(Hn)});var Vn=t(),Gn=r({code:Vn,message:t(),isRetryable:h()}),gr=g("status",[r({type:i("initResult"),initializationId:t(),status:i("success"),initialHeight:u(U(P(),be(),Se(0)))}),r({type:i("initResult"),initializationId:t(),status:i("error"),error:Gn})]);var br=r({type:i("invalidHostMessage"),reason:t()});var kr=R(["ascending","descending"]);var Sr=U(D,He(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Le(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),nt=I([p({contains:Sr}),p({does_not_contain:Sr})]),je=I([p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Ee=I([t(),O(t())]),Ir=p({object:R(["user","group"]),id:U(t(),ke(1))}),$n=I([p({contains:Ir}),p({does_not_contain:Ir}),je]),_r=p({object:i("user"),id:U(t(),ke(1),Me(2e3))}),Qn=I([p({contains:_r}),p({does_not_contain:_r}),p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Pe=I([p({equals:t()}),p({does_not_equal:t()}),p({contains:t()}),p({does_not_contain:t()}),p({starts_with:t()}),p({ends_with:t()}),je]),Xn=I([p({equals:P()}),p({does_not_equal:P()}),p({greater_than:P()}),p({less_than:P()}),p({greater_than_or_equal_to:P()}),p({less_than_or_equal_to:P()}),je]),Wn=I([p({equals:h()}),p({does_not_equal:h()})]),Or=I([p({equals:Ee}),p({does_not_equal:Ee}),je]),xr=R(["To-do","In progress","Complete","Current","Future"]),Cr=I([xr,U(O(xr),ke(1),Me(5))]),Jn=I([p({group_equals:Cr}),p({group_does_not_equal:Cr})]),Kn=I([Or,Jn]),Yn=I([p({contains:Ee}),p({contains_all:Ee}),p({does_not_contain:Ee}),je]),X=R(["start_date","end_date"]),Zn=R(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Oe=I([Zn,t()]),eo=I([p({target:u(X),equals:Oe}),p({target:u(X),before:Oe}),p({target:u(X),after:Oe}),p({target:u(X),on_or_before:Oe}),p({target:u(X),on_or_after:Oe}),p({target:u(X),this_week:p({})}),p({target:u(X),past_week:p({})}),p({target:u(X),past_month:p({})}),p({target:u(X),past_year:p({})}),p({target:u(X),next_week:p({})}),p({target:u(X),next_month:p({})}),p({target:u(X),next_year:p({})}),p({target:u(X),is_empty:i(!0)}),p({target:u(X),is_not_empty:i(!0)})]),Pr=I([p({propertyId:t(),relation:nt}),p({propertyId:t(),created_by:Qn}),p({propertyId:t(),title:Pe}),p({propertyId:t(),rich_text:Pe}),p({propertyId:t(),url:Pe}),p({propertyId:t(),email:Pe}),p({propertyId:t(),phone_number:Pe}),p({propertyId:t(),number:Xn}),p({propertyId:t(),checkbox:Wn}),p({propertyId:t(),select:Or}),p({propertyId:t(),multi_select:Yn}),p({propertyId:t(),status:Kn}),p({propertyId:t(),date:eo}),p({propertyId:t(),people:$n})]),to=I([Pr,p({and:O(Pr)})]),ot=10,ro=p({propertyId:t(),direction:kr}),Er=r({type:i("queryDataSource"),subscriptionId:t(),dataSourceId:Y,limit:P(),filter:u(to),sorts:u(O(ro))});var jr=r({type:i("resize"),height:U(P(),be(),Se(0))});var Br=r({type:i("unsubscribeDataSourceQuery"),subscriptionId:t()});var Rr=r({type:i("updatePage"),requestId:t(),pageId:D,properties:u(xe),icon:u(Xe),cover:u(We),archived:u(h())});var Mr=g("type",[dr,gr,Er,Br,hr,Mt,wt,qt,Ft,Rr,jr,br]);function Dr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function wr(e){let n=Dr(e);return n==="invalidHostMessage"||n==="invalidSandboxMessage"?{incomingType:n}:{incomingType:n,nack:{type:"invalidSandboxMessage",reason:no(n)}}}function no(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var Ar=r({initializationId:t()}),oo=r({bridgeProtocolVersion:I([P(),Ve()])});function Tr(e){let{iframe:n,sandboxOrigin:o,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:f,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:M,onCreatePage:S,onGetPage:H,onOpenPage:L,onGetUser:Q,onListUsers:j,onUpdatePage:V,onResize:ae}=e;function W(w,T){c("warn",{message:"Ignored unsupported sandbox message",payload:w,issues:T});let q=wr(w);if(q.incomingType==="connect"){let K=_e(Ar,w),Z=_e(oo,w);if(f({initializationId:K.success?K.output.initializationId:void 0,error:rr(),bridgeProtocolVersion:Z.success?Z.output.bridgeProtocolVersion:void 0})==="handled")return}if(q.incomingType==="initResult"){let K=_e(Ar,w);y({initializationId:K.success?K.output.initializationId:void 0,error:ur()})}q.nack!==void 0&&s()!=="stopped"&&l(q.nack)}return function(T){let q=T.source===n.contentWindow,K=T.origin===o;if(!q||!K)return;let Z=_e(Mr,T.data);if(!Z.success){W(T.data,Z.issues);return}let C=Z.output;if(!mr(C)&&s()!=="initialized"){c("warn",{message:`Ignored ${C.type} before initialization completed`,payload:C});return}switch(c("in",C),C.type){case"connect":m(C);return;case"initResult":x(C);return;case"queryDataSource":_(C);return;case"unsubscribeDataSourceQuery":M(C);return;case"createPage":S(C);return;case"openPage":L(C);return;case"getPage":H(C);return;case"getUser":Q(C);return;case"listUsers":j(C);return;case"updatePage":V(C);return;case"resize":ae(C);return;case"invalidHostMessage":return;default:se(C)}}}var Te=class{constructor(n){this.onUnsubscribe=n}onUnsubscribe;bySubscriptionId=new Map;subscribe(n){this.unsubscribe(n.subscriptionId);let o={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(n.subscriptionId,{message:n,token:o,isRefreshing:!0,shouldRefreshAgain:!1}),o}isCurrent(n,o){return this.bySubscriptionId.get(n)?.token===o}unsubscribe(n){this.bySubscriptionId.delete(n)&&this.onUnsubscribe(n)}refresh(n){let o=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===n){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(n,o){let s=this.bySubscriptionId.get(n);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 n of this.bySubscriptionId.keys())this.unsubscribe(n)}};function qr(e,n){if(e===void 0)return;let o="and"in e?e.and:[e];for(let s of o){let c=io(s,n);if(c!==void 0)return c}}function io(e,n){if(!Object.hasOwn(n.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=n.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(M=>!o.groups.some(S=>S.name===M));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!mt(nt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=so(e);if(c===void 0||o.type!==c.propertyType)return;let l=new Set(o.options.map(y=>y.name)),f=ao(c.operator).find(y=>!l.has(y));if(f!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${f}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function so(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 n=e.status;return"group_equals"in n||"group_does_not_equal"in n?void 0:{propertyType:"status",operator:n}}}function ao(e){let n;if("equals"in e)n=e.equals;else if("does_not_equal"in e)n=e.does_not_equal;else if("contains"in e)n=e.contains;else if("contains_all"in e)n=e.contains_all;else if("does_not_contain"in e)n=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:se(e);return Array.isArray(n)?n:[n]}var uo=new Set(gt);function Nr(e,n){if(e===void 0)return;if(e.length>ot)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${ot} 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(n.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=n.propertiesById[s.propertyId];if(!uo.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 Ur=5;function co(e){let{iframe:n,prepareInitialState:o,handlers:s,onInitialized:c,onConnectionFailure:l,onLog:f,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:x,noConnectTimeoutMs:_,initialStateTimeoutMs:M,noInitResultTimeoutMs:S}=e,H=Math.max(x??3,3),L={},Q=!1,j=new AbortController,V,ae,W=6,w=new Te(a=>{y?.(a)});function T(a,k){f?.(a,k)}function q(a){let k=v.status;switch(k){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return se(k)}let N=pr(a,W);T("out",N),n.contentWindow?.postMessage(N,m)}function K(a){q(te(Ae,a))}function Z(a){q(a)}function C(a){let k=v.status;switch(k){case"initialized":q(te(er,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:se(k)}}async function ue(a,k){if(k===void 0)return;let N=await k(a);C({type:`${a.type}Result`,requestId:a.requestId,...N})}function Be(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};C(k)}async function de(a,k=w.subscribe(a)){try{let N=lo(ae,a.dataSourceId),he=po(a,N);if(he!==void 0){w.isCurrent(a.subscriptionId,k)&&(w.unsubscribe(a.subscriptionId),Be({subscriptionId:a.subscriptionId,response:{status:"error",error:he}}));return}let Ne=await s.queryDataSource(a);if(!w.isCurrent(a.subscriptionId,k))return;Ne.status==="error"&&!Ne.error.isRetryable&&w.unsubscribe(a.subscriptionId),Be({subscriptionId:a.subscriptionId,response:Ne})}finally{let N=w.finish(a.subscriptionId,k);N!==void 0&&de(N.message,N.token)}}function ce(a){v.status==="stopped"||v.status==="error"||(Object.assign(L,a),b())}function b(){if(v.status!=="initialized")return;let a=L;L={},a.theme!==void 0&&C({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&C({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&C({type:"parentChanged",parent:a.parent}),a.page!==void 0&&C({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&C({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&C({type:"currentUserChanged",currentUser:a.currentUser})}let v=cr({async prepareInit(a){W=a.bridgeProtocolVersion;let k=await ee;return v.status!=="preparingInit"?k:G(k)},sendInitMessage:K,warn:a=>T("warn",a),flushPendingHostStateChanges:b,minBridgeProtocolVersion:H,noConnectTimeoutMs:_,initialStateTimeoutMs:M,noInitResultTimeoutMs:S,stopHostWithFailure:at,onInitResult(a){a.status==="success"&&V!==void 0&&c?.({manifest:V,initialHeight:a.initialHeight})},onConnectionFailure:a=>{j.abort(),l?.(a)}});function G(a){if(a.status==="error")return a;let k=te(fr,{...a.initialState,...L});if(V=k.manifest,L={},W<Ur&&k.page.type==="unavailable")return{status:"error",error:et()};let N=zr(k.manifest,k.dataSources);return N!==void 0?{status:"error",error:N}:(ae=k.dataSources,Q=!0,{status:"success",initialState:k})}let ee=qe().catch(a=>(j.signal.aborted||T("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Ce()}));async function qe(){let a=await lr({...e,sandboxOrigin:m,signal:j.signal,onError:N=>{T("warn",{message:"Failed to load custom block manifest",error:N})}});if(a.status==="error")return a;if(j.signal.aborted)return{status:"error",error:Ce()};let k=await o({manifest:a.manifest,signal:j.signal});return k.status==="error"?k:{status:"success",initialState:{...k.initialState,manifest:a.manifest}}}let it=Tr({iframe:n,sandboxOrigin:m,getInitStatus:()=>v.status,emit:T,sendNack:Z,onInvalidConnect:v.handleInvalidConnect,onInvalidInitResult:v.handleInvalidInitResult,onConnect:v.handleConnect,onInitResult:v.handleInitResult,onQueryDataSource:de,onUnsubscribeDataSourceQuery:a=>w.unsubscribe(a.subscriptionId),onCreatePage:a=>ue(a,s.createPage),onGetPage:a=>ue(a,s.getPage),onOpenPage:a=>ue(a,s.openPage),onGetUser:a=>ue(a,s.getUser),onListUsers:a=>ue(a,s.listUsers),onUpdatePage:a=>ue(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",it),n.addEventListener("load",v.onIframeLoad);function st(){j.abort(),window.removeEventListener("message",it),n.removeEventListener("load",v.onIframeLoad),v.stop(),w.unsubscribeAll()}function at(a){st(),T("warn",a),l?.(a)}return{stop:st,setTheme(a){ce({theme:a})},setContrastMode(a){ce({contrastMode:a})},setParent(a){ce({parent:a})},setPage(a){if(a.type==="unavailable"&&W<Ur&&(v.status==="preparingInit"&&Q||v.status==="waitingForInitResult"||v.status==="initialized")){at({...et(),phase:"runtime",source:"host"});return}ce({page:a})},setCurrentUser(a){ce({currentUser:a})},setDataSources(a){let k={bindings:te(le,a.bindings)};if(v.hasConnectedSandbox&&V!==void 0&&zr(V,k)!==void 0){T("warn",{message:"Ignored invalid data source bindings update",payload:k});return}ae=k,ce({dataSources:k})},refreshQuery({dataSourceId:a}){if(v.status!=="initialized")return;let k=te(Y,a),N=w.refresh(k);if(N===void 0){T("warn",`No active query exists for data source "${a}"`);return}for(let he of N)de(he.message,he.token)}}}function lo(e,n){return Object.values(e?.bindings??{}).find(o=>o.collectionPointer?.id===n)?.collectionSchema}function zr(e,n){for(let[o,s]of Object.entries(e.dataSources)){let c=n.bindings[o];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return or();for(let[l,f]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return ir();if(c.collectionSchema.propertiesById[y]?.type!==f.type)return sr()}}}function po(e,n){return n===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}:qr(e.filter,n)??Nr(e.sorts,n)}function fo(e){return te(D,e)}export{Fe as LATEST_BRIDGE_PROTOCOL_VERSION,Hr as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,co as createCustomBlockHost,Lr as getAutoBoundPropertyIdsByKey,rt as isLocalCustomBlockUrl,fo as toNotionPageId};
1
+ var Ue=6,Fe=6;function rn(e){let{manifestProperties:t,propertySchemasById:n}=e,i=[];for(let[l,c]of Object.entries(t)){let p=nn({propertyKey:l,manifestProperty:c,propertySchemasById:n});p!==void 0&&i.push([l,p])}return Object.fromEntries(i)}function nn(e){let{propertyKey:t,manifestProperty:n,propertySchemasById:i}=e,l=ft(n.name),c=Object.entries(i).filter(([p,y])=>y.type===n.type&&(p===t||ft(y.name)===l));return c.length===1?c[0][0]:void 0}function ft(e){return e.trim().toLowerCase()}var Me,on={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function ze(e){return!e&&!Me?on:{lang:e?.lang??Me?.lang,message:e?.message,abortEarly:e?.abortEarly??Me?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Me?.abortPipeEarly}}var sn;function an(e){return sn?.get(e)}var un;function cn(e){return un?.get(e)}var ln;function pn(e,t){return ln?.get(e)?.get(t)}function be(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 D(e,t,n,i,l){let c=l&&"input"in l?l.input:n.value,p=l?.expected??e.expects??null,y=l?.received??be(c),m={kind:e.kind,type:e.type,input:c,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:l?.path,issues:l?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},I=e.kind==="schema",_=l?.message??e.message??pn(e.reference,m.lang)??(I?cn(m.lang):null)??i.message??an(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),I&&(n.typed=!1),n.issues?n.issues.push(m):n.issues=[m]}var mt=new WeakMap;function L(e){let t=mt.get(e);return t||(t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},ze())}},mt.set(e,t)),t}function fn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function He(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}var mn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ae(e){return{kind:"transformation",type:"brand",reference:ae,async:!1,name:e,"~run"(t){return t}}}function Se(e){return{kind:"validation",type:"finite",reference:Se,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,n){return t.typed&&!this.requirement(t.value)&&D(this,"finite",t,n),t}}}function De(e,t){return{kind:"validation",type:"max_length",reference:De,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(n,i){return n.typed&&n.value.length>this.requirement&&D(this,"length",n,i,{received:`${n.value.length}`}),n}}}function ke(e,t){return{kind:"validation",type:"min_length",reference:ke,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(n,i){return n.typed&&n.value.length<this.requirement&&D(this,"length",n,i,{received:`${n.value.length}`}),n}}}function Ie(e,t){return{kind:"validation",type:"min_value",reference:Ie,async:!1,expects:`>=${e instanceof Date?e.toJSON():be(e)}`,requirement:e,message:t,"~run"(n,i){return n.typed&&!(n.value>=this.requirement)&&D(this,"value",n,i,{received:n.value instanceof Date?n.value.toJSON():be(n.value)}),n}}}function Le(e,t){return{kind:"validation",type:"regex",reference:Le,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(n,i){return n.typed&&!this.requirement.test(n.value)&&D(this,"format",n,i),n}}}function Ve(e){return{kind:"transformation",type:"transform",reference:Ve,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var dt={abortEarly:!0};function vt(e,t,n){return typeof e.fallback=="function"?e.fallback(t,n):e.fallback}function we(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function ht(e,t){return!e["~run"]({value:t},dt).issues}function O(e,t){return{kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:t,get"~standard"(){return L(this)},"~run"(n,i){let l=n.value;if(Array.isArray(l)){n.typed=!0,n.value=[];for(let c=0;c<l.length;c++){let p=l[c],y=this.item["~run"]({value:p},i);if(y.issues){let m={type:"array",origin:"value",input:l,key:c,value:p};for(let I of y.issues)I.path?I.path.unshift(m):I.path=[m],n.issues?.push(I);if(n.issues||(n.issues=y.issues),i.abortEarly){n.typed=!1;break}}y.typed||(n.typed=!1),n.value.push(y.value)}}else D(this,"type",n,i);return n}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return L(this)},"~run"(t,n){return typeof t.value=="boolean"?t.typed=!0:D(this,"type",t,n),t}}}function s(e,t){return{kind:"schema",type:"literal",reference:s,expects:be(e),async:!1,literal:e,message:t,get"~standard"(){return L(this)},"~run"(n,i){return n.value===this.literal?n.typed=!0:D(this,"type",n,i),n}}}function Ge(e){return{kind:"schema",type:"nan",reference:Ge,expects:"NaN",async:!1,message:e,get"~standard"(){return L(this)},"~run"(t,n){return Number.isNaN(t.value)?t.typed=!0:D(this,"type",t,n),t}}}function Z(e,t){return{kind:"schema",type:"nullable",reference:Z,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return L(this)},"~run"(n,i){return n.value===null&&(this.default!==void 0&&(n.value=we(this,n,i)),n.value===null)?(n.typed=!0,n):this.wrapped["~run"](n,i)}}}function C(e){return{kind:"schema",type:"number",reference:C,expects:"number",async:!1,message:e,get"~standard"(){return L(this)},"~run"(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:D(this,"type",t,n),t}}}function o(e,t){return{kind:"schema",type:"object",reference:o,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return L(this)},"~run"(n,i){let l=n.value;if(l&&typeof l=="object"){n.typed=!0,n.value={};for(let c in this.entries){let p=this.entries[c];if(c in l||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=c in l?l[c]:we(p),m=p["~run"]({value:y},i);if(m.issues){let I={type:"object",origin:"value",input:l,key:c,value:y};for(let _ of m.issues)_.path?_.path.unshift(I):_.path=[I],n.issues?.push(_);if(n.issues||(n.issues=m.issues),i.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[c]=m.value}else if(p.fallback!==void 0)n.value[c]=vt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(D(this,"key",n,i,{input:void 0,expected:`"${c}"`,path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]}),i.abortEarly))break}}else D(this,"type",n,i);return n}}}function u(e,t){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return L(this)},"~run"(n,i){return n.value===void 0&&(this.default!==void 0&&(n.value=we(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,i)}}}function w(e,t){return{kind:"schema",type:"picklist",reference:w,expects:He(e.map(be),"|"),async:!1,options:e,message:t,get"~standard"(){return L(this)},"~run"(n,i){return this.options.includes(n.value)?n.typed=!0:D(this,"type",n,i),n}}}function N(e,t,n){return{kind:"schema",type:"record",reference:N,expects:"Object",async:!1,key:e,value:t,message:n,get"~standard"(){return L(this)},"~run"(i,l){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let p in c)if(fn(c,p)){let y=c[p],m=this.key["~run"]({value:p},l);if(m.issues){let _={type:"object",origin:"key",input:c,key:p,value:y};for(let E of m.issues)E.path=[_],i.issues?.push(E);if(i.issues||(i.issues=m.issues),l.abortEarly){i.typed=!1;break}}let I=this.value["~run"]({value:y},l);if(I.issues){let _={type:"object",origin:"value",input:c,key:p,value:y};for(let E of I.issues)E.path?E.path.unshift(_):E.path=[_],i.issues?.push(E);if(i.issues||(i.issues=I.issues),l.abortEarly){i.typed=!1;break}}(!m.typed||!I.typed)&&(i.typed=!1),m.typed&&(i.value[m.value]=I.value)}}else D(this,"type",i,l);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 L(this)},"~run"(n,i){let l=n.value;if(l&&typeof l=="object"){n.typed=!0,n.value={};for(let c in this.entries){let p=this.entries[c];if(c in l||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=c in l?l[c]:we(p),m=p["~run"]({value:y},i);if(m.issues){let I={type:"object",origin:"value",input:l,key:c,value:y};for(let _ of m.issues)_.path?_.path.unshift(I):_.path=[I],n.issues?.push(_);if(n.issues||(n.issues=m.issues),i.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[c]=m.value}else if(p.fallback!==void 0)n.value[c]=vt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(D(this,"key",n,i,{input:void 0,expected:`"${c}"`,path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]}),i.abortEarly))break}if(!n.issues||!i.abortEarly){for(let c in l)if(!(c in this.entries)){D(this,"key",n,i,{input:c,expected:"never",path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]});break}}}else D(this,"type",n,i);return n}}}function r(e){return{kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,get"~standard"(){return L(this)},"~run"(t,n){return typeof t.value=="string"?t.typed=!0:D(this,"type",t,n),t}}}function yt(e){let t;if(e)for(let n of e)if(t)for(let i of n.issues)t.push(i);else t=n.issues;return t}function x(e,t){return{kind:"schema",type:"union",reference:x,expects:He(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return L(this)},"~run"(n,i){let l,c,p;for(let y of this.options){let m=y["~run"]({value:n.value},i);if(m.typed)if(m.issues)c?c.push(m):c=[m];else{l=m;break}else p?p.push(m):p=[m]}if(l)return l;if(c){if(c.length===1)return c[0];D(this,"type",n,i,{issues:yt(c)}),n.typed=!0}else{if(p?.length===1)return p[0];D(this,"type",n,i,{issues:yt(p)})}return n}}}function _e(){return{kind:"schema",type:"unknown",reference:_e,expects:"unknown",async:!1,get"~standard"(){return L(this)},"~run"(e){return e.typed=!0,e}}}function d(e,t,n){return{kind:"schema",type:"variant",reference:d,expects:"Object",async:!1,key:e,options:t,message:n,get"~standard"(){return L(this)},"~run"(i,l){let c=i.value;if(c&&typeof c=="object"){let p,y=0,m=this.key,I=[],_=(E,S)=>{for(let U of E.options){if(U.type==="variant")_(U,new Set(S).add(U.key));else{let V=!0,F=0;for(let B of S){let Y=U.entries[B];if(B in c?Y["~run"]({typed:!1,value:c[B]},dt).issues:Y.type!=="exact_optional"&&Y.type!=="optional"&&Y.type!=="nullish"){V=!1,m!==B&&(y<F||y===F&&B in c&&!(m in c))&&(y=F,m=B,I=[]),m===B&&I.push(U.entries[B].expects);break}F++}if(V){let B=U["~run"]({value:c},l);(!p||!p.typed&&B.typed)&&(p=B)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;D(this,"type",i,l,{input:c[m],expected:He(I,"|"),path:[{type:"object",origin:"value",input:c,key:m,value:c[m]}]})}else D(this,"type",i,l);return i}}}function se(e,t,n){let i=e["~run"]({value:t},ze(n));if(i.issues)throw new mn(i.issues);return i.value}function H(...e){return{...e[0],pipe:e,get"~standard"(){return L(this)},"~run"(t,n){for(let i of e)if(i.kind!=="metadata"){if(t.issues&&(i.kind==="schema"||i.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=i["~run"](t,n))}return t}}}function xe(e,t,n){let i=e["~run"]({value:t},ze(n));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}var ue=H(r(),ae("NotionBlockId")),re=H(r(),ae("NotionDataSourceId")),q=H(r(),ae("NotionPageId")),gt=H(r(),ae("NotionAgentId")),bt=H(r(),ae("NotionSpaceId"));var St=w(["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"]),$e=o({id:r(),name:r(),color:u(St),description:u(r())}),yn=o({id:r(),name:r(),color:u(St),option_ids:O(r())}),dn=o({synced_property_id:r(),synced_property_name:r()}),j=o({name:r(),description:u(r())}),vn=["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"],kt=w(vn),It=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Qe=d("type",[o({...j.entries,type:s("title")}),o({...j.entries,type:s("rich_text")}),o({...j.entries,type:s("number")}),o({...j.entries,type:s("checkbox")}),o({...j.entries,type:s("url")}),o({...j.entries,type:s("email")}),o({...j.entries,type:s("phone_number")}),o({...j.entries,type:s("select"),options:O($e)}),o({...j.entries,type:s("multi_select"),options:O($e)}),o({...j.entries,type:s("status"),options:O($e),groups:O(yn)}),o({...j.entries,type:s("date")}),o({...j.entries,type:s("people")}),o({...j.entries,type:s("files")}),o({...j.entries,type:s("unique_id")}),o({...j.entries,type:s("relation"),data_source_id:u(r()),dual_property:u(dn)}),o({...j.entries,type:s("place")}),o({...j.entries,type:s("formula")}),o({...j.entries,type:s("rollup")}),o({...j.entries,type:s("button")}),o({...j.entries,type:s("verification")}),o({...j.entries,type:s("last_visited_time")}),o({...j.entries,type:s("location")}),o({...j.entries,type:s("created_time")}),o({...j.entries,type:s("last_edited_time")}),o({...j.entries,type:s("created_by")}),o({...j.entries,type:s("last_edited_by")})]);var _t=o({id:re,table:r(),spaceId:u(bt)}),xt=o({id:u(re),propertiesById:N(r(),Qe)}),Ao=o({key:r(),collectionPointer:u(_t),collectionSchema:u(xt),propertyIdsByKey:N(r(),u(r())),propertySchemasById:N(r(),Qe)}),hn=o({collectionPointer:u(_t),collectionSchema:u(xt),propertyIdsByKey:u(N(r(),u(r())))}),fe=N(r(),hn);var de=w(["standard","high"]),Ct="standard";var Et=o({type:s("contrastModeChanged"),contrastMode:de});var Te=o({id:r(),table:r()});var ce=d("type",[o({type:s("page_id"),page_id:q}),o({type:s("data_source_id"),data_source_id:re}),o({type:s("workspace"),workspace:s(!0)}),o({type:s("block_id"),block_id:ue}),o({type:s("agent_id"),agent_id:gt}),o({type:s("unavailable")})]);var ve=d("type",[o({type:s("unavailable")}),o({type:s("page"),id:q,parent:ce})]),gn=o({type:s("emoji"),emoji:r()}),bn=o({type:s("custom_emoji"),custom_emoji:o({id:r(),name:u(r()),url:u(r())})}),jt=o({type:s("external"),external:o({url:r()})}),Bt=o({type:s("file"),file:o({url:r(),expiry_time:u(r())})}),We=d("type",[gn,bn,jt,Bt]),Je=d("type",[jt,Bt]),Q=Z(r()),Ot=N(r(),_e()),Xe=x([o({id:r(),name:u(r()),color:u(r()),description:u(Q)}),o({name:r(),id:u(r()),color:u(r()),description:u(Q)})]),Sn=o({start:r(),end:u(Q),time_zone:u(Q)}),kn=x([o({object:u(s("user")),id:r()}),o({object:s("group"),id:r(),name:u(Q)})]),In=o({id:r()}),_n=x([o({type:s("external"),name:r(),external:o({url:r()})}),o({type:s("file"),name:r(),file:o({url:r(),expiry_time:u(r())})})]),xn=o({lat:C(),lon:C(),name:u(Q),address:u(Q),aws_place_id:u(Q),google_place_id:u(Q)}),A={id:r()},Pt=Z(o({...Te.entries,table:w(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Ke=d("type",[o({...A,type:s("title"),title:O(Ot)}),o({...A,type:s("rich_text"),rich_text:O(Ot)}),o({...A,type:s("number"),number:Z(C())}),o({...A,type:s("url"),url:Q}),o({...A,type:s("email"),email:Q}),o({...A,type:s("phone_number"),phone_number:Q}),o({...A,type:s("checkbox"),checkbox:h()}),o({...A,type:s("select"),select:Z(Xe)}),o({...A,type:s("status"),status:Z(Xe)}),o({...A,type:s("multi_select"),multi_select:O(Xe)}),o({...A,type:s("date"),date:Z(Sn)}),o({...A,type:s("people"),people:O(kn)}),o({...A,type:s("relation"),has_more:u(h()),relation:O(In)}),o({...A,type:s("files"),files:O(_n)}),o({...A,type:s("place"),place:Z(xn)}),o({...A,type:s("created_time"),created_time:Q}),o({...A,type:s("last_edited_time"),last_edited_time:Q}),o({...A,type:s("created_by"),created_by:Pt}),o({...A,type:s("last_edited_by"),last_edited_by:Pt}),o({...A,type:s("last_visited_time"),last_visited_time:Q})]),Ce=N(r(),Ke),he=o({object:s("page"),id:q,parent:ce,properties:Ce,created_time:u(r()),last_edited_time:u(r()),icon:u(We),cover:u(Je),url:u(r()),public_url:u(r()),is_archived:h(),in_trash:h()});var Cn=r(),En=o({code:Cn,message:r(),isRetryable:h()}),Rt=d("status",[o({type:s("createPageResult"),requestId:r(),status:s("success"),page:he}),o({type:s("createPageResult"),requestId:r(),status:s("error"),error:En})]);var Ye=H(r(),ae("NotionUserId")),le=o({object:s("user"),id:Ye,name:u(r()),avatar_url:Z(r()),type:s("person"),person:o({email:r()})}),Mt=o({object:s("list"),results:O(le),next_cursor:Z(r()),has_more:h(),type:s("user"),user:N(r(),_e())});var Dt=o({type:s("currentUserChanged"),currentUser:le});var wt=o({type:s("dataSourcesChanged"),dataSources:o({bindings:fe})});var On=r(),Pn=o({code:On,message:r(),isRetryable:h()}),Tt=o({type:s("getPage"),requestId:r(),pageId:q}),qt=d("status",[o({type:s("getPageResult"),requestId:r(),status:s("success"),page:he}),o({type:s("getPageResult"),requestId:r(),status:s("error"),error:Pn})]);var jn=r(),Bn=o({code:jn,message:r(),isRetryable:h()}),At=o({type:s("getUser"),requestId:r(),userId:Ye}),Nt=d("status",[o({type:s("getUserResult"),requestId:r(),status:s("success"),user:le}),o({type:s("getUserResult"),requestId:r(),status:s("error"),error:Bn})]);var Rn=d("type",[o({type:s("emoji"),emoji:r()}),o({type:s("external"),url:r()})]),Mn=o({name:r(),description:u(r()),type:kt}),Dn=o({name:r(),description:u(r()),icon:u(Rn),properties:u(N(r(),Mn),{})}),me=o({version:s(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(o({type:s("emoji"),emoji:r()})),dataSources:u(N(r(),Dn),{})});var ge=w(["light","dark"]);var wn=r(),Tn=o({code:wn,message:r(),isRetryable:h()});var qe=d("status",[o({type:s("init"),initializationId:r(),status:s("success"),theme:ge,contrastMode:de,blockId:ue,parent:ce,page:ve,manifest:me,dataSources:o({bindings:fe}),currentUser:le}),o({type:s("init"),initializationId:r(),status:s("error"),error:Tn})]);var Ut=o({type:s("invalidSandboxMessage"),reason:r()});var qn=r(),An=o({code:qn,message:r(),isRetryable:h()}),Ft=o({type:s("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(C())}),zt=d("status",[o({type:s("listUsersResult"),requestId:r(),status:s("success"),list:Mt}),o({type:s("listUsersResult"),requestId:r(),status:s("error"),error:An})]);var Nn=r(),Un=o({code:Nn,message:r(),isRetryable:h()}),Ht=o({type:s("openExternalUrl"),requestId:r(),url:r()}),Lt=d("status",[o({type:s("openExternalUrlResult"),requestId:r(),status:s("success")}),o({type:s("openExternalUrlResult"),requestId:r(),status:s("error"),error:Un})]);var Fn=w(["side_peek","center_peek"]),zn=r(),Hn=o({code:zn,message:r(),isRetryable:h()}),Vt=o({type:s("openPage"),requestId:r(),pageId:q,mode:Fn}),Gt=d("status",[o({type:s("openPageResult"),requestId:r(),status:s("success"),pageId:q}),o({type:s("openPageResult"),requestId:r(),status:s("error"),error:Hn})]);var $t=o({type:s("pageChanged"),page:ve});var Qt=o({type:s("parentChanged"),parent:ce});var Xt=o({unit:w(["year","month","week","day"]),value:C(),time:r(),defaultTimeZone:u(r())}),Ln=o({unit:w(["hour","minute"]),value:C()}),Wt=o({unit:s("none")}),Vn=x([Xt,Ln]),Jt=u(x([Xt,Wt])),Kt=u(x([Vn,Wt])),Gn=o({type:s("date"),start_date:r(),reminder:Jt}),$n=o({type:s("daterange"),start_date:r(),end_date:r(),reminder:Jt}),Qn=o({type:s("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:Kt}),Xn=o({type:s("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:Kt}),Yt=d("type",[Gn,$n,Qn,Xn]);var Zt=x([r(),C(),h(),Yt,O(r()),O(Te)]);var er=o({id:q,is_archived:h(),in_trash:h(),propertiesById:N(r(),u(Zt))}),Ze=o({id:q,is_archived:h(),in_trash:h(),properties:N(r(),u(Ke))});var Wn=r(),tr=o({code:Wn,message:r(),isRetryable:h()}),rr=d("status",[o({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("success"),items:O(Ze),hasMore:h()}),o({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("error"),error:tr})]),nr=d("status",[o({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("success"),items:O(x([Ze,er])),hasMore:h()}),o({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("error"),error:tr})]);var or=o({type:s("themeChanged"),theme:ge});var Jn=r(),Kn=o({code:Jn,message:r(),isRetryable:h()}),sr=d("status",[o({type:s("updatePageResult"),requestId:r(),status:s("success"),page:he}),o({type:s("updatePageResult"),requestId:r(),status:s("error"),error:Kn})]);var ir=d("type",[qe,or,Et,Qt,$t,Dt,wt,Rt,qt,Nt,zt,Gt,Lt,sr,Ut]),ar=d("type",[...ir.options,rr]),si=d("type",[...ir.options,nr]);function ur(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function cr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function et(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function tt(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:n}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${n}.`,isRetryable:!1}}function rt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function lr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function pr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function fr(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function mr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function yr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function dr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Ee(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function ne(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function nt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Yn=5e3,Zn=5e3,eo=5e3;function vr(e){let{prepareInit:t,sendInitMessage:n,warn:i,flushPendingHostStateChanges:l,minBridgeProtocolVersion:c,noConnectTimeoutMs:p=Yn,initialStateTimeoutMs:y=Zn,noInitResultTimeoutMs:m=eo,stopHostWithFailure:I,onInitResult:_,onConnectionFailure:E}=e,S="waitingForConnect",U,V,F,B,Y=!1,ee=!1;function W(){U!==void 0&&(window.clearTimeout(U),U=void 0)}function ie(){V!==void 0&&(window.clearTimeout(V),V=void 0)}function G(){F!==void 0&&(window.clearTimeout(F),F=void 0)}function R(g){let{initializationId:k,error:$,phase:te,source:T}=g;switch(S){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return ne(S)}S="error",B=k,W(),ie(),n({type:"init",initializationId:k,status:"error",error:$}),E?.({...$,phase:te,source:T})}async function z(g){if(S==="waitingForConnect"){S="preparingInit",B=g.initializationId,W(),V=window.setTimeout(()=>{if(S!=="preparingInit")return;let k=lr();i({...k,initializationId:g.initializationId}),R({initializationId:g.initializationId,error:k,phase:"init",source:"host"})},y);try{let k=await t(g);if(S!=="preparingInit")return;if(ie(),k.status==="error"){R({initializationId:g.initializationId,error:k.error,phase:"init",source:"host"});return}S="waitingForInitResult";let $={type:"init",initializationId:g.initializationId,status:"success",theme:k.initialState.theme,contrastMode:k.initialState.contrastMode??Ct,blockId:k.initialState.blockId,parent:k.initialState.parent,page:k.initialState.page,currentUser:k.initialState.currentUser,manifest:k.initialState.manifest,dataSources:k.initialState.dataSources};n($),F=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let te=yr();E?.({...te,phase:"initResult",source:"host"}),i({...te,initializationId:g.initializationId})},m)}catch(k){if(S!=="preparingInit")return;i({message:"Failed to prepare custom block initialization",error:k}),R({initializationId:g.initializationId,error:Ee(),phase:"init",source:"host"})}}}function J(g){if(S!=="stopped"&&S==="waitingForConnect"){if(!nt(g.bridgeProtocolVersion)){let k=et({currentBridgeProtocolVersion:g.bridgeProtocolVersion});R({initializationId:g.initializationId,error:k,phase:"connect",source:"host"});return}if(g.bridgeProtocolVersion<c){let k=tt({currentBridgeProtocolVersion:g.bridgeProtocolVersion,minBridgeProtocolVersion:c});R({initializationId:g.initializationId,error:k,phase:"connect",source:"host"});return}if(g.status==="error"){R({initializationId:g.initializationId,error:g.error,phase:"connect",source:"sandbox"});return}ee=!0,z(g)}}function oe(g){if(S==="stopped"||S!=="waitingForConnect")return"handled";let{initializationId:k,bridgeProtocolVersion:$}=g;if(k===void 0)return"nack";let te=g.error;return $!==void 0&&(nt($)?$<c&&(te=tt({currentBridgeProtocolVersion:$,minBridgeProtocolVersion:c})):te=et({currentBridgeProtocolVersion:$})),R({initializationId:k,error:te,phase:"connect",source:"host"}),"handled"}function M(g){let{initializationId:k,error:$}=g;S!=="waitingForInitResult"||k===void 0||k!==B||(W(),G(),S="error",i($),E?.({...$,phase:"initResult",source:"host"}))}function K(){if(S!=="stopped"){if(Y){I({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}Y=!0,W(),S==="waitingForConnect"&&(U=window.setTimeout(()=>{if(S!=="waitingForConnect")return;S="error";let g=ur();i(g),E?.({...g,phase:"connect",source:"host"})},p))}}function pe(g){if(S!=="waitingForInitResult"||g.initializationId!==B){i({message:"Ignored stale or unexpected initResult",payload:g});return}G(),S=g.status==="success"?"initialized":"error",g.status==="success"?l():E?.({...g.error,phase:"initResult",source:"sandbox"}),_?.(g)}function Re(){S="stopped",W(),ie(),G()}return{get status(){return S},get hasConnectedSandbox(){return ee},handleConnect:J,handleInitResult:pe,handleInvalidConnect:oe,handleInvalidInitResult:M,onIframeLoad:K,stop:Re}}function ot({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 hr(e){let t=new AbortController,n=()=>t.abort();e.signal.addEventListener("abort",n,{once:!0});let i=new Promise((c,p)=>{t.signal.addEventListener("abort",()=>p(t.signal.reason),{once:!0})});e.signal.aborted&&t.abort();let l=e.manifestSource==="local"?window.setTimeout(()=>{t.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let c=await Promise.race([e.manifestSource==="local"?to(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:se(me,c)}}catch(c){return e.signal.aborted||e.onError(c),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(l),e.signal.removeEventListener("abort",n)}}async function to(e,t){let n=new URL(e);if(!ot({url:n,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let i=await fetch(new URL("/manifest",n),{credentials:"omit",redirect:"error",cache:"no-store",signal:t});if(!i.ok)throw new Error(`Manifest request failed: HTTP ${i.status}.`);return i.json()}function br(e){let t={};for(let n of Object.values(e.properties))n&&(t[n.id]=no(n));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:t}}function gr(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let n=t.text;return n&&typeof n=="object"&&"content"in n&&typeof n.content=="string"?n.content:""}).join("")}function st(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 ro(e){let t=e.start.includes("T")||e.time_zone!=null,n=e.start.match(/([+-])(\d{2}):(\d{2})$/),i=n?(Number(n[2])*60+Number(n[3]))*(n[1]==="-"?-1:1):0,l=m=>{if(!m.includes("T"))return{date:m,time:"00:00"};let I=m.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(I)return{date:I[1],time:I[2]};if(!e.time_zone){let S=new Date(new Date(m).getTime()+i*6e4).toISOString();return{date:S.slice(0,10),time:S.slice(11,16)}}let _=new Intl.DateTimeFormat("en-CA",{timeZone:e.time_zone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(m)),E=S=>_.find(U=>U.type===S)?.value;return{date:`${E("year")}-${E("month")}-${E("day")}`,time:`${E("hour")}:${E("minute")}`}},c=l(e.start),p=e.end?l(e.end):void 0;if(!t)return p?{type:"daterange",start_date:c.date,end_date:p.date}:{type:"date",start_date:c.date};let y=e.time_zone??(i===0?"UTC":`UTC${i<0?"-":"+"}${Math.floor(Math.abs(i)/60)}${Math.abs(i)%60===0?"":`:${String(Math.abs(i)%60).padStart(2,"0")}`}`);return p?{type:"datetimerange",start_date:c.date,start_time:c.time,end_date:p.date,end_time:p.time,time_zone:y}:{type:"datetime",start_date:c.date,start_time:c.time,time_zone:y}}function no(e){switch(e.type){case"title":return gr(e.title);case"rich_text":return gr(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?ro(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"place":return"";case"created_time":return st(e.created_time);case"last_edited_time":return st(e.last_edited_time);case"last_visited_time":return st(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 ne(e)}}function Sr(e,t){return t<6&&e.type==="queryDataSourceResult"&&e.status==="success"?{...e,items:e.items.map(n=>"properties"in n?br(n):n)}:e}function kr(e,t){return Sr(e,t)}var Ir=o({theme:ge,contrastMode:u(de),blockId:ue,parent:ce,page:ve,manifest:me,dataSources:o({bindings:fe}),currentUser:le});function _r(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 xr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Cr=o({code:r(),message:r(),isRetryable:h()});var Er={type:s("connect"),initializationId:r(),bridgeProtocolVersion:C(),sdkVersion:r()},Or=d("status",[o({status:s("success"),manifest:u(me),...Er}),o({status:s("error"),error:Cr,...Er})]);var oo=d("type",[o({type:s("start")}),o({type:s("end")}),o({type:s("before"),blockId:ue}),o({type:s("after"),blockId:ue})]),so=d("type",[o({type:s("page_id"),page_id:q}),o({type:s("data_source_id"),data_source_id:re})]),Pr=o({type:s("createPage"),requestId:r(),parent:so,properties:Ce,position:u(oo)});var io=r(),ao=o({code:io,message:r(),isRetryable:h()}),jr=d("status",[o({type:s("initResult"),initializationId:r(),status:s("success"),initialHeight:u(H(C(),Se(),Ie(0)))}),o({type:s("initResult"),initializationId:r(),status:s("error"),error:ao})]);var Br=o({type:s("invalidHostMessage"),reason:r()});var Rr=w(["ascending","descending"]);var Mr=H(q,Le(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Ve(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),it=x([f({contains:Mr}),f({does_not_contain:Mr})]),Be=x([f({is_empty:s(!0)}),f({is_not_empty:s(!0)})]),je=x([r(),O(r())]),Dr=f({object:w(["user","group"]),id:H(r(),ke(1))}),uo=x([f({contains:Dr}),f({does_not_contain:Dr}),Be]),wr=f({object:s("user"),id:H(r(),ke(1),De(2e3))}),co=x([f({contains:wr}),f({does_not_contain:wr}),f({is_empty:s(!0)}),f({is_not_empty:s(!0)})]),Oe=x([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),Be]),lo=x([f({equals:C()}),f({does_not_equal:C()}),f({greater_than:C()}),f({less_than:C()}),f({greater_than_or_equal_to:C()}),f({less_than_or_equal_to:C()}),Be]),po=x([f({equals:h()}),f({does_not_equal:h()})]),Nr=x([f({equals:je}),f({does_not_equal:je}),Be]),Tr=w(["To-do","In progress","Complete","Current","Future"]),qr=x([Tr,H(O(Tr),ke(1),De(5))]),fo=x([f({group_equals:qr}),f({group_does_not_equal:qr})]),mo=x([Nr,fo]),yo=x([f({contains:je}),f({contains_all:je}),f({does_not_contain:je}),Be]),X=w(["start_date","end_date"]),vo=w(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Pe=x([vo,r()]),ho=x([f({target:u(X),equals:Pe}),f({target:u(X),before:Pe}),f({target:u(X),after:Pe}),f({target:u(X),on_or_before:Pe}),f({target:u(X),on_or_after:Pe}),f({target:u(X),this_week:f({})}),f({target:u(X),past_week:f({})}),f({target:u(X),past_month:f({})}),f({target:u(X),past_year:f({})}),f({target:u(X),next_week:f({})}),f({target:u(X),next_month:f({})}),f({target:u(X),next_year:f({})}),f({target:u(X),is_empty:s(!0)}),f({target:u(X),is_not_empty:s(!0)})]),Ar=x([f({propertyId:r(),relation:it}),f({propertyId:r(),created_by:co}),f({propertyId:r(),title:Oe}),f({propertyId:r(),rich_text:Oe}),f({propertyId:r(),url:Oe}),f({propertyId:r(),email:Oe}),f({propertyId:r(),phone_number:Oe}),f({propertyId:r(),number:lo}),f({propertyId:r(),checkbox:po}),f({propertyId:r(),select:Nr}),f({propertyId:r(),multi_select:yo}),f({propertyId:r(),status:mo}),f({propertyId:r(),date:ho}),f({propertyId:r(),people:uo})]),go=x([Ar,f({and:O(Ar)})]),at=10,bo=f({propertyId:r(),direction:Rr}),Ur=o({type:s("queryDataSource"),subscriptionId:r(),dataSourceId:re,limit:C(),filter:u(go),sorts:u(O(bo))});var Fr=o({type:s("resize"),height:H(C(),Se(),Ie(0))});var zr=o({type:s("unsubscribeDataSourceQuery"),subscriptionId:r()});var Hr=o({type:s("updatePage"),requestId:r(),pageId:q,properties:u(Ce),icon:u(We),cover:u(Je),archived:u(h())});var Lr=d("type",[Or,jr,Ur,zr,Pr,Tt,At,Ft,Vt,Ht,Hr,Fr,Br]);function Vr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Gr(e){let t=Vr(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:So(t)}}}function So(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var $r=o({initializationId:r()}),ko=o({bridgeProtocolVersion:x([C(),Ge()])});function Qr(e){let{iframe:t,sandboxOrigin:n,getInitStatus:i,emit:l,sendNack:c,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:I,onQueryDataSource:_,onUnsubscribeDataSourceQuery:E,onCreatePage:S,onGetPage:U,onOpenPage:V,onOpenExternalUrl:F,onGetUser:B,onListUsers:Y,onUpdatePage:ee,onResize:W}=e;function ie(G,R){l("warn",{message:"Ignored unsupported sandbox message",payload:ut(G),issues:R});let z=Gr(G);if(z.incomingType==="connect"){let J=xe($r,G),oe=xe(ko,G);if(p({initializationId:J.success?J.output.initializationId:void 0,error:cr(),bridgeProtocolVersion:oe.success?oe.output.bridgeProtocolVersion:void 0})==="handled")return}if(z.incomingType==="initResult"){let J=xe($r,G);y({initializationId:J.success?J.output.initializationId:void 0,error:dr()})}z.nack!==void 0&&i()!=="stopped"&&c(z.nack)}return function(R){let z=R.source===t.contentWindow,J=R.origin===n;if(!z||!J)return;let oe=xe(Lr,R.data);if(!oe.success){ie(R.data,oe.issues);return}let M=oe.output;if(!xr(M)&&i()!=="initialized"){l("warn",{message:`Ignored ${M.type} before initialization completed`,payload:ut(M)});return}switch(l("in",ut(M)),M.type){case"connect":m(M);return;case"initResult":I(M);return;case"queryDataSource":_(M);return;case"unsubscribeDataSourceQuery":E(M);return;case"createPage":S(M);return;case"openPage":V(M);return;case"openExternalUrl":F(M);return;case"getPage":U(M);return;case"getUser":B(M);return;case"listUsers":Y(M);return;case"updatePage":ee(M);return;case"resize":W(M);return;case"invalidHostMessage":return;default:ne(M)}}}function ut(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ae=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let n={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:n,isRefreshing:!0,shouldRefreshAgain:!1}),n}isCurrent(t,n){return this.bySubscriptionId.get(t)?.token===n}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let n=[],i=!1;for(let l of this.bySubscriptionId.values())if(l.message.dataSourceId===t){if(i=!0,l.isRefreshing){l.shouldRefreshAgain=!0;continue}l.isRefreshing=!0,n.push({message:l.message,token:l.token})}return i?n:void 0}finish(t,n){let i=this.bySubscriptionId.get(t);if(i?.token===n&&(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 Xr(e,t){if(e===void 0)return;let n="and"in e?e.and:[e];for(let i of n){let l=Io(i,t);if(l!==void 0)return l}}function Io(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 n=t.propertiesById[e.propertyId],i=Object.keys(e).find(y=>y!=="propertyId");if(i!==n.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${i}" does not match property type "${n.type}".`,isRetryable:!1};if("status"in e&&n.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(E=>!n.groups.some(S=>S.name===E));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!ht(it,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let l=_o(e);if(l===void 0||n.type!==l.propertyType)return;let c=new Set(n.options.map(y=>y.name)),p=xo(l.operator).find(y=>!c.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function _o(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let t=e.status;return"group_equals"in t||"group_does_not_equal"in t?void 0:{propertyType:"status",operator:t}}}function xo(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?[]:ne(e);return Array.isArray(t)?t:[t]}var Co=new Set(It);function Wr(e,t){if(e===void 0)return;if(e.length>at)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${at} entries.`,isRetryable:!1};let n=new Set;for(let i of e){if(n.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(n.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 l=t.propertiesById[i.propertyId];if(!Co.has(l.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${l.type}".`,isRetryable:!1}}}var Kr=5;function Eo(e){let{iframe:t,prepareInitialState:n,handlers:i,onInitialized:l,onConnectionFailure:c,onLog:p,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:I,noConnectTimeoutMs:_,initialStateTimeoutMs:E,noInitResultTimeoutMs:S}=e,U=Math.max(I??3,3),V=new AbortController,F,B={},Y=!1,ee=new AbortController,W,ie,G=6,R=new Ae(a=>{y?.(a)});function z(a,b){p?.(a,b)}function J(a){let b=T.status;switch(b){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return ne(b)}let P=kr(a,G);z("out",P),t.contentWindow?.postMessage(P,m)}function oe(a){J(se(qe,a))}function M(a){J(a)}function K(a){let b=T.status;switch(b){case"initialized":J(se(ar,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:ne(b)}}async function pe(a,b){if(b===void 0)return;let P=await b(a);K({type:`${a.type}Result`,requestId:a.requestId,...P})}function Re(a){let b=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};K(b)}async function g(a,b=R.subscribe(a)){try{let P=Oo(ie,a.dataSourceId),ye=Po(a,P);if(ye!==void 0){R.isCurrent(a.subscriptionId,b)&&(R.unsubscribe(a.subscriptionId),Re({subscriptionId:a.subscriptionId,response:{status:"error",error:ye}}));return}let Ne=await i.queryDataSource(a);if(!R.isCurrent(a.subscriptionId,b))return;Ne.status==="error"&&!Ne.error.isRetryable&&R.unsubscribe(a.subscriptionId),Re({subscriptionId:a.subscriptionId,response:Ne})}finally{let P=R.finish(a.subscriptionId,b);P!==void 0&&g(P.message,P.token)}}function k(a){T.status==="stopped"||T.status==="error"||(Object.assign(B,a),te())}async function $(a){if(i.openExternalUrl===void 0||V.signal.aborted||F===a.requestId)return;if(F!==void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};K(P);return}let b=_r(a.url);if(b===void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};K(P);return}F=a.requestId;try{let P=await i.openExternalUrl({...a,url:b},{signal:V.signal});if(V.signal.aborted)return;let ye={type:"openExternalUrlResult",requestId:a.requestId,...P};K(ye)}catch(P){if(!V.signal.aborted)throw P}finally{F===a.requestId&&(F=void 0)}}function te(){if(T.status!=="initialized")return;let a=B;B={},a.theme!==void 0&&K({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&K({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&K({type:"parentChanged",parent:a.parent}),a.page!==void 0&&K({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&K({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&K({type:"currentUserChanged",currentUser:a.currentUser})}let T=vr({async prepareInit(a){G=a.bridgeProtocolVersion;let b=await en;return T.status!=="preparingInit"?b:Zr(b)},sendInitMessage:oe,warn:a=>z("warn",a),flushPendingHostStateChanges:te,minBridgeProtocolVersion:U,noConnectTimeoutMs:_,initialStateTimeoutMs:E,noInitResultTimeoutMs:S,stopHostWithFailure:pt,onInitResult(a){a.status==="success"&&W!==void 0&&l?.({manifest:W,initialHeight:a.initialHeight})},onConnectionFailure:a=>{ee.abort(),c?.(a)}});function Zr(a){if(a.status==="error")return a;let b=se(Ir,{...a.initialState,...B});if(W=b.manifest,B={},G<Kr&&b.page.type==="unavailable")return{status:"error",error:rt()};let P=Yr(b.manifest,b.dataSources);return P!==void 0?{status:"error",error:P}:(ie=b.dataSources,Y=!0,{status:"success",initialState:b})}let en=tn().catch(a=>(ee.signal.aborted||z("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Ee()}));async function tn(){let a=await hr({...e,sandboxOrigin:m,signal:ee.signal,onError:P=>{z("warn",{message:"Failed to load custom block manifest",error:P})}});if(a.status==="error")return a;if(ee.signal.aborted)return{status:"error",error:Ee()};let b=await n({manifest:a.manifest,signal:ee.signal});return b.status==="error"?b:{status:"success",initialState:{...b.initialState,manifest:a.manifest}}}let ct=Qr({iframe:t,sandboxOrigin:m,getInitStatus:()=>T.status,emit:z,sendNack:M,onInvalidConnect:T.handleInvalidConnect,onInvalidInitResult:T.handleInvalidInitResult,onConnect:T.handleConnect,onInitResult:T.handleInitResult,onQueryDataSource:g,onUnsubscribeDataSourceQuery:a=>R.unsubscribe(a.subscriptionId),onOpenExternalUrl:$,onCreatePage:a=>pe(a,i.createPage),onGetPage:a=>pe(a,i.getPage),onOpenPage:a=>pe(a,i.openPage),onGetUser:a=>pe(a,i.getUser),onListUsers:a=>pe(a,i.listUsers),onUpdatePage:a=>pe(a,i.updatePage),onResize:a=>i.resize?.(a)});window.addEventListener("message",ct),t.addEventListener("load",T.onIframeLoad);function lt(){V.abort(),ee.abort(),window.removeEventListener("message",ct),t.removeEventListener("load",T.onIframeLoad),T.stop(),R.unsubscribeAll()}function pt(a){lt(),z("warn",a),c?.(a)}return{stop:lt,setTheme(a){k({theme:a})},setContrastMode(a){k({contrastMode:a})},setParent(a){k({parent:a})},setPage(a){if(a.type==="unavailable"&&G<Kr&&(T.status==="preparingInit"&&Y||T.status==="waitingForInitResult"||T.status==="initialized")){pt({...rt(),phase:"runtime",source:"host"});return}k({page:a})},setCurrentUser(a){k({currentUser:a})},setDataSources(a){let b={bindings:se(fe,a.bindings)};if(T.hasConnectedSandbox&&W!==void 0&&Yr(W,b)!==void 0){z("warn",{message:"Ignored invalid data source bindings update",payload:b});return}ie=b,k({dataSources:b})},refreshQuery({dataSourceId:a}){if(T.status!=="initialized")return;let b=se(re,a),P=R.refresh(b);if(P===void 0){z("warn",`No active query exists for data source "${a}"`);return}for(let ye of P)g(ye.message,ye.token)}}}function Oo(e,t){return Object.values(e?.bindings??{}).find(n=>n.collectionPointer?.id===t)?.collectionSchema}function Yr(e,t){for(let[n,i]of Object.entries(e.dataSources)){let l=t.bindings[n];if(l?.collectionPointer===void 0||l.collectionSchema===void 0)return pr();for(let[c,p]of Object.entries(i.properties??{})){let y=l.propertyIdsByKey?.[c];if(y===void 0)return fr();if(l.collectionSchema.propertiesById[y]?.type!==p.type)return mr()}}}function Po(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}:Xr(e.filter,t)??Wr(e.sorts,t)}function jo(e){return se(q,e)}export{Ue as LATEST_BRIDGE_PROTOCOL_VERSION,Fe as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,Eo as createCustomBlockHost,rn as getAutoBoundPropertyIdsByKey,ot as isLocalCustomBlockUrl,jo as toNotionPageId};
@@ -1 +1 @@
1
- {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AAI5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAgBvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAA;AAEpF,OAAO,KAAK,EACX,iCAAiC,EAIjC,kCAAkC,EAClC,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,qBAAqB,CAAA;AAe5B,MAAM,MAAM,sBAAsB,GAAG,8BAA8B,GAAG;IACrE,MAAM,EAAE,iBAAiB,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,EAAE,uBAAuB,CAAA;IACjC,gGAAgG;IAChG,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACvB,QAAQ,EAAE,mBAAmB,CAAA;QAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;KACtB,KAAK,IAAI,CAAA;IACV;;;;;OAKG;IACH,mBAAmB,EAAE,CAAC,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IAC1E,+FAA+F;IAC/F,mBAAmB,EAAE,CAAC,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IACnE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1E,iFAAiF;IACjF,mBAAmB,EAAE,kCAAkC,CAAA;IACvD,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAC/D,eAAe,EAAE,CAChB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,KACrD,IAAI,CAAA;IACT,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,KAAK,IAAI,CAAA;IAClE,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,KAAK,IAAI,CAAA;IACjE,cAAc,EAAE,CAAC,WAAW,EAAE,iCAAiC,KAAK,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,KAAK,IAAI,CAAA;IAC1E,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;KACzD,KAAK,IAAI,CAAA;CACV,CAAA;AAQD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CA0bvB"}
1
+ {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AAI5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAoBvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAA;AAEpF,OAAO,KAAK,EACX,iCAAiC,EAIjC,kCAAkC,EAClC,MAAM,sBAAsB,CAAA;AAI7B,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,qBAAqB,CAAA;AAe5B,MAAM,MAAM,sBAAsB,GAAG,8BAA8B,GAAG;IACrE,MAAM,EAAE,iBAAiB,CAAA;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,EAAE,uBAAuB,CAAA;IACjC,gGAAgG;IAChG,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACvB,QAAQ,EAAE,mBAAmB,CAAA;QAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;KACtB,KAAK,IAAI,CAAA;IACV;;;;;OAKG;IACH,mBAAmB,EAAE,CAAC,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IAC1E,+FAA+F;IAC/F,mBAAmB,EAAE,CAAC,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IACnE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1E,iFAAiF;IACjF,mBAAmB,EAAE,kCAAkC,CAAA;IACvD,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAC/D,eAAe,EAAE,CAChB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,KACrD,IAAI,CAAA;IACT,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,KAAK,IAAI,CAAA;IAClE,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,KAAK,IAAI,CAAA;IACjE,cAAc,EAAE,CAAC,WAAW,EAAE,iCAAiC,KAAK,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,KAAK,IAAI,CAAA;IAC1E,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;KACzD,KAAK,IAAI,CAAA;CACV,CAAA;AAQD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CAmgBvB"}
@@ -9,6 +9,7 @@ import { createInitializationController } from "./lifecycle/initializationContro
9
9
  import { loadCustomBlockManifest } from "./lifecycle/loadCustomBlockManifest.js";
10
10
  import { normalizeHostToSandboxMessage } from "./lifecycle/normalizeHostToSandboxMessage.js";
11
11
  import { customBlockHostInitialStateSchema } from "./lifecycle/types.js";
12
+ import { parseExternalUrl } from "./messages/parseExternalUrl.js";
12
13
  import { createSandboxMessageRouter } from "./messages/sandboxMessageRouter.js";
13
14
  import { MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION } from "./protocolVersion.js";
14
15
  import { QuerySubscriptions, } from "./queries/querySubscriptions.js";
@@ -24,6 +25,8 @@ export function createCustomBlockHost(options) {
24
25
  // the runtime no longer implements. Omission uses the runtime minimum.
25
26
  const minBridgeProtocolVersion = Math.max(configuredMinBridgeProtocolVersion ??
26
27
  MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION, MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION);
28
+ const navigationAbortController = new AbortController();
29
+ let pendingOpenExternalUrlRequestId;
27
30
  let pendingState = {};
28
31
  let hasPreparedInitialState = false;
29
32
  const preparationController = new AbortController();
@@ -152,6 +155,69 @@ export function createCustomBlockHost(options) {
152
155
  Object.assign(pendingState, update);
153
156
  flushPendingHostStateChanges();
154
157
  }
158
+ async function handleOpenExternalUrl(message) {
159
+ if (handlers.openExternalUrl === undefined ||
160
+ navigationAbortController.signal.aborted) {
161
+ return;
162
+ }
163
+ if (pendingOpenExternalUrlRequestId === message.requestId) {
164
+ return;
165
+ }
166
+ if (pendingOpenExternalUrlRequestId !== undefined) {
167
+ const pendingResult = {
168
+ type: "openExternalUrlResult",
169
+ requestId: message.requestId,
170
+ status: "error",
171
+ error: {
172
+ code: "pending_navigation",
173
+ message: "Another external navigation request is pending.",
174
+ isRetryable: true,
175
+ },
176
+ };
177
+ sendInitializedMessage(pendingResult);
178
+ return;
179
+ }
180
+ const url = parseExternalUrl(message.url);
181
+ if (url === undefined) {
182
+ const invalidResult = {
183
+ type: "openExternalUrlResult",
184
+ requestId: message.requestId,
185
+ status: "error",
186
+ error: {
187
+ code: "invalid_url",
188
+ message: "Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",
189
+ isRetryable: false,
190
+ },
191
+ };
192
+ sendInitializedMessage(invalidResult);
193
+ return;
194
+ }
195
+ pendingOpenExternalUrlRequestId = message.requestId;
196
+ try {
197
+ const response = await handlers.openExternalUrl({ ...message, url }, {
198
+ signal: navigationAbortController.signal,
199
+ });
200
+ if (navigationAbortController.signal.aborted) {
201
+ return;
202
+ }
203
+ const result = {
204
+ type: "openExternalUrlResult",
205
+ requestId: message.requestId,
206
+ ...response,
207
+ };
208
+ sendInitializedMessage(result);
209
+ }
210
+ catch (error) {
211
+ if (!navigationAbortController.signal.aborted) {
212
+ throw error;
213
+ }
214
+ }
215
+ finally {
216
+ if (pendingOpenExternalUrlRequestId === message.requestId) {
217
+ pendingOpenExternalUrlRequestId = undefined;
218
+ }
219
+ }
220
+ }
155
221
  function flushPendingHostStateChanges() {
156
222
  // Keep updates queued until the sandbox acknowledges initialization.
157
223
  // Updates received before init is sent are included in its payload instead.
@@ -295,6 +361,7 @@ export function createCustomBlockHost(options) {
295
361
  onInitResult: initializationController.handleInitResult,
296
362
  onQueryDataSource: handleQuery,
297
363
  onUnsubscribeDataSourceQuery: message => querySubscriptions.unsubscribe(message.subscriptionId),
364
+ onOpenExternalUrl: handleOpenExternalUrl,
298
365
  onCreatePage: message => respondToRequest(message, handlers.createPage),
299
366
  onGetPage: message => respondToRequest(message, handlers.getPage),
300
367
  onOpenPage: message => respondToRequest(message, handlers.openPage),
@@ -306,6 +373,7 @@ export function createCustomBlockHost(options) {
306
373
  window.addEventListener("message", onMessage);
307
374
  iframe.addEventListener("load", initializationController.onIframeLoad);
308
375
  function stop() {
376
+ navigationAbortController.abort();
309
377
  preparationController.abort();
310
378
  window.removeEventListener("message", onMessage);
311
379
  iframe.removeEventListener("load", initializationController.onIframeLoad);
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export type { CreatePageMessage } from "./protocol/messages/createPage.js";
7
7
  export type { GetPageMessage } from "./protocol/messages/getPage.js";
8
8
  export type { GetUserMessage } from "./protocol/messages/getUser.js";
9
9
  export type { ListUsersMessage } from "./protocol/messages/listUsers.js";
10
+ export type { OpenExternalUrlMessage } from "./protocol/messages/openExternalUrl.js";
10
11
  export type { OpenPageMessage } from "./protocol/messages/openPage.js";
11
12
  export type { CustomBlockCheckboxFilterOperator, CustomBlockContainsFilterOperator, CustomBlockCreatedByFilterOperator, CustomBlockDateFilterOperator, CustomBlockNumberFilterOperator, CustomBlockOptionFilterOperator, CustomBlockPeopleFilterOperator, CustomBlockPersonFilterValue, CustomBlockRelationFilterOperator, CustomBlockStatusFilterOperator, CustomBlockStatusGroupFilterOperator, CustomBlockStatusGroupName, CustomBlockTextFilterOperator, QueryDataSourceMessage, ResolvedCustomBlockDataSourceFilter, ResolvedCustomBlockDataSourcePropertyFilter, ResolvedCustomBlockDataSourceSort, } from "./protocol/messages/queryDataSource.js";
12
13
  export type { ResizeMessage } from "./protocol/messages/resize.js";
@@ -19,6 +20,6 @@ export { toNotionPageId } from "./ids.js";
19
20
  export type { CustomBlockHostManifestOptions } from "./lifecycle/manifestOptions.js";
20
21
  export type { ConnectSuccessMessage, CustomBlockHostDataSourcesPayload, CustomBlockHostInitialState, CustomBlockHostInitialStateResult, CustomBlockHostPreparedStateResult, CustomBlockHostPrepareInitialState, } from "./lifecycle/types.js";
21
22
  export { isLocalCustomBlockUrl } from "./localBlockUrl.js";
22
- export type { CreatePageMessageInput, CustomBlockHostCreatePageResult, CustomBlockHostFailure, CustomBlockHostGetPageResult, CustomBlockHostGetUserResult, CustomBlockHostHandlers, CustomBlockHostListUsersResult, CustomBlockHostLogDirection, CustomBlockHostOpenPageResult, CustomBlockHostUpdatePageResult, GetPageMessageInput, GetUserMessageInput, ListUsersMessageInput, OpenPageMessageInput, QueryDataSourceMessageInput, ResizeMessageInput, UpdatePageMessageInput, } from "./messages/types.js";
23
+ export type { CreatePageMessageInput, CustomBlockHostCreatePageResult, CustomBlockHostFailure, CustomBlockHostGetPageResult, CustomBlockHostGetUserResult, CustomBlockHostHandlers, CustomBlockHostListUsersResult, CustomBlockHostLogDirection, CustomBlockHostNavigationContext, CustomBlockHostOpenExternalUrlResult, CustomBlockHostOpenPageResult, CustomBlockHostUpdatePageResult, GetPageMessageInput, GetUserMessageInput, ListUsersMessageInput, OpenExternalUrlMessageInput, OpenPageMessageInput, QueryDataSourceMessageInput, ResizeMessageInput, UpdatePageMessageInput, } from "./messages/types.js";
23
24
  export type { CustomBlockHostQueryDataSourceResult } from "./queries/types.js";
24
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,gCAAgC,EAChC,0BAA0B,GAC1B,MAAM,gEAAgE,CAAA;AACvE,YAAY,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAA;AAC/G,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAA;AAC9F,YAAY,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,YAAY,EACX,iCAAiC,EACjC,iCAAiC,EACjC,kCAAkC,EAClC,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,EAC5B,iCAAiC,EACjC,+BAA+B,EAC/B,oCAAoC,EACpC,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,mCAAmC,EACnC,2CAA2C,EAC3C,iCAAiC,GACjC,MAAM,8DAA8D,CAAA;AACrE,YAAY,EAAE,aAAa,EAAE,MAAM,qDAAqD,CAAA;AACxF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,gDAAgD,CAAA;AACvD,OAAO,EACN,8BAA8B,EAC9B,sCAAsC,GACtC,MAAM,qDAAqD,CAAA;AAC5D,OAAO,EACN,KAAK,oBAAoB,EACzB,4BAA4B,GAC5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,qBAAqB,GACrB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,YAAY,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAA;AACpF,YAAY,EACX,qBAAqB,EACrB,iCAAiC,EACjC,2BAA2B,EAC3B,iCAAiC,EACjC,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EACX,sBAAsB,EACtB,+BAA+B,EAC/B,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,8BAA8B,EAC9B,2BAA2B,EAC3B,6BAA6B,EAC7B,+BAA+B,EAC/B,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,gCAAgC,EAChC,0BAA0B,GAC1B,MAAM,gEAAgE,CAAA;AACvE,YAAY,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAA;AAC/G,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAA;AAC9F,YAAY,EAAE,sBAAsB,EAAE,MAAM,8DAA8D,CAAA;AAC1G,YAAY,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,YAAY,EACX,iCAAiC,EACjC,iCAAiC,EACjC,kCAAkC,EAClC,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,EAC5B,iCAAiC,EACjC,+BAA+B,EAC/B,oCAAoC,EACpC,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,mCAAmC,EACnC,2CAA2C,EAC3C,iCAAiC,GACjC,MAAM,8DAA8D,CAAA;AACrE,YAAY,EAAE,aAAa,EAAE,MAAM,qDAAqD,CAAA;AACxF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,gDAAgD,CAAA;AACvD,OAAO,EACN,8BAA8B,EAC9B,sCAAsC,GACtC,MAAM,qDAAqD,CAAA;AAC5D,OAAO,EACN,KAAK,oBAAoB,EACzB,4BAA4B,GAC5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,qBAAqB,GACrB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,YAAY,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAA;AACpF,YAAY,EACX,qBAAqB,EACrB,iCAAiC,EACjC,2BAA2B,EAC3B,iCAAiC,EACjC,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EACX,sBAAsB,EACtB,+BAA+B,EAC/B,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,8BAA8B,EAC9B,2BAA2B,EAC3B,gCAAgC,EAChC,oCAAoC,EACpC,6BAA6B,EAC7B,+BAA+B,EAC/B,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,EAC3B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,68 @@
1
+ import type { NotionDataSourcePageBridge } from "../protocol/dataSources/dataSourcePage.js";
2
+ export declare function toLegacyQueryPage(page: NotionDataSourcePageBridge): {
3
+ id: string & import("valibot").Brand<"NotionPageId">;
4
+ is_archived: boolean;
5
+ in_trash: boolean;
6
+ propertiesById: Record<string, string | number | boolean | string[] | {
7
+ id: string;
8
+ table: string;
9
+ }[] | {
10
+ type: "date";
11
+ start_date: string;
12
+ reminder?: {
13
+ unit: "day" | "month" | "week" | "year";
14
+ value: number;
15
+ time: string;
16
+ defaultTimeZone?: string | undefined;
17
+ } | {
18
+ unit: "none";
19
+ } | undefined;
20
+ } | {
21
+ type: "daterange";
22
+ start_date: string;
23
+ end_date: string;
24
+ reminder?: {
25
+ unit: "day" | "month" | "week" | "year";
26
+ value: number;
27
+ time: string;
28
+ defaultTimeZone?: string | undefined;
29
+ } | {
30
+ unit: "none";
31
+ } | undefined;
32
+ } | {
33
+ type: "datetime";
34
+ start_date: string;
35
+ start_time: string;
36
+ time_zone?: string | undefined;
37
+ reminder?: {
38
+ unit: "day" | "month" | "week" | "year";
39
+ value: number;
40
+ time: string;
41
+ defaultTimeZone?: string | undefined;
42
+ } | {
43
+ unit: "hour" | "minute";
44
+ value: number;
45
+ } | {
46
+ unit: "none";
47
+ } | undefined;
48
+ } | {
49
+ type: "datetimerange";
50
+ start_date: string;
51
+ start_time: string;
52
+ end_date: string;
53
+ end_time: string;
54
+ time_zone?: string | undefined;
55
+ reminder?: {
56
+ unit: "day" | "month" | "week" | "year";
57
+ value: number;
58
+ time: string;
59
+ defaultTimeZone?: string | undefined;
60
+ } | {
61
+ unit: "hour" | "minute";
62
+ value: number;
63
+ } | {
64
+ unit: "none";
65
+ } | undefined;
66
+ } | undefined>;
67
+ };
68
+ //# sourceMappingURL=legacyPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacyPage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/legacyPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAA;AAKhH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAajE"}