@notionhq/custom-blocks-host 0.2.20 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -239
- package/dist/browser.js +1 -1
- package/dist/createCustomBlockHost.d.ts +5 -5
- package/dist/createCustomBlockHost.d.ts.map +1 -1
- package/dist/createCustomBlockHost.js +54 -15
- package/dist/ids.d.ts +3 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +5 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lifecycle/loadCustomBlockManifest.d.ts +16 -0
- package/dist/lifecycle/loadCustomBlockManifest.d.ts.map +1 -0
- package/dist/lifecycle/loadCustomBlockManifest.js +65 -0
- package/dist/lifecycle/manifestOptions.d.ts +17 -0
- package/dist/lifecycle/manifestOptions.d.ts.map +1 -0
- package/dist/lifecycle/manifestOptions.js +1 -0
- package/dist/lifecycle/types.d.ts +14 -2
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lifecycle/types.js +1 -1
- package/dist/protocol/dataSources/dataSourcePage.d.ts +160 -1
- package/dist/protocol/dataSources/dataSourcePage.js +8 -1
- package/dist/protocol/dataSources/propertySchema.d.ts +1 -0
- package/dist/protocol/messages/hostToSandbox.d.ts +159 -2
- package/dist/protocol/messages/queryDataSourceResult.d.ts +159 -2
- package/dist/protocol/messages/queryDataSourceResult.js +5 -2
- package/dist/protocol/protocolVersion.d.ts +2 -1
- package/dist/protocol/protocolVersion.js +4 -1
- package/package.json +1 -1
- package/src/createCustomBlockHost.ts +64 -23
- package/src/ids.ts +9 -0
- package/src/index.ts +12 -1
- package/src/lifecycle/loadCustomBlockManifest.ts +89 -0
- package/src/lifecycle/manifestOptions.ts +19 -0
- package/src/lifecycle/types.ts +17 -5
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function qr(e){let{manifestProperties:o,propertySchemasById:n}=e,s=[];for(let[c,l]of Object.entries(o)){let f=Tr({propertyKey:c,manifestProperty:l,propertySchemasById:n});f!==void 0&&s.push([c,f])}return Object.fromEntries(s)}function Tr(e){let{propertyKey:o,manifestProperty:n,propertySchemasById:s}=e,c=rt(n.name),l=Object.entries(s).filter(([f,y])=>y.type===n.type&&(f===o||rt(y.name)===c));return l.length===1?l[0][0]:void 0}function rt(e){return e.trim().toLowerCase()}var Re,Nr={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Ne(e){return!e&&!Re?Nr:{lang:e?.lang??Re?.lang,message:e?.message,abortEarly:e?.abortEarly??Re?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Re?.abortPipeEarly}}var Fr;function Ur(e){return Fr?.get(e)}var zr;function Hr(e){return zr?.get(e)}var Lr;function Gr(e,o){return Lr?.get(e)?.get(o)}function ge(e){let o=typeof e;return o==="string"?`"${e}"`:o==="number"||o==="bigint"||o==="boolean"?`${e}`:o==="object"||o==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":o}function j(e,o,n,s,c){let l=c&&"input"in c?c.input:n.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 ${o}: ${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},S=e.kind==="schema",I=c?.message??e.message??Gr(e.reference,m.lang)??(S?Hr(m.lang):null)??s.message??Ur(m.lang);I!==void 0&&(m.message=typeof I=="function"?I(m):I),S&&(n.typed=!1),n.issues?n.issues.push(m):n.issues=[m]}var nt=new WeakMap;function z(e){let o=nt.get(e);return o||(o={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},Ne())}},nt.set(e,o)),o}function Vr(e,o){return Object.prototype.hasOwnProperty.call(e,o)&&o!=="__proto__"&&o!=="prototype"&&o!=="constructor"}function Fe(e,o){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${o} `)})`:n[0]??"never"}var $r=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function te(e){return{kind:"transformation",type:"brand",reference:te,async:!1,name:e,"~run"(o){return o}}}function be(e){return{kind:"validation",type:"finite",reference:be,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(o,n){return o.typed&&!this.requirement(o.value)&&j(this,"finite",o,n),o}}}function Me(e,o){return{kind:"validation",type:"max_length",reference:Me,async:!1,expects:`<=${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&n.value.length>this.requirement&&j(this,"length",n,s,{received:`${n.value.length}`}),n}}}function ke(e,o){return{kind:"validation",type:"min_length",reference:ke,async:!1,expects:`>=${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&n.value.length<this.requirement&&j(this,"length",n,s,{received:`${n.value.length}`}),n}}}function Se(e,o){return{kind:"validation",type:"min_value",reference:Se,async:!1,expects:`>=${e instanceof Date?e.toJSON():ge(e)}`,requirement:e,message:o,"~run"(n,s){return n.typed&&!(n.value>=this.requirement)&&j(this,"value",n,s,{received:n.value instanceof Date?n.value.toJSON():ge(n.value)}),n}}}function Ue(e,o){return{kind:"validation",type:"regex",reference:Ue,async:!1,expects:`${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&!this.requirement.test(n.value)&&j(this,"format",n,s),n}}}function ze(e){return{kind:"transformation",type:"transform",reference:ze,async:!1,operation:e,"~run"(o){return o.value=this.operation(o.value),o}}}var it={abortEarly:!0};function st(e,o,n){return typeof e.fallback=="function"?e.fallback(o,n):e.fallback}function De(e,o,n){return typeof e.default=="function"?e.default(o,n):e.default}function ut(e,o){return!e["~run"]({value:o},it).issues}function O(e,o){return{kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(Array.isArray(c)){n.typed=!0,n.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 S of y.issues)S.path?S.path.unshift(m):S.path=[m],n.issues?.push(S);if(n.issues||(n.issues=y.issues),s.abortEarly){n.typed=!1;break}}y.typed||(n.typed=!1),n.value.push(y.value)}}else j(this,"type",n,s);return n}}}function b(e){return{kind:"schema",type:"boolean",reference:b,expects:"boolean",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="boolean"?o.typed=!0:j(this,"type",o,n),o}}}function i(e,o){return{kind:"schema",type:"literal",reference:i,expects:ge(e),async:!1,literal:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===this.literal?n.typed=!0:j(this,"type",n,s),n}}}function He(e){return{kind:"schema",type:"nan",reference:He,expects:"NaN",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return Number.isNaN(o.value)?o.typed=!0:j(this,"type",o,n),o}}}function W(e,o){return{kind:"schema",type:"nullable",reference:W,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===null&&(this.default!==void 0&&(n.value=De(this,n,s)),n.value===null)?(n.typed=!0,n):this.wrapped["~run"](n,s)}}}function E(e){return{kind:"schema",type:"number",reference:E,expects:"number",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="number"&&!isNaN(o.value)?o.typed=!0:j(this,"type",o,n),o}}}function r(e,o){return{kind:"schema",type:"object",reference:r,expects:"Object",async:!1,entries:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.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 S={type:"object",origin:"value",input:c,key:l,value:y};for(let I of m.issues)I.path?I.path.unshift(S):I.path=[S],n.issues?.push(I);if(n.issues||(n.issues=m.issues),s.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[l]=m.value}else if(f.fallback!==void 0)n.value[l]=st(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(j(this,"key",n,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}}else j(this,"type",n,s);return n}}}function u(e,o){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===void 0&&(this.default!==void 0&&(n.value=De(this,n,s)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,s)}}}function B(e,o){return{kind:"schema",type:"picklist",reference:B,expects:Fe(e.map(ge),"|"),async:!1,options:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){return this.options.includes(n.value)?n.typed=!0:j(this,"type",n,s),n}}}function H(e,o,n){return{kind:"schema",type:"record",reference:H,expects:"Object",async:!1,key:e,value:o,message:n,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(Vr(l,f)){let y=l[f],m=this.key["~run"]({value:f},c);if(m.issues){let I={type:"object",origin:"key",input:l,key:f,value:y};for(let R of m.issues)R.path=[I],s.issues?.push(R);if(s.issues||(s.issues=m.issues),c.abortEarly){s.typed=!1;break}}let S=this.value["~run"]({value:y},c);if(S.issues){let I={type:"object",origin:"value",input:l,key:f,value:y};for(let R of S.issues)R.path?R.path.unshift(I):R.path=[I],s.issues?.push(R);if(s.issues||(s.issues=S.issues),c.abortEarly){s.typed=!1;break}}(!m.typed||!S.typed)&&(s.typed=!1),m.typed&&(s.value[m.value]=S.value)}}else j(this,"type",s,c);return s}}}function p(e,o){return{kind:"schema",type:"strict_object",reference:p,expects:"Object",async:!1,entries:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.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 S={type:"object",origin:"value",input:c,key:l,value:y};for(let I of m.issues)I.path?I.path.unshift(S):I.path=[S],n.issues?.push(I);if(n.issues||(n.issues=m.issues),s.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[l]=m.value}else if(f.fallback!==void 0)n.value[l]=st(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(j(this,"key",n,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!n.issues||!s.abortEarly){for(let l in c)if(!(l in this.entries)){j(this,"key",n,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else j(this,"type",n,s);return n}}}function t(e){return{kind:"schema",type:"string",reference:t,expects:"string",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="string"?o.typed=!0:j(this,"type",o,n),o}}}function ot(e){let o;if(e)for(let n of e)if(o)for(let s of n.issues)o.push(s);else o=n.issues;return o}function _(e,o){return{kind:"schema",type:"union",reference:_,expects:Fe(e.map(n=>n.expects),"|"),async:!1,options:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c,l,f;for(let y of this.options){let m=y["~run"]({value:n.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];j(this,"type",n,s,{issues:ot(l)}),n.typed=!0}else{if(f?.length===1)return f[0];j(this,"type",n,s,{issues:ot(f)})}return n}}}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 h(e,o,n){return{kind:"schema",type:"variant",reference:h,expects:"Object",async:!1,key:e,options:o,message:n,get"~standard"(){return z(this)},"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let f,y=0,m=this.key,S=[],I=(R,k)=>{for(let G of R.options){if(G.type==="variant")I(G,new Set(k).add(G.key));else{let J=!0,N=0;for(let M of k){let F=G.entries[M];if(M in l?F["~run"]({typed:!1,value:l[M]},it).issues:F.type!=="exact_optional"&&F.type!=="optional"&&F.type!=="nullish"){J=!1,m!==M&&(y<N||y===N&&M in l&&!(m in l))&&(y=N,m=M,S=[]),m===M&&S.push(G.entries[M].expects);break}N++}if(J){let M=G["~run"]({value:l},c);(!f||!f.typed&&M.typed)&&(f=M)}}if(f&&!f.issues)break}};if(I(this,new Set([this.key])),f)return f;j(this,"type",s,c,{input:l[m],expected:Fe(S,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else j(this,"type",s,c);return s}}}function at(e,o){let n={...e.entries};for(let s of o)delete n[s];return{...e,entries:n,get"~standard"(){return z(this)}}}function fe(e,o,n){let s=e["~run"]({value:o},Ne(n));if(s.issues)throw new $r(s.issues);return s.value}function L(...e){return{...e[0],pipe:e,get"~standard"(){return z(this)},"~run"(o,n){for(let s of e)if(s.kind!=="metadata"){if(o.issues&&(s.kind==="schema"||s.kind==="transformation")){o.typed=!1;break}(!o.issues||!n.abortEarly&&!n.abortPipeEarly)&&(o=s["~run"](o,n))}return o}}}function _e(e,o,n){let s=e["~run"]({value:o},Ne(n));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var re=L(t(),te("NotionBlockId")),Y=L(t(),te("NotionDataSourceId")),T=L(t(),te("NotionPageId")),ct=L(t(),te("NotionAgentId")),lt=L(t(),te("NotionSpaceId"));var pt=B(["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"]),Le=r({id:t(),name:t(),color:u(pt),description:u(t())}),Qr=r({id:t(),name:t(),color:u(pt),option_ids:O(t())}),Xr=r({synced_property_id:t(),synced_property_name:t()}),P=r({name:t(),description:u(t())}),Wr=["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"],ft=B(Wr),mt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Ge=h("type",[r({...P.entries,type:i("title")}),r({...P.entries,type:i("rich_text")}),r({...P.entries,type:i("number")}),r({...P.entries,type:i("checkbox")}),r({...P.entries,type:i("url")}),r({...P.entries,type:i("email")}),r({...P.entries,type:i("phone_number")}),r({...P.entries,type:i("select"),options:O(Le)}),r({...P.entries,type:i("multi_select"),options:O(Le)}),r({...P.entries,type:i("status"),options:O(Le),groups:O(Qr)}),r({...P.entries,type:i("date")}),r({...P.entries,type:i("people")}),r({...P.entries,type:i("files")}),r({...P.entries,type:i("unique_id")}),r({...P.entries,type:i("relation"),data_source_id:u(t()),dual_property:u(Xr)}),r({...P.entries,type:i("place")}),r({...P.entries,type:i("formula")}),r({...P.entries,type:i("rollup")}),r({...P.entries,type:i("button")}),r({...P.entries,type:i("verification")}),r({...P.entries,type:i("last_visited_time")}),r({...P.entries,type:i("location")}),r({...P.entries,type:i("created_time")}),r({...P.entries,type:i("last_edited_time")}),r({...P.entries,type:i("created_by")}),r({...P.entries,type:i("last_edited_by")})]);var yt={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 vt=r({id:Y,table:t(),spaceId:u(lt)}),dt=r({id:u(Y),propertiesById:H(t(),Ge)}),mo=r({key:t(),collectionPointer:u(vt),collectionSchema:u(dt),propertyIdsByKey:H(t(),u(t())),propertySchemasById:H(t(),Ge)}),Jr=r({collectionPointer:u(vt),collectionSchema:u(dt),propertyIdsByKey:u(H(t(),u(t())))}),le=H(t(),Jr);var Kr=h("type",[r({type:i("emoji"),emoji:t()}),r({type:i("external"),url:t()})]),Zr=r({name:t(),description:u(t()),type:ft}),Yr=r({name:t(),description:u(t()),icon:u(Kr),properties:u(H(t(),Zr),{})}),pe=r({version:i(1),name:u(t()),description:u(t()),slashCommand:u(t()),icon:u(r({type:i("emoji"),emoji:t()})),dataSources:u(H(t(),Yr),{})});var me=B(["standard","high"]),ht="standard";var gt=r({type:i("contrastModeChanged"),contrastMode:me});var we=r({id:t(),table:t()});var ne=h("type",[r({type:i("page_id"),page_id:T}),r({type:i("data_source_id"),data_source_id:Y}),r({type:i("workspace"),workspace:i(!0)}),r({type:i("block_id"),block_id:re}),r({type:i("agent_id"),agent_id:ct}),r({type:i("unavailable")})]);var ye=h("type",[r({type:i("unavailable")}),r({type:i("page"),id:T,parent:ne})]),en=r({type:i("emoji"),emoji:t()}),tn=r({type:i("custom_emoji"),custom_emoji:r({id:t(),name:u(t()),url:u(t())})}),St=r({type:i("external"),external:r({url:t()})}),It=r({type:i("file"),file:r({url:t(),expiry_time:u(t())})}),$e=h("type",[en,tn,St,It]),Qe=h("type",[St,It]),$=W(t()),bt=H(t(),Ie()),Ve=_([r({id:t(),name:u(t()),color:u(t()),description:u($)}),r({name:t(),id:u(t()),color:u(t()),description:u($)})]),rn=r({start:t(),end:u($),time_zone:u($)}),nn=_([r({object:u(i("user")),id:t()}),r({object:i("group"),id:t(),name:u($)})]),on=r({id:t()}),sn=_([r({type:i("external"),name:t(),external:r({url:t()})}),r({type:i("file"),name:t(),file:r({url:t(),expiry_time:u(t())})})]),un=r({lat:E(),lon:E(),name:u($),address:u($),aws_place_id:u($),google_place_id:u($)}),w={id:t()},kt=W(r({...we.entries,table:B(["notion_user","bot","organization_bot"]),spaceId:u(t())})),an=h("type",[r({...w,type:i("title"),title:O(bt)}),r({...w,type:i("rich_text"),rich_text:O(bt)}),r({...w,type:i("number"),number:W(E())}),r({...w,type:i("url"),url:$}),r({...w,type:i("email"),email:$}),r({...w,type:i("phone_number"),phone_number:$}),r({...w,type:i("checkbox"),checkbox:b()}),r({...w,type:i("select"),select:W(Ve)}),r({...w,type:i("status"),status:W(Ve)}),r({...w,type:i("multi_select"),multi_select:O(Ve)}),r({...w,type:i("date"),date:W(rn)}),r({...w,type:i("people"),people:O(nn)}),r({...w,type:i("relation"),has_more:u(b()),relation:O(on)}),r({...w,type:i("files"),files:O(sn)}),r({...w,type:i("place"),place:W(un)}),r({...w,type:i("created_time"),created_time:$}),r({...w,type:i("last_edited_time"),last_edited_time:$}),r({...w,type:i("created_by"),created_by:kt}),r({...w,type:i("last_edited_by"),last_edited_by:kt}),r({...w,type:i("last_visited_time"),last_visited_time:$})]),xe=H(t(),an),ve=r({object:i("page"),id:T,parent:ne,properties:xe,created_time:u(t()),last_edited_time:u(t()),icon:u($e),cover:u(Qe),url:u(t()),public_url:u(t()),is_archived:b(),in_trash:b()});var cn=t(),ln=r({code:cn,message:t(),isRetryable:b()}),_t=h("status",[r({type:i("createPageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("createPageResult"),requestId:t(),status:i("error"),error:ln})]);var Xe=L(t(),te("NotionUserId")),oe=r({object:i("user"),id:Xe,name:u(t()),avatar_url:W(t()),type:i("person"),person:r({email:t()})}),xt=r({object:i("list"),results:O(oe),next_cursor:W(t()),has_more:b(),type:i("user"),user:H(t(),Ie())});var Ct=r({type:i("currentUserChanged"),currentUser:oe});var Et=r({type:i("dataSourcesChanged"),dataSources:r({bindings:le})});var pn=t(),fn=r({code:pn,message:t(),isRetryable:b()}),Ot=r({type:i("getPage"),requestId:t(),pageId:T}),Pt=h("status",[r({type:i("getPageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("getPageResult"),requestId:t(),status:i("error"),error:fn})]);var mn=t(),yn=r({code:mn,message:t(),isRetryable:b()}),jt=r({type:i("getUser"),requestId:t(),userId:Xe}),Bt=h("status",[r({type:i("getUserResult"),requestId:t(),status:i("success"),user:oe}),r({type:i("getUserResult"),requestId:t(),status:i("error"),error:yn})]);var de=B(["light","dark"]);var vn=t(),dn=r({code:vn,message:t(),isRetryable:b()});var Ae=h("status",[r({type:i("init"),initializationId:t(),status:i("success"),theme:de,contrastMode:me,blockId:re,parent:ne,page:ye,manifest:pe,dataSources:r({bindings:le}),currentUser:oe}),r({type:i("init"),initializationId:t(),status:i("error"),error:dn})]);var Rt=r({type:i("invalidSandboxMessage"),reason:t()});var hn=t(),gn=r({code:hn,message:t(),isRetryable:b()}),Mt=r({type:i("listUsers"),requestId:t(),startCursor:u(t()),pageSize:u(E())}),Dt=h("status",[r({type:i("listUsersResult"),requestId:t(),status:i("success"),list:xt}),r({type:i("listUsersResult"),requestId:t(),status:i("error"),error:gn})]);var bn=B(["side_peek","center_peek"]),kn=t(),Sn=r({code:kn,message:t(),isRetryable:b()}),wt=r({type:i("openPage"),requestId:t(),pageId:T,mode:bn}),At=h("status",[r({type:i("openPageResult"),requestId:t(),status:i("success"),pageId:T}),r({type:i("openPageResult"),requestId:t(),status:i("error"),error:Sn})]);var qt=r({type:i("pageChanged"),page:ye});var Tt=r({type:i("parentChanged"),parent:ne});var Nt=r({unit:B(["year","month","week","day"]),value:E(),time:t(),defaultTimeZone:u(t())}),In=r({unit:B(["hour","minute"]),value:E()}),Ft=r({unit:i("none")}),_n=_([Nt,In]),Ut=u(_([Nt,Ft])),zt=u(_([_n,Ft])),xn=r({type:i("date"),start_date:t(),reminder:Ut}),Cn=r({type:i("daterange"),start_date:t(),end_date:t(),reminder:Ut}),En=r({type:i("datetime"),start_date:t(),start_time:t(),time_zone:u(t()),reminder:zt}),On=r({type:i("datetimerange"),start_date:t(),start_time:t(),end_date:t(),end_time:t(),time_zone:u(t()),reminder:zt}),Ht=h("type",[xn,Cn,En,On]);var Lt=_([t(),E(),b(),Ht,O(t()),O(we)]);var Gt=r({id:T,is_archived:b(),in_trash:b(),propertiesById:H(t(),u(Lt))});var Pn=t(),jn=r({code:Pn,message:t(),isRetryable:b()}),Vt=h("status",[r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("success"),items:O(Gt),hasMore:b()}),r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("error"),error:jn})]);var $t=r({type:i("themeChanged"),theme:de});var Bn=t(),Rn=r({code:Bn,message:t(),isRetryable:b()}),Qt=h("status",[r({type:i("updatePageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("updatePageResult"),requestId:t(),status:i("error"),error:Rn})]);var Xt=h("type",[Ae,$t,gt,Tt,qt,Ct,Et,Vt,_t,Pt,Bt,Dt,At,Qt,Rt]);function Wt(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function Jt(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function We(e){let{currentBridgeProtocolVersion:o}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${o}`,isRetryable:!1}}function Je(e){let{currentBridgeProtocolVersion:o,minBridgeProtocolVersion:n}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${o} is not supported. Minimum supported version is ${n}.`,isRetryable:!1}}function Ke(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Kt(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Zt(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function Yt(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function er(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function tr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function rr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function nr(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function ie(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function Ze(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Mn=5e3,Dn=5e3,wn=5e3;function or(e){let{prepareInit:o,sendInitMessage:n,warn:s,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:f=Mn,initialStateTimeoutMs:y=Dn,noInitResultTimeoutMs:m=wn,stopHostWithFailure:S,onInitResult:I,onConnectionFailure:R}=e,k="waitingForConnect",G,J,N,M,F=!1,se=!1;function X(){G!==void 0&&(window.clearTimeout(G),G=void 0)}function D(){J!==void 0&&(window.clearTimeout(J),J=void 0)}function U(){N!==void 0&&(window.clearTimeout(N),N=void 0)}function q(g){let{initializationId:v,error:V,phase:Z,source:Be}=g;switch(k){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return ie(k)}k="error",M=v,X(),D(),n({type:"init",initializationId:v,status:"error",error:V}),R?.({...V,phase:Z,source:Be})}async function K(g){if(k==="waitingForConnect"){k="preparingInit",M=g.initializationId,X(),J=window.setTimeout(()=>{if(k!=="preparingInit")return;let v=Kt();s({...v,initializationId:g.initializationId}),q({initializationId:g.initializationId,error:v,phase:"init",source:"host"})},y);try{let v=await o(g);if(k!=="preparingInit")return;if(D(),v.status==="error"){q({initializationId:g.initializationId,error:v.error,phase:"init",source:"host"});return}k="waitingForInitResult";let V={type:"init",initializationId:g.initializationId,status:"success",theme:v.initialState.theme,contrastMode:v.initialState.contrastMode??ht,blockId:v.initialState.blockId,parent:v.initialState.parent,page:v.initialState.page,currentUser:v.initialState.currentUser,manifest:v.initialState.manifest,dataSources:v.initialState.dataSources};n(V),N=window.setTimeout(()=>{if(k!=="waitingForInitResult")return;k="error";let Z=tr();R?.({...Z,phase:"initResult",source:"host"}),s({...Z,initializationId:g.initializationId})},m)}catch(v){if(k!=="preparingInit")return;s({message:"Failed to prepare custom block initialization",error:v}),q({initializationId:g.initializationId,error:nr(),phase:"init",source:"host"})}}}function ee(g){if(k!=="stopped"&&k==="waitingForConnect"){if(!Ze(g.bridgeProtocolVersion)){let v=We({currentBridgeProtocolVersion:g.bridgeProtocolVersion});q({initializationId:g.initializationId,error:v,phase:"connect",source:"host"});return}if(g.bridgeProtocolVersion<l){let v=Je({currentBridgeProtocolVersion:g.bridgeProtocolVersion,minBridgeProtocolVersion:l});q({initializationId:g.initializationId,error:v,phase:"connect",source:"host"});return}if(g.status==="error"){q({initializationId:g.initializationId,error:g.error,phase:"connect",source:"sandbox"});return}se=!0,K(g)}}function x(g){if(k==="stopped"||k!=="waitingForConnect")return"handled";let{initializationId:v,bridgeProtocolVersion:V}=g;if(v===void 0)return"nack";let Z=g.error;return V!==void 0&&(Ze(V)?V<l&&(Z=Je({currentBridgeProtocolVersion:V,minBridgeProtocolVersion:l})):Z=We({currentBridgeProtocolVersion:V})),q({initializationId:v,error:Z,phase:"connect",source:"host"}),"handled"}function ue(g){let{initializationId:v,error:V}=g;k!=="waitingForInitResult"||v===void 0||v!==M||(X(),U(),k="error",s(V),R?.({...V,phase:"initResult",source:"host"}))}function je(){if(k!=="stopped"){if(F){S({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}F=!0,X(),k==="waitingForConnect"&&(G=window.setTimeout(()=>{if(k!=="waitingForConnect")return;k="error";let g=Wt();s(g),R?.({...g,phase:"connect",source:"host"})},f))}}function he(g){if(k!=="waitingForInitResult"||g.initializationId!==M){s({message:"Ignored stale or unexpected initResult",payload:g});return}U(),k=g.status==="success"?"initialized":"error",g.status==="success"?c():R?.({...g.error,phase:"initResult",source:"sandbox"}),I?.(g)}function ae(){k="stopped",X(),D(),U()}return{get status(){return k},get hasConnectedSandbox(){return se},handleConnect:ee,handleInitResult:he,handleInvalidConnect:x,handleInvalidInitResult:ue,onIframeLoad:je,stop:ae}}function ir(e,o){return o>=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,...yt}}}]))}}}var sr=r({theme:de,contrastMode:u(me),blockId:re,parent:ne,page:ye,manifest:pe,dataSources:r({bindings:le}),currentUser:oe});function ur(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var ar=r({code:t(),message:t(),isRetryable:b()});var cr={type:i("connect"),initializationId:t(),bridgeProtocolVersion:E(),sdkVersion:t()},lr=h("status",[r({status:i("success"),manifest:u(pe),...cr}),r({status:i("error"),error:ar,...cr})]);var An=h("type",[r({type:i("start")}),r({type:i("end")}),r({type:i("before"),blockId:re}),r({type:i("after"),blockId:re})]),qn=h("type",[r({type:i("page_id"),page_id:T}),r({type:i("data_source_id"),data_source_id:Y})]),pr=r({type:i("createPage"),requestId:t(),parent:qn,properties:xe,position:u(An)});var Tn=t(),Nn=r({code:Tn,message:t(),isRetryable:b()}),fr=h("status",[r({type:i("initResult"),initializationId:t(),status:i("success"),initialHeight:u(L(E(),be(),Se(0)))}),r({type:i("initResult"),initializationId:t(),status:i("error"),error:Nn})]);var mr=r({type:i("invalidHostMessage"),reason:t()});var yr=B(["ascending","descending"]);var vr=L(T,Ue(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),ze(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),Ye=_([p({contains:vr}),p({does_not_contain:vr})]),Pe=_([p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Oe=_([t(),O(t())]),dr=p({object:B(["user","group"]),id:L(t(),ke(1))}),Fn=_([p({contains:dr}),p({does_not_contain:dr}),Pe]),hr=p({object:i("user"),id:L(t(),ke(1),Me(2e3))}),Un=_([p({contains:hr}),p({does_not_contain:hr}),p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Ce=_([p({equals:t()}),p({does_not_equal:t()}),p({contains:t()}),p({does_not_contain:t()}),p({starts_with:t()}),p({ends_with:t()}),Pe]),zn=_([p({equals:E()}),p({does_not_equal:E()}),p({greater_than:E()}),p({less_than:E()}),p({greater_than_or_equal_to:E()}),p({less_than_or_equal_to:E()}),Pe]),Hn=_([p({equals:b()}),p({does_not_equal:b()})]),Sr=_([p({equals:Oe}),p({does_not_equal:Oe}),Pe]),gr=B(["To-do","In progress","Complete","Current","Future"]),br=_([gr,L(O(gr),ke(1),Me(5))]),Ln=_([p({group_equals:br}),p({group_does_not_equal:br})]),Gn=_([Sr,Ln]),Vn=_([p({contains:Oe}),p({contains_all:Oe}),p({does_not_contain:Oe}),Pe]),Q=B(["start_date","end_date"]),$n=B(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Ee=_([$n,t()]),Qn=_([p({target:u(Q),equals:Ee}),p({target:u(Q),before:Ee}),p({target:u(Q),after:Ee}),p({target:u(Q),on_or_before:Ee}),p({target:u(Q),on_or_after:Ee}),p({target:u(Q),this_week:p({})}),p({target:u(Q),past_week:p({})}),p({target:u(Q),past_month:p({})}),p({target:u(Q),past_year:p({})}),p({target:u(Q),next_week:p({})}),p({target:u(Q),next_month:p({})}),p({target:u(Q),next_year:p({})}),p({target:u(Q),is_empty:i(!0)}),p({target:u(Q),is_not_empty:i(!0)})]),kr=_([p({propertyId:t(),relation:Ye}),p({propertyId:t(),created_by:Un}),p({propertyId:t(),title:Ce}),p({propertyId:t(),rich_text:Ce}),p({propertyId:t(),url:Ce}),p({propertyId:t(),email:Ce}),p({propertyId:t(),phone_number:Ce}),p({propertyId:t(),number:zn}),p({propertyId:t(),checkbox:Hn}),p({propertyId:t(),select:Sr}),p({propertyId:t(),multi_select:Vn}),p({propertyId:t(),status:Gn}),p({propertyId:t(),date:Qn}),p({propertyId:t(),people:Fn})]),Xn=_([kr,p({and:O(kr)})]),et=10,Wn=p({propertyId:t(),direction:yr}),Ir=r({type:i("queryDataSource"),subscriptionId:t(),dataSourceId:Y,limit:E(),filter:u(Xn),sorts:u(O(Wn))});var _r=r({type:i("resize"),height:L(E(),be(),Se(0))});var xr=r({type:i("unsubscribeDataSourceQuery"),subscriptionId:t()});var Cr=r({type:i("updatePage"),requestId:t(),pageId:T,properties:u(xe),icon:u($e),cover:u(Qe),archived:u(b())});var Er=h("type",[lr,fr,Ir,xr,pr,Ot,jt,Mt,wt,Cr,_r,mr]);function Or(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Pr(e){let o=Or(e);return o==="invalidHostMessage"||o==="invalidSandboxMessage"?{incomingType:o}:{incomingType:o,nack:{type:"invalidSandboxMessage",reason:Jn(o)}}}function Jn(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var jr=r({initializationId:t()}),Kn=r({bridgeProtocolVersion:_([E(),He()])});function Br(e){let{iframe:o,sandboxOrigin:n,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:f,onInvalidInitResult:y,onConnect:m,onInitResult:S,onQueryDataSource:I,onUnsubscribeDataSourceQuery:R,onCreatePage:k,onGetPage:G,onOpenPage:J,onGetUser:N,onListUsers:M,onUpdatePage:F,onResize:se}=e;function X(D,U){c("warn",{message:"Ignored unsupported sandbox message",payload:D,issues:U});let q=Pr(D);if(q.incomingType==="connect"){let K=_e(jr,D),ee=_e(Kn,D);if(f({initializationId:K.success?K.output.initializationId:void 0,error:Jt(),bridgeProtocolVersion:ee.success?ee.output.bridgeProtocolVersion:void 0})==="handled")return}if(q.incomingType==="initResult"){let K=_e(jr,D);y({initializationId:K.success?K.output.initializationId:void 0,error:rr()})}q.nack!==void 0&&s()!=="stopped"&&l(q.nack)}return function(U){let q=U.source===o.contentWindow,K=U.origin===n;if(!q||!K)return;let ee=_e(Er,U.data);if(!ee.success){X(U.data,ee.issues);return}let x=ee.output;if(!ur(x)&&s()!=="initialized"){c("warn",{message:`Ignored ${x.type} before initialization completed`,payload:x});return}switch(c("in",x),x.type){case"connect":m(x);return;case"initResult":S(x);return;case"queryDataSource":I(x);return;case"unsubscribeDataSourceQuery":R(x);return;case"createPage":k(x);return;case"openPage":J(x);return;case"getPage":G(x);return;case"getUser":N(x);return;case"listUsers":M(x);return;case"updatePage":F(x);return;case"resize":se(x);return;case"invalidHostMessage":return;default:ie(x)}}}var qe=class{constructor(o){this.onUnsubscribe=o}onUnsubscribe;bySubscriptionId=new Map;subscribe(o){this.unsubscribe(o.subscriptionId);let n={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(o.subscriptionId,{message:o,token:n,isRefreshing:!0,shouldRefreshAgain:!1}),n}isCurrent(o,n){return this.bySubscriptionId.get(o)?.token===n}unsubscribe(o){this.bySubscriptionId.delete(o)&&this.onUnsubscribe(o)}refresh(o){let n=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===o){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,n.push({message:c.message,token:c.token})}return s?n:void 0}finish(o,n){let s=this.bySubscriptionId.get(o);if(s?.token===n&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let o of this.bySubscriptionId.keys())this.unsubscribe(o)}};function Rr(e,o){if(e===void 0)return;let n="and"in e?e.and:[e];for(let s of n){let c=Zn(s,o);if(c!==void 0)return c}}function Zn(e,o){if(!Object.hasOwn(o.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=o.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==n.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" 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,I=(Array.isArray(m)?m:[m]).find(R=>!n.groups.some(k=>k.name===R));return I===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${I}".`,isRetryable:!1}}}if("relation"in e&&!ut(Ye,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=Yn(e);if(c===void 0||n.type!==c.propertyType)return;let l=new Set(n.options.map(y=>y.name)),f=eo(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 Yn(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 o=e.status;return"group_equals"in o||"group_does_not_equal"in o?void 0:{propertyType:"status",operator:o}}}function eo(e){let o;if("equals"in e)o=e.equals;else if("does_not_equal"in e)o=e.does_not_equal;else if("contains"in e)o=e.contains;else if("contains_all"in e)o=e.contains_all;else if("does_not_contain"in e)o=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:ie(e);return Array.isArray(o)?o:[o]}var to=new Set(mt);function Mr(e,o){if(e===void 0)return;if(e.length>et)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${et} entries.`,isRetryable:!1};let n=new Set;for(let s of e){if(n.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(n.add(s.propertyId),!Object.hasOwn(o.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=o.propertiesById[s.propertyId];if(!to.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 wr=5;function no(e){let{iframe:o,getInitialState:n,handlers:s,onManifest:c,onInitialized:l,onConnectionFailure:f,onLog:y,onQueryUnsubscribed:m,sandboxOrigin:S,minBridgeProtocolVersion:I,noConnectTimeoutMs:R,initialStateTimeoutMs:k,noInitResultTimeoutMs:G}=e,J=Math.max(I??3,3),N={},M=!1,F,se,X=5,D=new qe(a=>{m?.(a)});function U(a,C){y?.(a,C)}function q(a){let C=v.status;switch(C){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return ie(C)}let A=ir(a,X);U("out",A),o.contentWindow?.postMessage(A,S)}function K(a){q(fe(Ae,a))}function ee(a){q(a)}function x(a){let C=v.status;switch(C){case"initialized":q(fe(Xt,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:ie(C)}}async function ue(a,C){if(C===void 0)return;let A=await C(a);x({type:`${a.type}Result`,requestId:a.requestId,...A})}function je(a){let C=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};x(C)}async function he(a,C=D.subscribe(a)){try{let A=oo(se,a.dataSourceId),ce=io(a,A);if(ce!==void 0){D.isCurrent(a.subscriptionId,C)&&(D.unsubscribe(a.subscriptionId),je({subscriptionId:a.subscriptionId,response:{status:"error",error:ce}}));return}let Te=await s.queryDataSource(a);if(!D.isCurrent(a.subscriptionId,C))return;Te.status==="error"&&!Te.error.isRetryable&&D.unsubscribe(a.subscriptionId),je({subscriptionId:a.subscriptionId,response:Te})}finally{let A=D.finish(a.subscriptionId,C);A!==void 0&&he(A.message,A.token)}}function ae(a){v.status==="stopped"||v.status==="error"||(Object.assign(N,a),g())}function g(){if(v.status!=="initialized")return;let a=N;N={},a.theme!==void 0&&x({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&x({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&x({type:"parentChanged",parent:a.parent}),a.page!==void 0&&x({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&x({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&x({type:"currentUserChanged",currentUser:a.currentUser})}let v=or({async prepareInit(a){X=a.bridgeProtocolVersion;let C=await n(a);return v.status!=="preparingInit"?C:V(C)},sendInitMessage:K,warn:a=>U("warn",a),flushPendingHostStateChanges:g,minBridgeProtocolVersion:J,noConnectTimeoutMs:R,initialStateTimeoutMs:k,noInitResultTimeoutMs:G,stopHostWithFailure:tt,onInitResult(a){a.status==="success"&&F!==void 0&&l?.({manifest:F,initialHeight:a.initialHeight})},onConnectionFailure:f});function V(a){if(a.status==="error")return a;F=fe(pe,a.initialState.manifest),c?.(F);let C={...a.initialState,...N};N={};let A={...fe(at(sr,["manifest"]),C),manifest:F};if(X<wr&&A.page.type==="unavailable")return{status:"error",error:Ke()};let ce=Ar(A.manifest,A.dataSources);return ce!==void 0?{status:"error",error:ce}:(se=A.dataSources,M=!0,{status:"success",initialState:A})}let Z=Br({iframe:o,sandboxOrigin:S,getInitStatus:()=>v.status,emit:U,sendNack:ee,onInvalidConnect:v.handleInvalidConnect,onInvalidInitResult:v.handleInvalidInitResult,onConnect:v.handleConnect,onInitResult:v.handleInitResult,onQueryDataSource:he,onUnsubscribeDataSourceQuery:a=>D.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",Z),o.addEventListener("load",v.onIframeLoad);function Be(){window.removeEventListener("message",Z),o.removeEventListener("load",v.onIframeLoad),v.stop(),D.unsubscribeAll()}function tt(a){Be(),U("warn",a),f?.(a)}return{stop:Be,setTheme(a){ae({theme:a})},setContrastMode(a){ae({contrastMode:a})},setParent(a){ae({parent:a})},setPage(a){if(a.type==="unavailable"&&X<wr&&(v.status==="preparingInit"&&M||v.status==="waitingForInitResult"||v.status==="initialized")){tt({...Ke(),phase:"runtime",source:"host"});return}ae({page:a})},setCurrentUser(a){ae({currentUser:a})},setDataSources(a){let C={bindings:fe(le,a.bindings)};if(v.hasConnectedSandbox&&F!==void 0&&Ar(F,C)!==void 0){U("warn",{message:"Ignored invalid data source bindings update",payload:C});return}se=C,ae({dataSources:C})},refreshQuery({dataSourceId:a}){if(v.status!=="initialized")return;let C=fe(Y,a),A=D.refresh(C);if(A===void 0){U("warn",`No active query exists for data source "${a}"`);return}for(let ce of A)he(ce.message,ce.token)}}}function oo(e,o){return Object.values(e?.bindings??{}).find(n=>n.collectionPointer?.id===o)?.collectionSchema}function Ar(e,o){for(let[n,s]of Object.entries(e.dataSources)){let c=o.bindings[n];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Zt();for(let[l,f]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return Yt();if(c.collectionSchema.propertiesById[y]?.type!==f.type)return er()}}}function io(e,o){return o===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}:Rr(e.filter,o)??Mr(e.sorts,o)}function so(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}export{no as createCustomBlockHost,qr as getAutoBoundPropertyIdsByKey,so as isLocalCustomBlockUrl};
|
|
1
|
+
var zr=6;function Hr(e){let{manifestProperties:o,propertySchemasById:n}=e,s=[];for(let[c,l]of Object.entries(o)){let f=Lr({propertyKey:c,manifestProperty:l,propertySchemasById:n});f!==void 0&&s.push([c,f])}return Object.fromEntries(s)}function Lr(e){let{propertyKey:o,manifestProperty:n,propertySchemasById:s}=e,c=at(n.name),l=Object.entries(s).filter(([f,y])=>y.type===n.type&&(f===o||at(y.name)===c));return l.length===1?l[0][0]:void 0}function at(e){return e.trim().toLowerCase()}var Re,Vr={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Fe(e){return!e&&!Re?Vr:{lang:e?.lang??Re?.lang,message:e?.message,abortEarly:e?.abortEarly??Re?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Re?.abortPipeEarly}}var Gr;function $r(e){return Gr?.get(e)}var Qr;function Xr(e){return Qr?.get(e)}var Wr;function Jr(e,o){return Wr?.get(e)?.get(o)}function ge(e){let o=typeof e;return o==="string"?`"${e}"`:o==="number"||o==="bigint"||o==="boolean"?`${e}`:o==="object"||o==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":o}function B(e,o,n,s,c){let l=c&&"input"in c?c.input:n.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 ${o}: ${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??Jr(e.reference,m.lang)??(x?Xr(m.lang):null)??s.message??$r(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(n.typed=!1),n.issues?n.issues.push(m):n.issues=[m]}var ut=new WeakMap;function z(e){let o=ut.get(e);return o||(o={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},Fe())}},ut.set(e,o)),o}function Kr(e,o){return Object.prototype.hasOwnProperty.call(e,o)&&o!=="__proto__"&&o!=="prototype"&&o!=="constructor"}function Ue(e,o){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${o} `)})`:n[0]??"never"}var Yr=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"(o){return o}}}function be(e){return{kind:"validation",type:"finite",reference:be,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(o,n){return o.typed&&!this.requirement(o.value)&&B(this,"finite",o,n),o}}}function Me(e,o){return{kind:"validation",type:"max_length",reference:Me,async:!1,expects:`<=${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&n.value.length>this.requirement&&B(this,"length",n,s,{received:`${n.value.length}`}),n}}}function ke(e,o){return{kind:"validation",type:"min_length",reference:ke,async:!1,expects:`>=${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&n.value.length<this.requirement&&B(this,"length",n,s,{received:`${n.value.length}`}),n}}}function Se(e,o){return{kind:"validation",type:"min_value",reference:Se,async:!1,expects:`>=${e instanceof Date?e.toJSON():ge(e)}`,requirement:e,message:o,"~run"(n,s){return n.typed&&!(n.value>=this.requirement)&&B(this,"value",n,s,{received:n.value instanceof Date?n.value.toJSON():ge(n.value)}),n}}}function ze(e,o){return{kind:"validation",type:"regex",reference:ze,async:!1,expects:`${e}`,requirement:e,message:o,"~run"(n,s){return n.typed&&!this.requirement.test(n.value)&&B(this,"format",n,s),n}}}function He(e){return{kind:"transformation",type:"transform",reference:He,async:!1,operation:e,"~run"(o){return o.value=this.operation(o.value),o}}}var lt={abortEarly:!0};function pt(e,o,n){return typeof e.fallback=="function"?e.fallback(o,n):e.fallback}function De(e,o,n){return typeof e.default=="function"?e.default(o,n):e.default}function ft(e,o){return!e["~run"]({value:o},lt).issues}function E(e,o){return{kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(Array.isArray(c)){n.typed=!0,n.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],n.issues?.push(x);if(n.issues||(n.issues=y.issues),s.abortEarly){n.typed=!1;break}}y.typed||(n.typed=!1),n.value.push(y.value)}}else B(this,"type",n,s);return n}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="boolean"?o.typed=!0:B(this,"type",o,n),o}}}function i(e,o){return{kind:"schema",type:"literal",reference:i,expects:ge(e),async:!1,literal:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===this.literal?n.typed=!0:B(this,"type",n,s),n}}}function Le(e){return{kind:"schema",type:"nan",reference:Le,expects:"NaN",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return Number.isNaN(o.value)?o.typed=!0:B(this,"type",o,n),o}}}function J(e,o){return{kind:"schema",type:"nullable",reference:J,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===null&&(this.default!==void 0&&(n.value=De(this,n,s)),n.value===null)?(n.typed=!0,n):this.wrapped["~run"](n,s)}}}function P(e){return{kind:"schema",type:"number",reference:P,expects:"number",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="number"&&!isNaN(o.value)?o.typed=!0:B(this,"type",o,n),o}}}function r(e,o){return{kind:"schema",type:"object",reference:r,expects:"Object",async:!1,entries:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.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],n.issues?.push(_);if(n.issues||(n.issues=m.issues),s.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[l]=m.value}else if(f.fallback!==void 0)n.value[l]=pt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(B(this,"key",n,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",n,s);return n}}}function u(e,o){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:o,get"~standard"(){return z(this)},"~run"(n,s){return n.value===void 0&&(this.default!==void 0&&(n.value=De(this,n,s)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,s)}}}function R(e,o){return{kind:"schema",type:"picklist",reference:R,expects:Ue(e.map(ge),"|"),async:!1,options:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){return this.options.includes(n.value)?n.typed=!0:B(this,"type",n,s),n}}}function F(e,o,n){return{kind:"schema",type:"record",reference:F,expects:"Object",async:!1,key:e,value:o,message:n,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(Kr(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,o){return{kind:"schema",type:"strict_object",reference:p,expects:"Object",async:!1,entries:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.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],n.issues?.push(_);if(n.issues||(n.issues=m.issues),s.abortEarly){n.typed=!1;break}}m.typed||(n.typed=!1),n.value[l]=m.value}else if(f.fallback!==void 0)n.value[l]=pt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(B(this,"key",n,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!n.issues||!s.abortEarly){for(let l in c)if(!(l in this.entries)){B(this,"key",n,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else B(this,"type",n,s);return n}}}function t(e){return{kind:"schema",type:"string",reference:t,expects:"string",async:!1,message:e,get"~standard"(){return z(this)},"~run"(o,n){return typeof o.value=="string"?o.typed=!0:B(this,"type",o,n),o}}}function ct(e){let o;if(e)for(let n of e)if(o)for(let s of n.issues)o.push(s);else o=n.issues;return o}function I(e,o){return{kind:"schema",type:"union",reference:I,expects:Ue(e.map(n=>n.expects),"|"),async:!1,options:e,message:o,get"~standard"(){return z(this)},"~run"(n,s){let c,l,f;for(let y of this.options){let m=y["~run"]({value:n.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",n,s,{issues:ct(l)}),n.typed=!0}else{if(f?.length===1)return f[0];B(this,"type",n,s,{issues:ct(f)})}return n}}}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,o,n){return{kind:"schema",type:"variant",reference:g,expects:"Object",async:!1,key:e,options:o,message:n,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]},lt).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:Ue(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else B(this,"type",s,c);return s}}}function te(e,o,n){let s=e["~run"]({value:o},Fe(n));if(s.issues)throw new Yr(s.issues);return s.value}function U(...e){return{...e[0],pipe:e,get"~standard"(){return z(this)},"~run"(o,n){for(let s of e)if(s.kind!=="metadata"){if(o.issues&&(s.kind==="schema"||s.kind==="transformation")){o.typed=!1;break}(!o.issues||!n.abortEarly&&!n.abortPipeEarly)&&(o=s["~run"](o,n))}return o}}}function _e(e,o,n){let s=e["~run"]({value:o},Fe(n));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")),mt=U(t(),re("NotionAgentId")),yt=U(t(),re("NotionSpaceId"));var vt=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"]),Ve=r({id:t(),name:t(),color:u(vt),description:u(t())}),Zr=r({id:t(),name:t(),color:u(vt),option_ids:E(t())}),en=r({synced_property_id:t(),synced_property_name:t()}),O=r({name:t(),description:u(t())}),tn=["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"],dt=R(tn),ht=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Ge=g("type",[r({...O.entries,type:i("title")}),r({...O.entries,type:i("rich_text")}),r({...O.entries,type:i("number")}),r({...O.entries,type:i("checkbox")}),r({...O.entries,type:i("url")}),r({...O.entries,type:i("email")}),r({...O.entries,type:i("phone_number")}),r({...O.entries,type:i("select"),options:E(Ve)}),r({...O.entries,type:i("multi_select"),options:E(Ve)}),r({...O.entries,type:i("status"),options:E(Ve),groups:E(Zr)}),r({...O.entries,type:i("date")}),r({...O.entries,type:i("people")}),r({...O.entries,type:i("files")}),r({...O.entries,type:i("unique_id")}),r({...O.entries,type:i("relation"),data_source_id:u(t()),dual_property:u(en)}),r({...O.entries,type:i("place")}),r({...O.entries,type:i("formula")}),r({...O.entries,type:i("rollup")}),r({...O.entries,type:i("button")}),r({...O.entries,type:i("verification")}),r({...O.entries,type:i("last_visited_time")}),r({...O.entries,type:i("location")}),r({...O.entries,type:i("created_time")}),r({...O.entries,type:i("last_edited_time")}),r({...O.entries,type:i("created_by")}),r({...O.entries,type:i("last_edited_by")})]);var gt={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 bt=r({id:Y,table:t(),spaceId:u(yt)}),kt=r({id:u(Y),propertiesById:F(t(),Ge)}),So=r({key:t(),collectionPointer:u(bt),collectionSchema:u(kt),propertyIdsByKey:F(t(),u(t())),propertySchemasById:F(t(),Ge)}),rn=r({collectionPointer:u(bt),collectionSchema:u(kt),propertyIdsByKey:u(F(t(),u(t())))}),le=F(t(),rn);var fe=R(["standard","high"]),St="standard";var It=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:mt}),r({type:i("unavailable")})]);var me=g("type",[r({type:i("unavailable")}),r({type:i("page"),id:D,parent:oe})]),nn=r({type:i("emoji"),emoji:t()}),on=r({type:i("custom_emoji"),custom_emoji:r({id:t(),name:u(t()),url:u(t())})}),Ct=r({type:i("external"),external:r({url:t()})}),Pt=r({type:i("file"),file:r({url:t(),expiry_time:u(t())})}),Qe=g("type",[nn,on,Ct,Pt]),Xe=g("type",[Ct,Pt]),$=J(t()),_t=F(t(),Ie()),$e=I([r({id:t(),name:u(t()),color:u(t()),description:u($)}),r({name:t(),id:u(t()),color:u(t()),description:u($)})]),sn=r({start:t(),end:u($),time_zone:u($)}),an=I([r({object:u(i("user")),id:t()}),r({object:i("group"),id:t(),name:u($)})]),un=r({id:t()}),cn=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())})})]),ln=r({lat:P(),lon:P(),name:u($),address:u($),aws_place_id:u($),google_place_id:u($)}),A={id:t()},xt=J(r({...we.entries,table:R(["notion_user","bot","organization_bot"]),spaceId:u(t())})),We=g("type",[r({...A,type:i("title"),title:E(_t)}),r({...A,type:i("rich_text"),rich_text:E(_t)}),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($e)}),r({...A,type:i("status"),status:J($e)}),r({...A,type:i("multi_select"),multi_select:E($e)}),r({...A,type:i("date"),date:J(sn)}),r({...A,type:i("people"),people:E(an)}),r({...A,type:i("relation"),has_more:u(h()),relation:E(un)}),r({...A,type:i("files"),files:E(cn)}),r({...A,type:i("place"),place:J(ln)}),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:xt}),r({...A,type:i("last_edited_by"),last_edited_by:xt}),r({...A,type:i("last_visited_time"),last_visited_time:$})]),xe=F(t(),We),ye=r({object:i("page"),id:D,parent:oe,properties:xe,created_time:u(t()),last_edited_time:u(t()),icon:u(Qe),cover:u(Xe),url:u(t()),public_url:u(t()),is_archived:h(),in_trash:h()});var pn=t(),fn=r({code:pn,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:fn})]);var Je=U(t(),re("NotionUserId")),ie=r({object:i("user"),id:Je,name:u(t()),avatar_url:J(t()),type:i("person"),person:r({email:t()})}),Ot=r({object:i("list"),results:E(ie),next_cursor:J(t()),has_more:h(),type:i("user"),user:F(t(),Ie())});var jt=r({type:i("currentUserChanged"),currentUser:ie});var Bt=r({type:i("dataSourcesChanged"),dataSources:r({bindings:le})});var mn=t(),yn=r({code:mn,message:t(),isRetryable:h()}),Rt=r({type:i("getPage"),requestId:t(),pageId:D}),Mt=g("status",[r({type:i("getPageResult"),requestId:t(),status:i("success"),page:ye}),r({type:i("getPageResult"),requestId:t(),status:i("error"),error:yn})]);var vn=t(),dn=r({code:vn,message:t(),isRetryable:h()}),Dt=r({type:i("getUser"),requestId:t(),userId:Je}),wt=g("status",[r({type:i("getUserResult"),requestId:t(),status:i("success"),user:ie}),r({type:i("getUserResult"),requestId:t(),status:i("error"),error:dn})]);var hn=g("type",[r({type:i("emoji"),emoji:t()}),r({type:i("external"),url:t()})]),gn=r({name:t(),description:u(t()),type:dt}),bn=r({name:t(),description:u(t()),icon:u(hn),properties:u(F(t(),gn),{})}),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(),bn),{})});var ve=R(["light","dark"]);var kn=t(),Sn=r({code:kn,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:Sn})]);var At=r({type:i("invalidSandboxMessage"),reason:t()});var In=t(),_n=r({code:In,message:t(),isRetryable:h()}),qt=r({type:i("listUsers"),requestId:t(),startCursor:u(t()),pageSize:u(P())}),Tt=g("status",[r({type:i("listUsersResult"),requestId:t(),status:i("success"),list:Ot}),r({type:i("listUsersResult"),requestId:t(),status:i("error"),error:_n})]);var xn=R(["side_peek","center_peek"]),Cn=t(),Pn=r({code:Cn,message:t(),isRetryable:h()}),Nt=r({type:i("openPage"),requestId:t(),pageId:D,mode:xn}),Ft=g("status",[r({type:i("openPageResult"),requestId:t(),status:i("success"),pageId:D}),r({type:i("openPageResult"),requestId:t(),status:i("error"),error:Pn})]);var Ut=r({type:i("pageChanged"),page:me});var zt=r({type:i("parentChanged"),parent:oe});var Ht=r({unit:R(["year","month","week","day"]),value:P(),time:t(),defaultTimeZone:u(t())}),En=r({unit:R(["hour","minute"]),value:P()}),Lt=r({unit:i("none")}),On=I([Ht,En]),Vt=u(I([Ht,Lt])),Gt=u(I([On,Lt])),jn=r({type:i("date"),start_date:t(),reminder:Vt}),Bn=r({type:i("daterange"),start_date:t(),end_date:t(),reminder:Vt}),Rn=r({type:i("datetime"),start_date:t(),start_time:t(),time_zone:u(t()),reminder:Gt}),Mn=r({type:i("datetimerange"),start_date:t(),start_time:t(),end_date:t(),end_time:t(),time_zone:u(t()),reminder:Gt}),$t=g("type",[jn,Bn,Rn,Mn]);var Qt=I([t(),P(),h(),$t,E(t()),E(we)]);var Xt=r({id:D,is_archived:h(),in_trash:h(),propertiesById:F(t(),u(Qt))}),Wt=r({id:D,is_archived:h(),in_trash:h(),properties:F(t(),u(We))});var Dn=t(),wn=r({code:Dn,message:t(),isRetryable:h()}),Jt=g("status",[r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("success"),items:E(I([Wt,Xt])),hasMore:h()}),r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("error"),error:wn})]);var Kt=r({type:i("themeChanged"),theme:ve});var An=t(),qn=r({code:An,message:t(),isRetryable:h()}),Yt=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 Zt=g("type",[Ae,Kt,It,zt,Ut,jt,Bt,Jt,Et,Mt,wt,Tt,Ft,Yt,At]);function er(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function tr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function Ke(e){let{currentBridgeProtocolVersion:o}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${o}`,isRetryable:!1}}function Ye(e){let{currentBridgeProtocolVersion:o,minBridgeProtocolVersion:n}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${o} is not supported. Minimum supported version is ${n}.`,isRetryable:!1}}function Ze(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function rr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function nr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function or(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function ir(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function sr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function ar(){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 et(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Tn=5e3,Nn=5e3,Fn=5e3;function ur(e){let{prepareInit:o,sendInitMessage:n,warn:s,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:f=Tn,initialStateTimeoutMs:y=Nn,noInitResultTimeoutMs:m=Fn,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 q(){Q!==void 0&&(window.clearTimeout(Q),Q=void 0)}function T(b){let{initializationId:v,error:G,phase:ee,source:Te}=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(),n({type:"init",initializationId:v,status:"error",error:G}),M?.({...G,phase:ee,source:Te})}async function K(b){if(S==="waitingForConnect"){S="preparingInit",j=b.initializationId,W(),L=window.setTimeout(()=>{if(S!=="preparingInit")return;let v=rr();s({...v,initializationId:b.initializationId}),T({initializationId:b.initializationId,error:v,phase:"init",source:"host"})},y);try{let v=await o(b);if(S!=="preparingInit")return;if(w(),v.status==="error"){T({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??St,blockId:v.initialState.blockId,parent:v.initialState.parent,page:v.initialState.page,currentUser:v.initialState.currentUser,manifest:v.initialState.manifest,dataSources:v.initialState.dataSources};n(G),Q=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let ee=sr();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}),T({initializationId:b.initializationId,error:Ce(),phase:"init",source:"host"})}}}function Z(b){if(S!=="stopped"&&S==="waitingForConnect"){if(!et(b.bridgeProtocolVersion)){let v=Ke({currentBridgeProtocolVersion:b.bridgeProtocolVersion});T({initializationId:b.initializationId,error:v,phase:"connect",source:"host"});return}if(b.bridgeProtocolVersion<l){let v=Ye({currentBridgeProtocolVersion:b.bridgeProtocolVersion,minBridgeProtocolVersion:l});T({initializationId:b.initializationId,error:v,phase:"connect",source:"host"});return}if(b.status==="error"){T({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&&(et(G)?G<l&&(ee=Ye({currentBridgeProtocolVersion:G,minBridgeProtocolVersion:l})):ee=Ke({currentBridgeProtocolVersion:G})),T({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(),q(),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=er();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}q(),S=b.status==="success"?"initialized":"error",b.status==="success"?c():M?.({...b.error,phase:"initResult",source:"sandbox"}),_?.(b)}function ce(){S="stopped",W(),w(),q()}return{get status(){return S},get hasConnectedSandbox(){return ae},handleConnect:Z,handleInitResult:de,handleInvalidConnect:C,handleInvalidInitResult:ue,onIframeLoad:Be,stop:ce}}function tt(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function cr(e){let o=new AbortController,n=()=>o.abort();e.signal.addEventListener("abort",n,{once:!0});let s=new Promise((l,f)=>{o.signal.addEventListener("abort",()=>f(o.signal.reason),{once:!0})});e.signal.aborted&&o.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{o.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?Un(e.sandboxOrigin,o.signal):e.getPersistedManifest({signal:o.signal}),s]);if(o.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",n)}}async function Un(e,o){let n=new URL(e);if(!tt(n)||n.origin===window.location.origin)throw new Error("Preview requires a separate loopback origin.");let s=await fetch(new URL("/manifest",n),{credentials:"omit",redirect:"error",cache:"no-store",signal:o});if(!s.ok)throw new Error(`Manifest request failed: HTTP ${s.status}.`);return s.json()}function lr(e,o){return o>=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,...gt}}}]))}}}var pr=r({theme:ve,contrastMode:u(fe),blockId:ne,parent:oe,page:me,manifest:pe,dataSources:r({bindings:le}),currentUser:ie});function fr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var mr=r({code:t(),message:t(),isRetryable:h()});var yr={type:i("connect"),initializationId:t(),bridgeProtocolVersion:P(),sdkVersion:t()},vr=g("status",[r({status:i("success"),manifest:u(pe),...yr}),r({status:i("error"),error:mr,...yr})]);var zn=g("type",[r({type:i("start")}),r({type:i("end")}),r({type:i("before"),blockId:ne}),r({type:i("after"),blockId:ne})]),Hn=g("type",[r({type:i("page_id"),page_id:D}),r({type:i("data_source_id"),data_source_id:Y})]),dr=r({type:i("createPage"),requestId:t(),parent:Hn,properties:xe,position:u(zn)});var Ln=t(),Vn=r({code:Ln,message:t(),isRetryable:h()}),hr=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:Vn})]);var gr=r({type:i("invalidHostMessage"),reason:t()});var br=R(["ascending","descending"]);var kr=U(D,ze(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),He(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),rt=I([p({contains:kr}),p({does_not_contain:kr})]),je=I([p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Oe=I([t(),E(t())]),Sr=p({object:R(["user","group"]),id:U(t(),ke(1))}),Gn=I([p({contains:Sr}),p({does_not_contain:Sr}),je]),Ir=p({object:i("user"),id:U(t(),ke(1),Me(2e3))}),$n=I([p({contains:Ir}),p({does_not_contain:Ir}),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]),Qn=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]),Xn=I([p({equals:h()}),p({does_not_equal:h()})]),Pr=I([p({equals:Oe}),p({does_not_equal:Oe}),je]),_r=R(["To-do","In progress","Complete","Current","Future"]),xr=I([_r,U(E(_r),ke(1),Me(5))]),Wn=I([p({group_equals:xr}),p({group_does_not_equal:xr})]),Jn=I([Pr,Wn]),Kn=I([p({contains:Oe}),p({contains_all:Oe}),p({does_not_contain:Oe}),je]),X=R(["start_date","end_date"]),Yn=R(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Ee=I([Yn,t()]),Zn=I([p({target:u(X),equals:Ee}),p({target:u(X),before:Ee}),p({target:u(X),after:Ee}),p({target:u(X),on_or_before:Ee}),p({target:u(X),on_or_after:Ee}),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)})]),Cr=I([p({propertyId:t(),relation:rt}),p({propertyId:t(),created_by:$n}),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:Qn}),p({propertyId:t(),checkbox:Xn}),p({propertyId:t(),select:Pr}),p({propertyId:t(),multi_select:Kn}),p({propertyId:t(),status:Jn}),p({propertyId:t(),date:Zn}),p({propertyId:t(),people:Gn})]),eo=I([Cr,p({and:E(Cr)})]),nt=10,to=p({propertyId:t(),direction:br}),Er=r({type:i("queryDataSource"),subscriptionId:t(),dataSourceId:Y,limit:P(),filter:u(eo),sorts:u(E(to))});var Or=r({type:i("resize"),height:U(P(),be(),Se(0))});var jr=r({type:i("unsubscribeDataSourceQuery"),subscriptionId:t()});var Br=r({type:i("updatePage"),requestId:t(),pageId:D,properties:u(xe),icon:u(Qe),cover:u(Xe),archived:u(h())});var Rr=g("type",[vr,hr,Er,jr,dr,Rt,Dt,qt,Nt,Br,Or,gr]);function Mr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Dr(e){let o=Mr(e);return o==="invalidHostMessage"||o==="invalidSandboxMessage"?{incomingType:o}:{incomingType:o,nack:{type:"invalidSandboxMessage",reason:ro(o)}}}function ro(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var wr=r({initializationId:t()}),no=r({bridgeProtocolVersion:I([P(),Le()])});function Ar(e){let{iframe:o,sandboxOrigin:n,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,q){c("warn",{message:"Ignored unsupported sandbox message",payload:w,issues:q});let T=Dr(w);if(T.incomingType==="connect"){let K=_e(wr,w),Z=_e(no,w);if(f({initializationId:K.success?K.output.initializationId:void 0,error:tr(),bridgeProtocolVersion:Z.success?Z.output.bridgeProtocolVersion:void 0})==="handled")return}if(T.incomingType==="initResult"){let K=_e(wr,w);y({initializationId:K.success?K.output.initializationId:void 0,error:ar()})}T.nack!==void 0&&s()!=="stopped"&&l(T.nack)}return function(q){let T=q.source===o.contentWindow,K=q.origin===n;if(!T||!K)return;let Z=_e(Rr,q.data);if(!Z.success){W(q.data,Z.issues);return}let C=Z.output;if(!fr(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 qe=class{constructor(o){this.onUnsubscribe=o}onUnsubscribe;bySubscriptionId=new Map;subscribe(o){this.unsubscribe(o.subscriptionId);let n={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(o.subscriptionId,{message:o,token:n,isRefreshing:!0,shouldRefreshAgain:!1}),n}isCurrent(o,n){return this.bySubscriptionId.get(o)?.token===n}unsubscribe(o){this.bySubscriptionId.delete(o)&&this.onUnsubscribe(o)}refresh(o){let n=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===o){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,n.push({message:c.message,token:c.token})}return s?n:void 0}finish(o,n){let s=this.bySubscriptionId.get(o);if(s?.token===n&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let o of this.bySubscriptionId.keys())this.unsubscribe(o)}};function qr(e,o){if(e===void 0)return;let n="and"in e?e.and:[e];for(let s of n){let c=oo(s,o);if(c!==void 0)return c}}function oo(e,o){if(!Object.hasOwn(o.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=o.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==n.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" 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(M=>!n.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&&!ft(rt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=io(e);if(c===void 0||n.type!==c.propertyType)return;let l=new Set(n.options.map(y=>y.name)),f=so(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 io(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 o=e.status;return"group_equals"in o||"group_does_not_equal"in o?void 0:{propertyType:"status",operator:o}}}function so(e){let o;if("equals"in e)o=e.equals;else if("does_not_equal"in e)o=e.does_not_equal;else if("contains"in e)o=e.contains;else if("contains_all"in e)o=e.contains_all;else if("does_not_contain"in e)o=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:se(e);return Array.isArray(o)?o:[o]}var ao=new Set(ht);function Tr(e,o){if(e===void 0)return;if(e.length>nt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${nt} entries.`,isRetryable:!1};let n=new Set;for(let s of e){if(n.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(n.add(s.propertyId),!Object.hasOwn(o.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=o.propertiesById[s.propertyId];if(!ao.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 Fr=5;function co(e){let{iframe:o,prepareInitialState:n,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 qe(a=>{y?.(a)});function q(a,k){f?.(a,k)}function T(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=lr(a,W);q("out",N),o.contentWindow?.postMessage(N,m)}function K(a){T(te(Ae,a))}function Z(a){T(a)}function C(a){let k=v.status;switch(k){case"initialized":T(te(Zt,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=ur({async prepareInit(a){W=a.bridgeProtocolVersion;let k=await ee;return v.status!=="preparingInit"?k:G(k)},sendInitMessage:K,warn:a=>q("warn",a),flushPendingHostStateChanges:b,minBridgeProtocolVersion:H,noConnectTimeoutMs:_,initialStateTimeoutMs:M,noInitResultTimeoutMs:S,stopHostWithFailure:st,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(pr,{...a.initialState,...L});if(V=k.manifest,L={},W<Fr&&k.page.type==="unavailable")return{status:"error",error:Ze()};let N=Ur(k.manifest,k.dataSources);return N!==void 0?{status:"error",error:N}:(ae=k.dataSources,Q=!0,{status:"success",initialState:k})}let ee=Te().catch(a=>(j.signal.aborted||q("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Ce()}));async function Te(){let a=await cr({...e,sandboxOrigin:m,signal:j.signal,onError:N=>{q("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 n({manifest:a.manifest,signal:j.signal});return k.status==="error"?k:{status:"success",initialState:{...k.initialState,manifest:a.manifest}}}let ot=Ar({iframe:o,sandboxOrigin:m,getInitStatus:()=>v.status,emit:q,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",ot),o.addEventListener("load",v.onIframeLoad);function it(){j.abort(),window.removeEventListener("message",ot),o.removeEventListener("load",v.onIframeLoad),v.stop(),w.unsubscribeAll()}function st(a){it(),q("warn",a),l?.(a)}return{stop:it,setTheme(a){ce({theme:a})},setContrastMode(a){ce({contrastMode:a})},setParent(a){ce({parent:a})},setPage(a){if(a.type==="unavailable"&&W<Fr&&(v.status==="preparingInit"&&Q||v.status==="waitingForInitResult"||v.status==="initialized")){st({...Ze(),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&&Ur(V,k)!==void 0){q("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){q("warn",`No active query exists for data source "${a}"`);return}for(let he of N)de(he.message,he.token)}}}function lo(e,o){return Object.values(e?.bindings??{}).find(n=>n.collectionPointer?.id===o)?.collectionSchema}function Ur(e,o){for(let[n,s]of Object.entries(e.dataSources)){let c=o.bindings[n];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return nr();for(let[l,f]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return or();if(c.collectionSchema.propertiesById[y]?.type!==f.type)return ir()}}}function po(e,o){return o===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,o)??Tr(e.sorts,o)}function fo(e){return te(D,e)}export{zr as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,co as createCustomBlockHost,Hr as getAutoBoundPropertyIdsByKey,tt as isLocalCustomBlockUrl,fo as toNotionPageId};
|
|
@@ -6,9 +6,10 @@ import type { notionParentSchema } from "./protocol/parent.js";
|
|
|
6
6
|
import type { notionThemeSchema } from "./protocol/theme.js";
|
|
7
7
|
import type { notionUserSchema } from "./protocol/users/user.js";
|
|
8
8
|
import type { InferInput } from "valibot";
|
|
9
|
-
import type {
|
|
9
|
+
import type { CustomBlockHostManifestOptions } from "./lifecycle/manifestOptions.js";
|
|
10
|
+
import type { CustomBlockHostDataSourcesPayload, CustomBlockHostPrepareInitialState } from "./lifecycle/types.js";
|
|
10
11
|
import type { CustomBlockHostFailure, CustomBlockHostHandlers, CustomBlockHostLogDirection } from "./messages/types.js";
|
|
11
|
-
export type CustomBlockHostOptions = {
|
|
12
|
+
export type CustomBlockHostOptions = CustomBlockHostManifestOptions & {
|
|
12
13
|
iframe: HTMLIFrameElement;
|
|
13
14
|
sandboxOrigin: string;
|
|
14
15
|
/**
|
|
@@ -20,8 +21,6 @@ export type CustomBlockHostOptions = {
|
|
|
20
21
|
noConnectTimeoutMs?: number;
|
|
21
22
|
noInitResultTimeoutMs?: number;
|
|
22
23
|
handlers: CustomBlockHostHandlers;
|
|
23
|
-
/** Called as soon as the `manifest` is available after `connect`, before `onInitialized` and binding validation. */
|
|
24
|
-
onManifest?: (manifest: CustomBlockManifest) => void;
|
|
25
24
|
/** Callback fired when the initialization handshake with the sandbox completed successfully. */
|
|
26
25
|
onInitialized?: (state: {
|
|
27
26
|
manifest: CustomBlockManifest;
|
|
@@ -37,7 +36,8 @@ export type CustomBlockHostOptions = {
|
|
|
37
36
|
/** Releases adapter resources when a query ends, including replacement and terminal errors. */
|
|
38
37
|
onQueryUnsubscribed: ((subscriptionId: string) => void) | undefined;
|
|
39
38
|
onLog?: (direction: CustomBlockHostLogDirection, payload: unknown) => void;
|
|
40
|
-
|
|
39
|
+
/** Runs once, as soon as the manifest is validated, independently of connect. */
|
|
40
|
+
prepareInitialState: CustomBlockHostPrepareInitialState;
|
|
41
41
|
initialStateTimeoutMs?: number;
|
|
42
42
|
};
|
|
43
43
|
export type CustomBlockHostHandle = {
|
|
@@ -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;
|
|
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,12 +1,12 @@
|
|
|
1
1
|
import { notionDataSourceBindingsSchema } from "./protocol/dataSources/dataSource.js";
|
|
2
2
|
import { notionDataSourceIdSchema } from "./protocol/ids.js";
|
|
3
|
-
import { manifestSchema } from "./protocol/manifest.js";
|
|
4
3
|
import { hostToSandboxMessageSchema, } from "./protocol/messages/hostToSandbox.js";
|
|
5
4
|
import { initMessageSchema, } from "./protocol/messages/init.js";
|
|
6
5
|
import { LATEST_BRIDGE_PROTOCOL_VERSION } from "./protocol/protocolVersion.js";
|
|
7
6
|
import * as v from "valibot";
|
|
8
|
-
import { contextUnavailableError, invalidPropertyBindingError, missingDataSourceBindingError, missingPropertyBindingError, } from "./lifecycle/initErrors.js";
|
|
7
|
+
import { contextUnavailableError, invalidPropertyBindingError, missingDataSourceBindingError, missingPropertyBindingError, unknownInitializationError, } from "./lifecycle/initErrors.js";
|
|
9
8
|
import { createInitializationController } from "./lifecycle/initializationController.js";
|
|
9
|
+
import { loadCustomBlockManifest } from "./lifecycle/loadCustomBlockManifest.js";
|
|
10
10
|
import { normalizeHostToSandboxMessage } from "./lifecycle/normalizeHostToSandboxMessage.js";
|
|
11
11
|
import { customBlockHostInitialStateSchema } from "./lifecycle/types.js";
|
|
12
12
|
import { createSandboxMessageRouter } from "./messages/sandboxMessageRouter.js";
|
|
@@ -19,13 +19,14 @@ import { unreachable } from "./utils.js";
|
|
|
19
19
|
// Earlier SDKs cannot represent this context, so the host reports context_unavailable.
|
|
20
20
|
const BRIDGE_PROTOCOL_VERSION_INTRODUCING_UNAVAILABLE_PAGE = 5;
|
|
21
21
|
export function createCustomBlockHost(options) {
|
|
22
|
-
const { iframe,
|
|
22
|
+
const { iframe, prepareInitialState: prepareAdapterState, handlers, onInitialized, onConnectionFailure, onLog, onQueryUnsubscribed, sandboxOrigin, minBridgeProtocolVersion: configuredMinBridgeProtocolVersion, noConnectTimeoutMs, initialStateTimeoutMs, noInitResultTimeoutMs, } = options;
|
|
23
23
|
// Callers can retire older SDKs, but cannot restore support for protocols
|
|
24
24
|
// the runtime no longer implements. Omission uses the runtime minimum.
|
|
25
25
|
const minBridgeProtocolVersion = Math.max(configuredMinBridgeProtocolVersion ??
|
|
26
26
|
MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION, MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION);
|
|
27
27
|
let pendingState = {};
|
|
28
28
|
let hasPreparedInitialState = false;
|
|
29
|
+
const preparationController = new AbortController();
|
|
29
30
|
let manifest;
|
|
30
31
|
let activeDataSources;
|
|
31
32
|
let sandboxBridgeProtocolVersion = LATEST_BRIDGE_PROTOCOL_VERSION;
|
|
@@ -190,11 +191,11 @@ export function createCustomBlockHost(options) {
|
|
|
190
191
|
const initializationController = createInitializationController({
|
|
191
192
|
async prepareInit(connect) {
|
|
192
193
|
sandboxBridgeProtocolVersion = connect.bridgeProtocolVersion;
|
|
193
|
-
const result = await
|
|
194
|
+
const result = await preparation;
|
|
194
195
|
if (initializationController.status !== "preparingInit") {
|
|
195
196
|
return result;
|
|
196
197
|
}
|
|
197
|
-
return
|
|
198
|
+
return finalizeInitialState(result);
|
|
198
199
|
},
|
|
199
200
|
sendInitMessage,
|
|
200
201
|
warn: payload => emit("warn", payload),
|
|
@@ -209,23 +210,21 @@ export function createCustomBlockHost(options) {
|
|
|
209
210
|
onInitialized?.({ manifest, initialHeight: message.initialHeight });
|
|
210
211
|
}
|
|
211
212
|
},
|
|
212
|
-
onConnectionFailure
|
|
213
|
+
onConnectionFailure: failure => {
|
|
214
|
+
preparationController.abort();
|
|
215
|
+
onConnectionFailure?.(failure);
|
|
216
|
+
},
|
|
213
217
|
});
|
|
214
|
-
function
|
|
218
|
+
function finalizeInitialState(result) {
|
|
215
219
|
if (result.status === "error") {
|
|
216
220
|
return result;
|
|
217
221
|
}
|
|
218
|
-
|
|
219
|
-
onManifest?.(manifest);
|
|
220
|
-
const initialStateInput = {
|
|
222
|
+
const initialState = v.parse(customBlockHostInitialStateSchema, {
|
|
221
223
|
...result.initialState,
|
|
222
224
|
...pendingState,
|
|
223
|
-
};
|
|
225
|
+
});
|
|
226
|
+
manifest = initialState.manifest;
|
|
224
227
|
pendingState = {};
|
|
225
|
-
const initialState = {
|
|
226
|
-
...v.parse(v.omit(customBlockHostInitialStateSchema, ["manifest"]), initialStateInput),
|
|
227
|
-
manifest,
|
|
228
|
-
};
|
|
229
228
|
if (sandboxBridgeProtocolVersion <
|
|
230
229
|
BRIDGE_PROTOCOL_VERSION_INTRODUCING_UNAVAILABLE_PAGE &&
|
|
231
230
|
initialState.page.type === "unavailable") {
|
|
@@ -245,6 +244,45 @@ export function createCustomBlockHost(options) {
|
|
|
245
244
|
hasPreparedInitialState = true;
|
|
246
245
|
return { status: "success", initialState };
|
|
247
246
|
}
|
|
247
|
+
// Attach rejection handling immediately: preparation may finish before connect.
|
|
248
|
+
const preparation = prepare().catch((error) => {
|
|
249
|
+
if (!preparationController.signal.aborted) {
|
|
250
|
+
emit("warn", {
|
|
251
|
+
message: "Failed to prepare custom block initialization",
|
|
252
|
+
error,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return { status: "error", error: unknownInitializationError() };
|
|
256
|
+
});
|
|
257
|
+
async function prepare() {
|
|
258
|
+
const loaded = await loadCustomBlockManifest({
|
|
259
|
+
...options,
|
|
260
|
+
sandboxOrigin,
|
|
261
|
+
signal: preparationController.signal,
|
|
262
|
+
onError: error => {
|
|
263
|
+
emit("warn", {
|
|
264
|
+
message: "Failed to load custom block manifest",
|
|
265
|
+
error,
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
if (loaded.status === "error") {
|
|
270
|
+
return loaded;
|
|
271
|
+
}
|
|
272
|
+
if (preparationController.signal.aborted) {
|
|
273
|
+
return { status: "error", error: unknownInitializationError() };
|
|
274
|
+
}
|
|
275
|
+
const result = await prepareAdapterState({
|
|
276
|
+
manifest: loaded.manifest,
|
|
277
|
+
signal: preparationController.signal,
|
|
278
|
+
});
|
|
279
|
+
return result.status === "error"
|
|
280
|
+
? result
|
|
281
|
+
: {
|
|
282
|
+
status: "success",
|
|
283
|
+
initialState: { ...result.initialState, manifest: loaded.manifest },
|
|
284
|
+
};
|
|
285
|
+
}
|
|
248
286
|
const onMessage = createSandboxMessageRouter({
|
|
249
287
|
iframe,
|
|
250
288
|
sandboxOrigin,
|
|
@@ -268,6 +306,7 @@ export function createCustomBlockHost(options) {
|
|
|
268
306
|
window.addEventListener("message", onMessage);
|
|
269
307
|
iframe.addEventListener("load", initializationController.onIframeLoad);
|
|
270
308
|
function stop() {
|
|
309
|
+
preparationController.abort();
|
|
271
310
|
window.removeEventListener("message", onMessage);
|
|
272
311
|
iframe.removeEventListener("load", initializationController.onIframeLoad);
|
|
273
312
|
initializationController.stop();
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAEjB,MAAM,yCAAyC,CAAA;AAGhD,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAEvD"}
|
package/dist/ids.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export type { LegacyNotionDataSourcePageBridge, NotionDataSourcePageBridge, } from "./protocol/dataSources/dataSourcePage.js";
|
|
2
|
+
export type { NotionPropertySchemasById } from "./protocol/dataSources/propertySchema.js";
|
|
1
3
|
export type { CustomBlockErrorInfo } from "./protocol/errors.js";
|
|
4
|
+
export type { NotionPageId } from "./protocol/ids.js";
|
|
5
|
+
export type { CustomBlockManifest } from "./protocol/manifest.js";
|
|
2
6
|
export type { CreatePageMessage } from "./protocol/messages/createPage.js";
|
|
3
7
|
export type { GetPageMessage } from "./protocol/messages/getPage.js";
|
|
4
8
|
export type { GetUserMessage } from "./protocol/messages/getUser.js";
|
|
@@ -8,9 +12,12 @@ export type { CustomBlockCheckboxFilterOperator, CustomBlockContainsFilterOperat
|
|
|
8
12
|
export type { ResizeMessage } from "./protocol/messages/resize.js";
|
|
9
13
|
export type { UpdatePageMessage } from "./protocol/messages/updatePage.js";
|
|
10
14
|
export type { NotionDateInput, NotionFileInput, NotionPageCover, NotionPageIcon, NotionPagePropertyReadMap, NotionPagePropertyValue, NotionPagePropertyWriteMap, NotionRichTextItem, NotionSelectOptionInput, } from "./protocol/pages/page.js";
|
|
15
|
+
export { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION } from "./protocol/protocolVersion.js";
|
|
11
16
|
export { type AutoBindableProperty, getAutoBoundPropertyIdsByKey, } from "./autoBindProperties.js";
|
|
12
17
|
export { type CustomBlockHostHandle, type CustomBlockHostOptions, createCustomBlockHost, } from "./createCustomBlockHost.js";
|
|
13
|
-
export
|
|
18
|
+
export { toNotionPageId } from "./ids.js";
|
|
19
|
+
export type { CustomBlockHostManifestOptions } from "./lifecycle/manifestOptions.js";
|
|
20
|
+
export type { ConnectSuccessMessage, CustomBlockHostDataSourcesPayload, CustomBlockHostInitialState, CustomBlockHostInitialStateResult, CustomBlockHostPreparedStateResult, CustomBlockHostPrepareInitialState, } from "./lifecycle/types.js";
|
|
14
21
|
export { isLocalCustomBlockUrl } from "./localBlockUrl.js";
|
|
15
22
|
export type { CreatePageMessageInput, CustomBlockHostCreatePageResult, CustomBlockHostFailure, CustomBlockHostGetPageResult, CustomBlockHostGetUserResult, CustomBlockHostHandlers, CustomBlockHostListUsersResult, CustomBlockHostLogDirection, CustomBlockHostOpenPageResult, CustomBlockHostUpdatePageResult, GetPageMessageInput, GetUserMessageInput, ListUsersMessageInput, OpenPageMessageInput, QueryDataSourceMessageInput, ResizeMessageInput, UpdatePageMessageInput, } from "./messages/types.js";
|
|
16
23
|
export type { CustomBlockHostQueryDataSourceResult } from "./queries/types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,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,KAAK,oBAAoB,EACzB,4BAA4B,GAC5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,qBAAqB,GACrB,MAAM,4BAA4B,CAAA;AACnC,YAAY,EACX,qBAAqB,EACrB,iCAAiC,EACjC,
|
|
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,EAAE,sCAAsC,EAAE,MAAM,qDAAqD,CAAA;AAC5G,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION } from "./protocol/protocolVersion.js";
|
|
1
2
|
export { getAutoBoundPropertyIdsByKey, } from "./autoBindProperties.js";
|
|
2
3
|
export { createCustomBlockHost, } from "./createCustomBlockHost.js";
|
|
4
|
+
export { toNotionPageId } from "./ids.js";
|
|
3
5
|
export { isLocalCustomBlockUrl } from "./localBlockUrl.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CustomBlockManifest } from "../protocol/manifest.js";
|
|
2
|
+
import type { CustomBlockInitErrorInfo } from "../protocol/messages/init.js";
|
|
3
|
+
import type { CustomBlockHostManifestOptions } from "./manifestOptions.js";
|
|
4
|
+
/** Internal to the host: preview requests never carry credentials or follow redirects. */
|
|
5
|
+
export declare function loadCustomBlockManifest(args: CustomBlockHostManifestOptions & {
|
|
6
|
+
sandboxOrigin: string;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
onError: (error: unknown) => void;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
status: "success";
|
|
11
|
+
manifest: CustomBlockManifest;
|
|
12
|
+
} | {
|
|
13
|
+
status: "error";
|
|
14
|
+
error: CustomBlockInitErrorInfo;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=loadCustomBlockManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadCustomBlockManifest.d.ts","sourceRoot":"","sources":["../../src/lifecycle/loadCustomBlockManifest.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,mBAAmB,EAExB,MAAM,8CAA8C,CAAA;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAGjG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAA;AAE1E,0FAA0F;AAC1F,wBAAsB,uBAAuB,CAC5C,IAAI,EAAE,8BAA8B,GAAG;IACtC,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,WAAW,CAAA;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACjC,GACC,OAAO,CACP;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,mBAAmB,CAAA;CAAE,GACpD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,wBAAwB,CAAA;CAAE,CACtD,CAiDA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { manifestSchema, } from "../protocol/manifest.js";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { isLocalCustomBlockUrl } from "../localBlockUrl.js";
|
|
4
|
+
/** Internal to the host: preview requests never carry credentials or follow redirects. */
|
|
5
|
+
export async function loadCustomBlockManifest(args) {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const abort = () => controller.abort();
|
|
8
|
+
args.signal.addEventListener("abort", abort, { once: true });
|
|
9
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
10
|
+
controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
|
|
11
|
+
});
|
|
12
|
+
if (args.signal.aborted) {
|
|
13
|
+
controller.abort();
|
|
14
|
+
}
|
|
15
|
+
const timeout = args.manifestSource === "local"
|
|
16
|
+
? window.setTimeout(() => {
|
|
17
|
+
controller.abort(new Error("Manifest loading timed out after 5000 ms."));
|
|
18
|
+
}, 5_000)
|
|
19
|
+
: undefined;
|
|
20
|
+
try {
|
|
21
|
+
const input = await Promise.race([
|
|
22
|
+
args.manifestSource === "local"
|
|
23
|
+
? fetchLocalCustomBlockManifest(args.sandboxOrigin, controller.signal)
|
|
24
|
+
: args.getPersistedManifest({ signal: controller.signal }),
|
|
25
|
+
cancelled,
|
|
26
|
+
]);
|
|
27
|
+
if (controller.signal.aborted) {
|
|
28
|
+
throw new Error("Manifest loading was cancelled.");
|
|
29
|
+
}
|
|
30
|
+
return { status: "success", manifest: v.parse(manifestSchema, input) };
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!args.signal.aborted) {
|
|
34
|
+
args.onError(error);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
status: "error",
|
|
38
|
+
error: {
|
|
39
|
+
code: "manifest_unavailable",
|
|
40
|
+
message: "The custom block manifest is unavailable.",
|
|
41
|
+
isRetryable: true,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
window.clearTimeout(timeout);
|
|
47
|
+
args.signal.removeEventListener("abort", abort);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function fetchLocalCustomBlockManifest(origin, signal) {
|
|
51
|
+
const url = new URL(origin);
|
|
52
|
+
if (!isLocalCustomBlockUrl(url) || url.origin === window.location.origin) {
|
|
53
|
+
throw new Error("Preview requires a separate loopback origin.");
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(new URL("/manifest", url), {
|
|
56
|
+
credentials: "omit",
|
|
57
|
+
redirect: "error",
|
|
58
|
+
cache: "no-store",
|
|
59
|
+
signal,
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`Manifest request failed: HTTP ${response.status}.`);
|
|
63
|
+
}
|
|
64
|
+
return response.json();
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { manifestSchema } from "../protocol/manifest.js";
|
|
2
|
+
import type { InferInput } from "valibot";
|
|
3
|
+
/** Selects the manifest source used during host initialization. */
|
|
4
|
+
export type CustomBlockHostManifestOptions = {
|
|
5
|
+
/** Calls getPersistedManifest for a saved definition or worker registry manifest. */
|
|
6
|
+
manifestSource: "persisted";
|
|
7
|
+
getPersistedManifest: (args: {
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
}) => Promise<InferInput<typeof manifestSchema> | undefined>;
|
|
10
|
+
} | {
|
|
11
|
+
/**
|
|
12
|
+
* Fetches /manifest from the loopback sandboxOrigin. No persisted fallback.
|
|
13
|
+
* Local refers to the manifest server, not the host's environment.
|
|
14
|
+
*/
|
|
15
|
+
manifestSource: "local";
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=manifestOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifestOptions.d.ts","sourceRoot":"","sources":["../../src/lifecycle/manifestOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,mEAAmE;AACnE,MAAM,MAAM,8BAA8B,GACvC;IACA,qFAAqF;IACrF,cAAc,EAAE,WAAW,CAAA;IAC3B,oBAAoB,EAAE,CAAC,IAAI,EAAE;QAC5B,MAAM,EAAE,WAAW,CAAA;KACnB,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG,SAAS,CAAC,CAAA;CAC3D,GACD;IACA;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAA;CACtB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notionDataSourceBindingsSchema } from "../protocol/dataSources/dataSource.js";
|
|
2
|
+
import { type CustomBlockManifest } from "../protocol/manifest.js";
|
|
2
3
|
import type { ConnectMessage } from "../protocol/messages/connect.js";
|
|
3
4
|
import type { CustomBlockInitErrorInfo } from "../protocol/messages/init.js";
|
|
4
5
|
import * as v from "valibot";
|
|
@@ -9,7 +10,7 @@ export type ConnectSuccessMessage = Extract<ConnectMessage, {
|
|
|
9
10
|
export type InitStatus =
|
|
10
11
|
/** The host is waiting for the sandbox's first `connect` message. */
|
|
11
12
|
"waitingForConnect"
|
|
12
|
-
/** The host is waiting for
|
|
13
|
+
/** The host is waiting for host state preparation to complete `init`. */
|
|
13
14
|
| "preparingInit"
|
|
14
15
|
/** The host is waiting for a matching `initResult` after it sends `init`. */
|
|
15
16
|
| "waitingForInitResult"
|
|
@@ -267,5 +268,16 @@ export type CustomBlockHostInitialStateResult = {
|
|
|
267
268
|
status: "error";
|
|
268
269
|
error: CustomBlockInitErrorInfo;
|
|
269
270
|
};
|
|
270
|
-
|
|
271
|
+
/** Adapter-owned state; the runtime adds its selected manifest to init. */
|
|
272
|
+
export type CustomBlockHostPreparedStateResult = {
|
|
273
|
+
status: "success";
|
|
274
|
+
initialState: Omit<CustomBlockHostInitialState, "manifest">;
|
|
275
|
+
} | {
|
|
276
|
+
status: "error";
|
|
277
|
+
error: CustomBlockInitErrorInfo;
|
|
278
|
+
};
|
|
279
|
+
export type CustomBlockHostPrepareInitialState = (args: {
|
|
280
|
+
manifest: CustomBlockManifest;
|
|
281
|
+
signal: AbortSignal;
|
|
282
|
+
}) => Promise<CustomBlockHostPreparedStateResult>;
|
|
271
283
|
//# sourceMappingURL=types.d.ts.map
|