@notionhq/custom-blocks-host 0.2.21 → 0.3.1
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/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- 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/package.json +1 -1
- package/src/createCustomBlockHost.ts +64 -23
- package/src/index.ts +4 -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
|
-
var Nr=6;function Fr(e){let{manifestProperties:o,propertySchemasById:n}=e,s=[];for(let[c,l]of Object.entries(o)){let f=Ur({propertyKey:c,manifestProperty:l,propertySchemasById:n});f!==void 0&&s.push([c,f])}return Object.fromEntries(s)}function Ur(e){let{propertyKey:o,manifestProperty:n,propertySchemasById:s}=e,c=nt(n.name),l=Object.entries(s).filter(([f,y])=>y.type===n.type&&(f===o||nt(y.name)===c));return l.length===1?l[0][0]:void 0}function nt(e){return e.trim().toLowerCase()}var Re,zr={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Ne(e){return!e&&!Re?zr:{lang:e?.lang??Re?.lang,message:e?.message,abortEarly:e?.abortEarly??Re?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Re?.abortPipeEarly}}var Hr;function Lr(e){return Hr?.get(e)}var Gr;function Vr(e){return Gr?.get(e)}var $r;function Qr(e,o){return $r?.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},I=e.kind==="schema",_=c?.message??e.message??Qr(e.reference,m.lang)??(I?Vr(m.lang):null)??s.message??Lr(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),I&&(n.typed=!1),n.issues?n.issues.push(m):n.issues=[m]}var ot=new WeakMap;function H(e){let o=ot.get(e);return o||(o={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},Ne())}},ot.set(e,o)),o}function Xr(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 Wr=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 Se(e,o){return{kind:"validation",type:"min_length",reference:Se,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_value",reference:ke,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 st={abortEarly:!0};function ut(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 at(e,o){return!e["~run"]({value:o},st).issues}function O(e,o){return{kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:o,get"~standard"(){return H(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 I of y.issues)I.path?I.path.unshift(m):I.path=[m],n.issues?.push(I);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 h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return H(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 H(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 H(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 H(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 H(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 H(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 I={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(I):_.path=[I],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]=ut(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 H(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 H(this)},"~run"(n,s){return this.options.includes(n.value)?n.typed=!0:j(this,"type",n,s),n}}}function N(e,o,n){return{kind:"schema",type:"record",reference:N,expects:"Object",async:!1,key:e,value:o,message:n,get"~standard"(){return H(this)},"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let f in l)if(Xr(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 R of m.issues)R.path=[_],s.issues?.push(R);if(s.issues||(s.issues=m.issues),c.abortEarly){s.typed=!1;break}}let I=this.value["~run"]({value:y},c);if(I.issues){let _={type:"object",origin:"value",input:l,key:f,value:y};for(let R of I.issues)R.path?R.path.unshift(_):R.path=[_],s.issues?.push(R);if(s.issues||(s.issues=I.issues),c.abortEarly){s.typed=!1;break}}(!m.typed||!I.typed)&&(s.typed=!1),m.typed&&(s.value[m.value]=I.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 H(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 I={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(I):_.path=[I],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]=ut(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 H(this)},"~run"(o,n){return typeof o.value=="string"?o.typed=!0:j(this,"type",o,n),o}}}function it(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 k(e,o){return{kind:"schema",type:"union",reference:k,expects:Fe(e.map(n=>n.expects),"|"),async:!1,options:e,message:o,get"~standard"(){return H(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:it(l)}),n.typed=!0}else{if(f?.length===1)return f[0];j(this,"type",n,s,{issues:it(f)})}return n}}}function Ie(){return{kind:"schema",type:"unknown",reference:Ie,expects:"unknown",async:!1,get"~standard"(){return H(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 H(this)},"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let f,y=0,m=this.key,I=[],_=(R,S)=>{for(let G of R.options){if(G.type==="variant")_(G,new Set(S).add(G.key));else{let J=!0,F=0;for(let M of S){let U=G.entries[M];if(M in l?U["~run"]({typed:!1,value:l[M]},st).issues:U.type!=="exact_optional"&&U.type!=="optional"&&U.type!=="nullish"){J=!1,m!==M&&(y<F||y===F&&M in l&&!(m in l))&&(y=F,m=M,I=[]),m===M&&I.push(G.entries[M].expects);break}F++}if(J){let M=G["~run"]({value:l},c);(!f||!f.typed&&M.typed)&&(f=M)}}if(f&&!f.issues)break}};if(_(this,new Set([this.key])),f)return f;j(this,"type",s,c,{input:l[m],expected:Fe(I,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else j(this,"type",s,c);return s}}}function ct(e,o){let n={...e.entries};for(let s of o)delete n[s];return{...e,entries:n,get"~standard"(){return H(this)}}}function re(e,o,n){let s=e["~run"]({value:o},Ne(n));if(s.issues)throw new Wr(s.issues);return s.value}function L(...e){return{...e[0],pipe:e,get"~standard"(){return H(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 ne=L(t(),te("NotionBlockId")),Z=L(t(),te("NotionDataSourceId")),D=L(t(),te("NotionPageId")),lt=L(t(),te("NotionAgentId")),pt=L(t(),te("NotionSpaceId"));var ft=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(ft),description:u(t())}),Jr=r({id:t(),name:t(),color:u(ft),option_ids:O(t())}),Kr=r({synced_property_id:t(),synced_property_name:t()}),E=r({name:t(),description:u(t())}),Yr=["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"],mt=B(Yr),yt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Ge=g("type",[r({...E.entries,type:i("title")}),r({...E.entries,type:i("rich_text")}),r({...E.entries,type:i("number")}),r({...E.entries,type:i("checkbox")}),r({...E.entries,type:i("url")}),r({...E.entries,type:i("email")}),r({...E.entries,type:i("phone_number")}),r({...E.entries,type:i("select"),options:O(Le)}),r({...E.entries,type:i("multi_select"),options:O(Le)}),r({...E.entries,type:i("status"),options:O(Le),groups:O(Jr)}),r({...E.entries,type:i("date")}),r({...E.entries,type:i("people")}),r({...E.entries,type:i("files")}),r({...E.entries,type:i("unique_id")}),r({...E.entries,type:i("relation"),data_source_id:u(t()),dual_property:u(Kr)}),r({...E.entries,type:i("place")}),r({...E.entries,type:i("formula")}),r({...E.entries,type:i("rollup")}),r({...E.entries,type:i("button")}),r({...E.entries,type:i("verification")}),r({...E.entries,type:i("last_visited_time")}),r({...E.entries,type:i("location")}),r({...E.entries,type:i("created_time")}),r({...E.entries,type:i("last_edited_time")}),r({...E.entries,type:i("created_by")}),r({...E.entries,type:i("last_edited_by")})]);var vt={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 dt=r({id:Z,table:t(),spaceId:u(pt)}),ht=r({id:u(Z),propertiesById:N(t(),Ge)}),go=r({key:t(),collectionPointer:u(dt),collectionSchema:u(ht),propertyIdsByKey:N(t(),u(t())),propertySchemasById:N(t(),Ge)}),Zr=r({collectionPointer:u(dt),collectionSchema:u(ht),propertyIdsByKey:u(N(t(),u(t())))}),pe=N(t(),Zr);var en=g("type",[r({type:i("emoji"),emoji:t()}),r({type:i("external"),url:t()})]),tn=r({name:t(),description:u(t()),type:mt}),rn=r({name:t(),description:u(t()),icon:u(en),properties:u(N(t(),tn),{})}),fe=r({version:i(1),name:u(t()),description:u(t()),slashCommand:u(t()),icon:u(r({type:i("emoji"),emoji:t()})),dataSources:u(N(t(),rn),{})});var me=B(["standard","high"]),gt="standard";var bt=r({type:i("contrastModeChanged"),contrastMode:me});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:Z}),r({type:i("workspace"),workspace:i(!0)}),r({type:i("block_id"),block_id:ne}),r({type:i("agent_id"),agent_id:lt}),r({type:i("unavailable")})]);var ye=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())})}),It=r({type:i("external"),external:r({url:t()})}),_t=r({type:i("file"),file:r({url:t(),expiry_time:u(t())})}),$e=g("type",[nn,on,It,_t]),Qe=g("type",[It,_t]),$=W(t()),St=N(t(),Ie()),Ve=k([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($)}),un=k([r({object:u(i("user")),id:t()}),r({object:i("group"),id:t(),name:u($)})]),an=r({id:t()}),cn=k([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()},kt=W(r({...we.entries,table:B(["notion_user","bot","organization_bot"]),spaceId:u(t())})),Xe=g("type",[r({...A,type:i("title"),title:O(St)}),r({...A,type:i("rich_text"),rich_text:O(St)}),r({...A,type:i("number"),number:W(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:W(Ve)}),r({...A,type:i("status"),status:W(Ve)}),r({...A,type:i("multi_select"),multi_select:O(Ve)}),r({...A,type:i("date"),date:W(sn)}),r({...A,type:i("people"),people:O(un)}),r({...A,type:i("relation"),has_more:u(h()),relation:O(an)}),r({...A,type:i("files"),files:O(cn)}),r({...A,type:i("place"),place:W(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:kt}),r({...A,type:i("last_edited_by"),last_edited_by:kt}),r({...A,type:i("last_visited_time"),last_visited_time:$})]),xe=N(t(),Xe),ve=r({object:i("page"),id:D,parent:oe,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:h(),in_trash:h()});var pn=t(),fn=r({code:pn,message:t(),isRetryable:h()}),xt=g("status",[r({type:i("createPageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("createPageResult"),requestId:t(),status:i("error"),error:fn})]);var We=L(t(),te("NotionUserId")),ie=r({object:i("user"),id:We,name:u(t()),avatar_url:W(t()),type:i("person"),person:r({email:t()})}),Ct=r({object:i("list"),results:O(ie),next_cursor:W(t()),has_more:h(),type:i("user"),user:N(t(),Ie())});var Pt=r({type:i("currentUserChanged"),currentUser:ie});var Ot=r({type:i("dataSourcesChanged"),dataSources:r({bindings:pe})});var mn=t(),yn=r({code:mn,message:t(),isRetryable:h()}),Et=r({type:i("getPage"),requestId:t(),pageId:D}),jt=g("status",[r({type:i("getPageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("getPageResult"),requestId:t(),status:i("error"),error:yn})]);var vn=t(),dn=r({code:vn,message:t(),isRetryable:h()}),Bt=r({type:i("getUser"),requestId:t(),userId:We}),Rt=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 de=B(["light","dark"]);var hn=t(),gn=r({code:hn,message:t(),isRetryable:h()});var Ae=g("status",[r({type:i("init"),initializationId:t(),status:i("success"),theme:de,contrastMode:me,blockId:ne,parent:oe,page:ye,manifest:fe,dataSources:r({bindings:pe}),currentUser:ie}),r({type:i("init"),initializationId:t(),status:i("error"),error:gn})]);var Mt=r({type:i("invalidSandboxMessage"),reason:t()});var bn=t(),Sn=r({code:bn,message:t(),isRetryable:h()}),Dt=r({type:i("listUsers"),requestId:t(),startCursor:u(t()),pageSize:u(P())}),wt=g("status",[r({type:i("listUsersResult"),requestId:t(),status:i("success"),list:Ct}),r({type:i("listUsersResult"),requestId:t(),status:i("error"),error:Sn})]);var kn=B(["side_peek","center_peek"]),In=t(),_n=r({code:In,message:t(),isRetryable:h()}),At=r({type:i("openPage"),requestId:t(),pageId:D,mode:kn}),qt=g("status",[r({type:i("openPageResult"),requestId:t(),status:i("success"),pageId:D}),r({type:i("openPageResult"),requestId:t(),status:i("error"),error:_n})]);var Tt=r({type:i("pageChanged"),page:ye});var Nt=r({type:i("parentChanged"),parent:oe});var Ft=r({unit:B(["year","month","week","day"]),value:P(),time:t(),defaultTimeZone:u(t())}),xn=r({unit:B(["hour","minute"]),value:P()}),Ut=r({unit:i("none")}),Cn=k([Ft,xn]),zt=u(k([Ft,Ut])),Ht=u(k([Cn,Ut])),Pn=r({type:i("date"),start_date:t(),reminder:zt}),On=r({type:i("daterange"),start_date:t(),end_date:t(),reminder:zt}),En=r({type:i("datetime"),start_date:t(),start_time:t(),time_zone:u(t()),reminder:Ht}),jn=r({type:i("datetimerange"),start_date:t(),start_time:t(),end_date:t(),end_time:t(),time_zone:u(t()),reminder:Ht}),Lt=g("type",[Pn,On,En,jn]);var Gt=k([t(),P(),h(),Lt,O(t()),O(we)]);var Vt=r({id:D,is_archived:h(),in_trash:h(),propertiesById:N(t(),u(Gt))}),$t=r({id:D,is_archived:h(),in_trash:h(),properties:N(t(),u(Xe))});var Bn=t(),Rn=r({code:Bn,message:t(),isRetryable:h()}),Qt=g("status",[r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("success"),items:O(k([$t,Vt])),hasMore:h()}),r({type:i("queryDataSourceResult"),subscriptionId:t(),status:i("error"),error:Rn})]);var Xt=r({type:i("themeChanged"),theme:de});var Mn=t(),Dn=r({code:Mn,message:t(),isRetryable:h()}),Wt=g("status",[r({type:i("updatePageResult"),requestId:t(),status:i("success"),page:ve}),r({type:i("updatePageResult"),requestId:t(),status:i("error"),error:Dn})]);var Jt=g("type",[Ae,Xt,bt,Nt,Tt,Pt,Ot,Qt,xt,jt,Rt,wt,qt,Wt,Mt]);function Kt(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function Yt(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function Je(e){let{currentBridgeProtocolVersion:o}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${o}`,isRetryable:!1}}function Ke(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 Ye(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Zt(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function er(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function tr(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function rr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function nr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function or(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function ir(){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 Ze(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var wn=5e3,An=5e3,qn=5e3;function sr(e){let{prepareInit:o,sendInitMessage:n,warn:s,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:f=wn,initialStateTimeoutMs:y=An,noInitResultTimeoutMs:m=qn,stopHostWithFailure:I,onInitResult:_,onConnectionFailure:R}=e,S="waitingForConnect",G,J,F,M,U=!1,ue=!1;function X(){G!==void 0&&(window.clearTimeout(G),G=void 0)}function w(){J!==void 0&&(window.clearTimeout(J),J=void 0)}function z(){F!==void 0&&(window.clearTimeout(F),F=void 0)}function T(b){let{initializationId:v,error:V,phase:Y,source:Be}=b;switch(S){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return se(S)}S="error",M=v,X(),w(),n({type:"init",initializationId:v,status:"error",error:V}),R?.({...V,phase:Y,source:Be})}async function K(b){if(S==="waitingForConnect"){S="preparingInit",M=b.initializationId,X(),J=window.setTimeout(()=>{if(S!=="preparingInit")return;let v=Zt();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 V={type:"init",initializationId:b.initializationId,status:"success",theme:v.initialState.theme,contrastMode:v.initialState.contrastMode??gt,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),F=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let Y=nr();R?.({...Y,phase:"initResult",source:"host"}),s({...Y,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:ir(),phase:"init",source:"host"})}}}function ee(b){if(S!=="stopped"&&S==="waitingForConnect"){if(!Ze(b.bridgeProtocolVersion)){let v=Je({currentBridgeProtocolVersion:b.bridgeProtocolVersion});T({initializationId:b.initializationId,error:v,phase:"connect",source:"host"});return}if(b.bridgeProtocolVersion<l){let v=Ke({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}ue=!0,K(b)}}function x(b){if(S==="stopped"||S!=="waitingForConnect")return"handled";let{initializationId:v,bridgeProtocolVersion:V}=b;if(v===void 0)return"nack";let Y=b.error;return V!==void 0&&(Ze(V)?V<l&&(Y=Ke({currentBridgeProtocolVersion:V,minBridgeProtocolVersion:l})):Y=Je({currentBridgeProtocolVersion:V})),T({initializationId:v,error:Y,phase:"connect",source:"host"}),"handled"}function ae(b){let{initializationId:v,error:V}=b;S!=="waitingForInitResult"||v===void 0||v!==M||(X(),z(),S="error",s(V),R?.({...V,phase:"initResult",source:"host"}))}function je(){if(S!=="stopped"){if(U){I({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}U=!0,X(),S==="waitingForConnect"&&(G=window.setTimeout(()=>{if(S!=="waitingForConnect")return;S="error";let b=Kt();s(b),R?.({...b,phase:"connect",source:"host"})},f))}}function he(b){if(S!=="waitingForInitResult"||b.initializationId!==M){s({message:"Ignored stale or unexpected initResult",payload:b});return}z(),S=b.status==="success"?"initialized":"error",b.status==="success"?c():R?.({...b.error,phase:"initResult",source:"sandbox"}),_?.(b)}function ce(){S="stopped",X(),w(),z()}return{get status(){return S},get hasConnectedSandbox(){return ue},handleConnect:ee,handleInitResult:he,handleInvalidConnect:x,handleInvalidInitResult:ae,onIframeLoad:je,stop:ce}}function ur(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,...vt}}}]))}}}var ar=r({theme:de,contrastMode:u(me),blockId:ne,parent:oe,page:ye,manifest:fe,dataSources:r({bindings:pe}),currentUser:ie});function cr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var lr=r({code:t(),message:t(),isRetryable:h()});var pr={type:i("connect"),initializationId:t(),bridgeProtocolVersion:P(),sdkVersion:t()},fr=g("status",[r({status:i("success"),manifest:u(fe),...pr}),r({status:i("error"),error:lr,...pr})]);var Tn=g("type",[r({type:i("start")}),r({type:i("end")}),r({type:i("before"),blockId:ne}),r({type:i("after"),blockId:ne})]),Nn=g("type",[r({type:i("page_id"),page_id:D}),r({type:i("data_source_id"),data_source_id:Z})]),mr=r({type:i("createPage"),requestId:t(),parent:Nn,properties:xe,position:u(Tn)});var Fn=t(),Un=r({code:Fn,message:t(),isRetryable:h()}),yr=g("status",[r({type:i("initResult"),initializationId:t(),status:i("success"),initialHeight:u(L(P(),be(),ke(0)))}),r({type:i("initResult"),initializationId:t(),status:i("error"),error:Un})]);var vr=r({type:i("invalidHostMessage"),reason:t()});var dr=B(["ascending","descending"]);var hr=L(D,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"))),et=k([p({contains:hr}),p({does_not_contain:hr})]),Ee=k([p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Oe=k([t(),O(t())]),gr=p({object:B(["user","group"]),id:L(t(),Se(1))}),zn=k([p({contains:gr}),p({does_not_contain:gr}),Ee]),br=p({object:i("user"),id:L(t(),Se(1),Me(2e3))}),Hn=k([p({contains:br}),p({does_not_contain:br}),p({is_empty:i(!0)}),p({is_not_empty:i(!0)})]),Ce=k([p({equals:t()}),p({does_not_equal:t()}),p({contains:t()}),p({does_not_contain:t()}),p({starts_with:t()}),p({ends_with:t()}),Ee]),Ln=k([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()}),Ee]),Gn=k([p({equals:h()}),p({does_not_equal:h()})]),_r=k([p({equals:Oe}),p({does_not_equal:Oe}),Ee]),Sr=B(["To-do","In progress","Complete","Current","Future"]),kr=k([Sr,L(O(Sr),Se(1),Me(5))]),Vn=k([p({group_equals:kr}),p({group_does_not_equal:kr})]),$n=k([_r,Vn]),Qn=k([p({contains:Oe}),p({contains_all:Oe}),p({does_not_contain:Oe}),Ee]),Q=B(["start_date","end_date"]),Xn=B(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Pe=k([Xn,t()]),Wn=k([p({target:u(Q),equals:Pe}),p({target:u(Q),before:Pe}),p({target:u(Q),after:Pe}),p({target:u(Q),on_or_before:Pe}),p({target:u(Q),on_or_after:Pe}),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)})]),Ir=k([p({propertyId:t(),relation:et}),p({propertyId:t(),created_by:Hn}),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:Ln}),p({propertyId:t(),checkbox:Gn}),p({propertyId:t(),select:_r}),p({propertyId:t(),multi_select:Qn}),p({propertyId:t(),status:$n}),p({propertyId:t(),date:Wn}),p({propertyId:t(),people:zn})]),Jn=k([Ir,p({and:O(Ir)})]),tt=10,Kn=p({propertyId:t(),direction:dr}),xr=r({type:i("queryDataSource"),subscriptionId:t(),dataSourceId:Z,limit:P(),filter:u(Jn),sorts:u(O(Kn))});var Cr=r({type:i("resize"),height:L(P(),be(),ke(0))});var Pr=r({type:i("unsubscribeDataSourceQuery"),subscriptionId:t()});var Or=r({type:i("updatePage"),requestId:t(),pageId:D,properties:u(xe),icon:u($e),cover:u(Qe),archived:u(h())});var Er=g("type",[fr,yr,xr,Pr,mr,Et,Bt,Dt,At,Or,Cr,vr]);function jr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Br(e){let o=jr(e);return o==="invalidHostMessage"||o==="invalidSandboxMessage"?{incomingType:o}:{incomingType:o,nack:{type:"invalidSandboxMessage",reason:Yn(o)}}}function Yn(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var Rr=r({initializationId:t()}),Zn=r({bridgeProtocolVersion:k([P(),He()])});function Mr(e){let{iframe:o,sandboxOrigin:n,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:f,onInvalidInitResult:y,onConnect:m,onInitResult:I,onQueryDataSource:_,onUnsubscribeDataSourceQuery:R,onCreatePage:S,onGetPage:G,onOpenPage:J,onGetUser:F,onListUsers:M,onUpdatePage:U,onResize:ue}=e;function X(w,z){c("warn",{message:"Ignored unsupported sandbox message",payload:w,issues:z});let T=Br(w);if(T.incomingType==="connect"){let K=_e(Rr,w),ee=_e(Zn,w);if(f({initializationId:K.success?K.output.initializationId:void 0,error:Yt(),bridgeProtocolVersion:ee.success?ee.output.bridgeProtocolVersion:void 0})==="handled")return}if(T.incomingType==="initResult"){let K=_e(Rr,w);y({initializationId:K.success?K.output.initializationId:void 0,error:or()})}T.nack!==void 0&&s()!=="stopped"&&l(T.nack)}return function(z){let T=z.source===o.contentWindow,K=z.origin===n;if(!T||!K)return;let ee=_e(Er,z.data);if(!ee.success){X(z.data,ee.issues);return}let x=ee.output;if(!cr(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":I(x);return;case"queryDataSource":_(x);return;case"unsubscribeDataSourceQuery":R(x);return;case"createPage":S(x);return;case"openPage":J(x);return;case"getPage":G(x);return;case"getUser":F(x);return;case"listUsers":M(x);return;case"updatePage":U(x);return;case"resize":ue(x);return;case"invalidHostMessage":return;default:se(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 Dr(e,o){if(e===void 0)return;let n="and"in e?e.and:[e];for(let s of n){let c=eo(s,o);if(c!==void 0)return c}}function eo(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(R=>!n.groups.some(S=>S.name===R));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!at(et,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=to(e);if(c===void 0||n.type!==c.propertyType)return;let l=new Set(n.options.map(y=>y.name)),f=ro(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 to(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 ro(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 no=new Set(yt);function wr(e,o){if(e===void 0)return;if(e.length>tt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${tt} 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(!no.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 qr=5;function io(e){let{iframe:o,getInitialState:n,handlers:s,onManifest:c,onInitialized:l,onConnectionFailure:f,onLog:y,onQueryUnsubscribed:m,sandboxOrigin:I,minBridgeProtocolVersion:_,noConnectTimeoutMs:R,initialStateTimeoutMs:S,noInitResultTimeoutMs:G}=e,J=Math.max(_??3,3),F={},M=!1,U,ue,X=6,w=new qe(a=>{m?.(a)});function z(a,C){y?.(a,C)}function T(a){let C=v.status;switch(C){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return se(C)}let q=ur(a,X);z("out",q),o.contentWindow?.postMessage(q,I)}function K(a){T(re(Ae,a))}function ee(a){T(a)}function x(a){let C=v.status;switch(C){case"initialized":T(re(Jt,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:se(C)}}async function ae(a,C){if(C===void 0)return;let q=await C(a);x({type:`${a.type}Result`,requestId:a.requestId,...q})}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=w.subscribe(a)){try{let q=so(ue,a.dataSourceId),le=uo(a,q);if(le!==void 0){w.isCurrent(a.subscriptionId,C)&&(w.unsubscribe(a.subscriptionId),je({subscriptionId:a.subscriptionId,response:{status:"error",error:le}}));return}let Te=await s.queryDataSource(a);if(!w.isCurrent(a.subscriptionId,C))return;Te.status==="error"&&!Te.error.isRetryable&&w.unsubscribe(a.subscriptionId),je({subscriptionId:a.subscriptionId,response:Te})}finally{let q=w.finish(a.subscriptionId,C);q!==void 0&&he(q.message,q.token)}}function ce(a){v.status==="stopped"||v.status==="error"||(Object.assign(F,a),b())}function b(){if(v.status!=="initialized")return;let a=F;F={},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=sr({async prepareInit(a){X=a.bridgeProtocolVersion;let C=await n(a);return v.status!=="preparingInit"?C:V(C)},sendInitMessage:K,warn:a=>z("warn",a),flushPendingHostStateChanges:b,minBridgeProtocolVersion:J,noConnectTimeoutMs:R,initialStateTimeoutMs:S,noInitResultTimeoutMs:G,stopHostWithFailure:rt,onInitResult(a){a.status==="success"&&U!==void 0&&l?.({manifest:U,initialHeight:a.initialHeight})},onConnectionFailure:f});function V(a){if(a.status==="error")return a;U=re(fe,a.initialState.manifest),c?.(U);let C={...a.initialState,...F};F={};let q={...re(ct(ar,["manifest"]),C),manifest:U};if(X<qr&&q.page.type==="unavailable")return{status:"error",error:Ye()};let le=Tr(q.manifest,q.dataSources);return le!==void 0?{status:"error",error:le}:(ue=q.dataSources,M=!0,{status:"success",initialState:q})}let Y=Mr({iframe:o,sandboxOrigin:I,getInitStatus:()=>v.status,emit:z,sendNack:ee,onInvalidConnect:v.handleInvalidConnect,onInvalidInitResult:v.handleInvalidInitResult,onConnect:v.handleConnect,onInitResult:v.handleInitResult,onQueryDataSource:he,onUnsubscribeDataSourceQuery:a=>w.unsubscribe(a.subscriptionId),onCreatePage:a=>ae(a,s.createPage),onGetPage:a=>ae(a,s.getPage),onOpenPage:a=>ae(a,s.openPage),onGetUser:a=>ae(a,s.getUser),onListUsers:a=>ae(a,s.listUsers),onUpdatePage:a=>ae(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",Y),o.addEventListener("load",v.onIframeLoad);function Be(){window.removeEventListener("message",Y),o.removeEventListener("load",v.onIframeLoad),v.stop(),w.unsubscribeAll()}function rt(a){Be(),z("warn",a),f?.(a)}return{stop:Be,setTheme(a){ce({theme:a})},setContrastMode(a){ce({contrastMode:a})},setParent(a){ce({parent:a})},setPage(a){if(a.type==="unavailable"&&X<qr&&(v.status==="preparingInit"&&M||v.status==="waitingForInitResult"||v.status==="initialized")){rt({...Ye(),phase:"runtime",source:"host"});return}ce({page:a})},setCurrentUser(a){ce({currentUser:a})},setDataSources(a){let C={bindings:re(pe,a.bindings)};if(v.hasConnectedSandbox&&U!==void 0&&Tr(U,C)!==void 0){z("warn",{message:"Ignored invalid data source bindings update",payload:C});return}ue=C,ce({dataSources:C})},refreshQuery({dataSourceId:a}){if(v.status!=="initialized")return;let C=re(Z,a),q=w.refresh(C);if(q===void 0){z("warn",`No active query exists for data source "${a}"`);return}for(let le of q)he(le.message,le.token)}}}function so(e,o){return Object.values(e?.bindings??{}).find(n=>n.collectionPointer?.id===o)?.collectionSchema}function Tr(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 er();for(let[l,f]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return tr();if(c.collectionSchema.propertiesById[y]?.type!==f.type)return rr()}}}function uo(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}:Dr(e.filter,o)??wr(e.sorts,o)}function ao(e){return re(D,e)}function co(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{Nr as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,io as createCustomBlockHost,Fr as getAutoBoundPropertyIdsByKey,co as isLocalCustomBlockUrl,ao as toNotionPageId};
|
|
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/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type { LegacyNotionDataSourcePageBridge, NotionDataSourcePageBridge, } fr
|
|
|
2
2
|
export type { NotionPropertySchemasById } from "./protocol/dataSources/propertySchema.js";
|
|
3
3
|
export type { CustomBlockErrorInfo } from "./protocol/errors.js";
|
|
4
4
|
export type { NotionPageId } from "./protocol/ids.js";
|
|
5
|
+
export type { CustomBlockManifest } from "./protocol/manifest.js";
|
|
5
6
|
export type { CreatePageMessage } from "./protocol/messages/createPage.js";
|
|
6
7
|
export type { GetPageMessage } from "./protocol/messages/getPage.js";
|
|
7
8
|
export type { GetUserMessage } from "./protocol/messages/getUser.js";
|
|
@@ -15,7 +16,8 @@ export { LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION } from "./protocol/protocolVersi
|
|
|
15
16
|
export { type AutoBindableProperty, getAutoBoundPropertyIdsByKey, } from "./autoBindProperties.js";
|
|
16
17
|
export { type CustomBlockHostHandle, type CustomBlockHostOptions, createCustomBlockHost, } from "./createCustomBlockHost.js";
|
|
17
18
|
export { toNotionPageId } from "./ids.js";
|
|
18
|
-
export type {
|
|
19
|
+
export type { CustomBlockHostManifestOptions } from "./lifecycle/manifestOptions.js";
|
|
20
|
+
export type { ConnectSuccessMessage, CustomBlockHostDataSourcesPayload, CustomBlockHostInitialState, CustomBlockHostInitialStateResult, CustomBlockHostPreparedStateResult, CustomBlockHostPrepareInitialState, } from "./lifecycle/types.js";
|
|
19
21
|
export { isLocalCustomBlockUrl } from "./localBlockUrl.js";
|
|
20
22
|
export type { CreatePageMessageInput, CustomBlockHostCreatePageResult, CustomBlockHostFailure, CustomBlockHostGetPageResult, CustomBlockHostGetUserResult, CustomBlockHostHandlers, CustomBlockHostListUsersResult, CustomBlockHostLogDirection, CustomBlockHostOpenPageResult, CustomBlockHostUpdatePageResult, GetPageMessageInput, GetUserMessageInput, ListUsersMessageInput, OpenPageMessageInput, QueryDataSourceMessageInput, ResizeMessageInput, UpdatePageMessageInput, } from "./messages/types.js";
|
|
21
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,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,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,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"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lifecycle/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4DAA4D,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lifecycle/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4DAA4D,CAAA;AAE3G,OAAO,EACN,KAAK,mBAAmB,EAExB,MAAM,8CAA8C,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAKjG,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAC1C,cAAc,EACd;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CACrB,CAAA;AAED,gEAAgE;AAChE,MAAM,MAAM,UAAU;AACrB,qEAAqE;AACnE,mBAAmB;AACrB,yEAAyE;GACvE,eAAe;AACjB,6EAA6E;GAC3E,sBAAsB;AACxB,yDAAyD;GACvD,aAAa;AACf,gFAAgF;GAC9E,OAAO;AACT,2EAA2E;GACzE,SAAS,CAAA;AAEZ,MAAM,MAAM,iCAAiC,GAAG;IAC/C,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAA;CAC7D,CAAA;AAED,MAAM,MAAM,2CAA2C,GAAG;IACzD,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,OAAO,8BAA8B,CAAC,CAAA;CAC9D,CAAA;AAED,eAAO,MAAM,iCAAiC;;IAE7C;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAQF,CAAA;AAEF,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,UAAU,CACrD,OAAO,iCAAiC,CACxC,CAAA;AAED,MAAM,MAAM,iCAAiC,GAC1C;IACA,MAAM,EAAE,SAAS,CAAA;IACjB,YAAY,EAAE,2BAA2B,CAAA;CACxC,GACD;IACA,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,wBAAwB,CAAA;CAC9B,CAAA;AAEJ,2EAA2E;AAC3E,MAAM,MAAM,kCAAkC,GAC3C;IACA,MAAM,EAAE,SAAS,CAAA;IACjB,YAAY,EAAE,IAAI,CAAC,2BAA2B,EAAE,UAAU,CAAC,CAAA;CAC1D,GACD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,wBAAwB,CAAA;CAAE,CAAA;AAEvD,MAAM,MAAM,kCAAkC,GAAG,CAAC,IAAI,EAAE;IACvD,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,MAAM,EAAE,WAAW,CAAA;CACnB,KAAK,OAAO,CAAC,kCAAkC,CAAC,CAAA"}
|
package/dist/lifecycle/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { notionContrastModeSchema } from "../protocol/contrast.js";
|
|
2
2
|
import { notionDataSourceBindingsSchema } from "../protocol/dataSources/dataSource.js";
|
|
3
3
|
import { notionBlockIdSchema } from "../protocol/ids.js";
|
|
4
|
-
import { manifestSchema } from "../protocol/manifest.js";
|
|
4
|
+
import { manifestSchema, } from "../protocol/manifest.js";
|
|
5
5
|
import { customBlockPageSchema } from "../protocol/pages/page.js";
|
|
6
6
|
import { notionParentSchema } from "../protocol/parent.js";
|
|
7
7
|
import { notionThemeSchema } from "../protocol/theme.js";
|