@notionhq/custom-blocks-host 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -225
- package/THIRD_PARTY_LICENSES.md +9 -0
- package/dist/autoBindProperties.d.ts +5 -2
- package/dist/autoBindProperties.d.ts.map +1 -1
- package/dist/autoBindProperties.js +5 -2
- package/dist/browser.js +1 -1
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.d.ts +1215 -0
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.d.ts.map +1 -0
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.js +27 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.d.ts +8 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.d.ts.map +1 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.js +39 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.d.ts +11 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.d.ts.map +1 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.js +18 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.d.ts +9 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.d.ts.map +1 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.js +18 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts +1091 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts.map +1 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.js +9 -0
- package/dist/compatibility/pageForProtocol3To5.d.ts +159 -0
- package/dist/compatibility/pageForProtocol3To5.d.ts.map +1 -0
- package/dist/{lifecycle/legacyPage.js → compatibility/pageForProtocol3To5.js} +50 -9
- package/dist/compatibility/pageResult.d.ts +11 -0
- package/dist/compatibility/pageResult.d.ts.map +1 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.d.ts +9 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.d.ts.map +1 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.js +46 -0
- package/dist/createCustomBlockHost.d.ts +18 -19
- package/dist/createCustomBlockHost.d.ts.map +1 -1
- package/dist/createCustomBlockHost.js +103 -38
- package/dist/index.d.ts +2 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/{localBlockUrl.d.ts → isAllowedLocalPreviewUrl.d.ts} +2 -2
- package/dist/isAllowedLocalPreviewUrl.d.ts.map +1 -0
- package/dist/{localBlockUrl.js → isAllowedLocalPreviewUrl.js} +3 -7
- package/dist/lifecycle/initErrors.d.ts +1 -0
- package/dist/lifecycle/initErrors.d.ts.map +1 -1
- package/dist/lifecycle/initErrors.js +7 -0
- package/dist/lifecycle/initializationController.d.ts +6 -4
- package/dist/lifecycle/initializationController.d.ts.map +1 -1
- package/dist/lifecycle/initializationController.js +24 -15
- package/dist/lifecycle/resolveManifest.d.ts +13 -0
- package/dist/lifecycle/resolveManifest.d.ts.map +1 -0
- package/dist/lifecycle/resolveManifest.js +21 -0
- package/dist/lifecycle/types.d.ts +1637 -17
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lifecycle/types.js +18 -0
- package/dist/messages/sandboxMessageRouter.d.ts.map +1 -1
- package/dist/messages/sandboxMessageRouter.js +2 -2
- package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -4
- package/dist/protocol/dataSources/dataSourcePage.js +2 -3
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/isLocalBlockServerUrl.d.ts +2 -0
- package/dist/protocol/isLocalBlockServerUrl.js +9 -0
- package/dist/protocol/messages/connect.d.ts +2 -2
- package/dist/protocol/messages/connect.js +2 -2
- package/dist/protocol/messages/createPageResult.d.ts +2 -2
- package/dist/protocol/messages/createPageResult.js +3 -3
- package/dist/protocol/messages/getPage.d.ts +2 -2
- package/dist/protocol/messages/getPage.js +3 -3
- package/dist/protocol/messages/hostToSandbox.d.ts +3 -3
- package/dist/protocol/messages/hostToSandbox.js +10 -10
- package/dist/protocol/messages/init.d.ts +1 -1
- package/dist/protocol/messages/queryDataSourceResult.d.ts +3 -3
- package/dist/protocol/messages/queryDataSourceResult.js +6 -3
- package/dist/protocol/messages/updatePageResult.d.ts +2 -2
- package/dist/protocol/messages/updatePageResult.js +3 -3
- package/dist/protocol/pages/page.d.ts +2 -2
- package/dist/protocol/pages/page.js +1 -1
- package/dist/protocol/protocolVersion.d.ts +3 -2
- package/dist/protocol/protocolVersion.js +4 -2
- package/dist/protocol.d.ts +9 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +8 -0
- package/docs/bridge/changelog.md +67 -0
- package/docs/bridge/protocol.md +182 -0
- package/docs/bridge/versioning.md +38 -0
- package/docs/compatibility.md +68 -0
- package/docs/handlers.md +199 -0
- package/docs/lifecycle.md +117 -0
- package/package.json +11 -3
- package/src/autoBindProperties.ts +5 -2
- package/src/compatibility/addMetadataReadSchemasForProtocol3To4.ts +36 -0
- package/src/compatibility/normalizeHostToSandboxMessage.ts +54 -0
- package/src/compatibility/normalizePageResultsForProtocol3To5.ts +28 -0
- package/src/compatibility/normalizePageResultsForProtocol6.ts +23 -0
- package/src/compatibility/normalizeSandboxToHostMessage.ts +10 -0
- package/src/{lifecycle/legacyPage.ts → compatibility/pageForProtocol3To5.ts} +52 -11
- package/src/compatibility/pageResult.ts +18 -0
- package/src/compatibility/pageWithNullTextFallbackProperties.ts +53 -0
- package/src/createCustomBlockHost.ts +152 -62
- package/src/index.ts +4 -51
- package/src/{localBlockUrl.ts → isAllowedLocalPreviewUrl.ts} +4 -7
- package/src/lifecycle/initErrors.ts +9 -0
- package/src/lifecycle/initializationController.ts +34 -19
- package/src/lifecycle/resolveManifest.ts +31 -0
- package/src/lifecycle/types.ts +84 -16
- package/src/messages/sandboxMessageRouter.ts +2 -2
- package/src/protocol.ts +8 -0
- package/dist/lifecycle/legacyPage.d.ts +0 -70
- package/dist/lifecycle/legacyPage.d.ts.map +0 -1
- package/dist/lifecycle/loadCustomBlockManifest.d.ts +0 -16
- package/dist/lifecycle/loadCustomBlockManifest.d.ts.map +0 -1
- package/dist/lifecycle/loadCustomBlockManifest.js +0 -65
- package/dist/lifecycle/manifestOptions.d.ts +0 -17
- package/dist/lifecycle/manifestOptions.d.ts.map +0 -1
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +0 -6
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +0 -1
- package/dist/lifecycle/normalizeHostToSandboxMessage.js +0 -16
- package/dist/lifecycle/normalizePage.d.ts +0 -7
- package/dist/lifecycle/normalizePage.d.ts.map +0 -1
- package/dist/lifecycle/normalizePage.js +0 -22
- package/dist/localBlockUrl.d.ts.map +0 -1
- package/src/lifecycle/loadCustomBlockManifest.ts +0 -89
- package/src/lifecycle/manifestOptions.ts +0 -19
- package/src/lifecycle/normalizeHostToSandboxMessage.ts +0 -29
- package/src/lifecycle/normalizePage.ts +0 -35
- /package/dist/{lifecycle/manifestOptions.js → compatibility/pageResult.js} +0 -0
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $e=6,Qe=6;function vn(e){let{manifestProperties:t,propertySchemasById:s}=e,i=[];for(let[c,l]of Object.entries(t)){let p=dn({propertyKey:c,manifestProperty:l,propertySchemasById:s});p!==void 0&&i.push([c,p])}return Object.fromEntries(i)}function dn(e){let{propertyKey:t,manifestProperty:s,propertySchemasById:i}=e,c=bt(s.name),l=Object.entries(i).filter(([p,y])=>y.type===s.type&&(p===t||bt(y.name)===c));return l.length===1?l[0][0]:void 0}function bt(e){return e.trim().toLowerCase()}var qe,hn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Xe(e){return!e&&!qe?hn:{lang:e?.lang??qe?.lang,message:e?.message,abortEarly:e?.abortEarly??qe?.abortEarly,abortPipeEarly:e?.abortPipeEarly??qe?.abortPipeEarly}}var gn;function bn(e){return gn?.get(e)}var Sn;function kn(e){return Sn?.get(e)}var In;function _n(e,t){return In?.get(e)?.get(t)}function he(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function w(e,t,s,i,c){let l=c&&"input"in c?c.input:s.value,p=c?.expected??e.expects??null,y=c?.received??he(l),m={kind:e.kind,type:e.type,input:l,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},x=e.kind==="schema",_=c?.message??e.message??_n(e.reference,m.lang)??(x?kn(m.lang):null)??i.message??bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(s.typed=!1),s.issues?s.issues.push(m):s.issues=[m]}var St=new WeakMap;function Q(e){let t=St.get(e);return t||(t={version:1,vendor:"valibot",validate(s){return e["~run"]({value:s},Xe())}},St.set(e,t)),t}function xn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function We(e,t){let s=[...new Set(e)];return s.length>1?`(${s.join(` ${t} `)})`:s[0]??"never"}var Cn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ce(e){return{kind:"transformation",type:"brand",reference:ce,async:!1,name:e,"~run"(t){return t}}}function Ie(e){return{kind:"validation",type:"finite",reference:Ie,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,s){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,s),t}}}function Je(e,t){let s=he(e);return{kind:"validation",type:"includes",reference:Je,async:!1,expects:s,requirement:e,message:t,"~run"(i,c){return i.typed&&!i.value.includes(this.requirement)&&w(this,"content",i,c,{received:`!${s}`}),i}}}function Te(e,t){return{kind:"validation",type:"max_length",reference:Te,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&s.value.length>this.requirement&&w(this,"length",s,i,{received:`${s.value.length}`}),s}}}function _e(e,t){return{kind:"validation",type:"min_length",reference:_e,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&s.value.length<this.requirement&&w(this,"length",s,i,{received:`${s.value.length}`}),s}}}function xe(e,t){return{kind:"validation",type:"min_value",reference:xe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(s,i){return s.typed&&!(s.value>=this.requirement)&&w(this,"value",s,i,{received:s.value instanceof Date?s.value.toJSON():he(s.value)}),s}}}function Ke(e,t){return{kind:"validation",type:"regex",reference:Ke,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(s,i){return s.typed&&!this.requirement.test(s.value)&&w(this,"format",s,i),s}}}function Ze(e){return{kind:"transformation",type:"transform",reference:Ze,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var It={abortEarly:!0};function _t(e,t,s){return typeof e.fallback=="function"?e.fallback(t,s):e.fallback}function Ae(e,t,s){return typeof e.default=="function"?e.default(t,s):e.default}function xt(e,t){return!e["~run"]({value:t},It).issues}function E(e,t){return{kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(Array.isArray(c)){s.typed=!0,s.value=[];for(let l=0;l<c.length;l++){let p=c[l],y=this.item["~run"]({value:p},i);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:p};for(let x of y.issues)x.path?x.path.unshift(m):x.path=[m],s.issues?.push(x);if(s.issues||(s.issues=y.issues),i.abortEarly){s.typed=!1;break}}y.typed||(s.typed=!1),s.value.push(y.value)}}else w(this,"type",s,i);return s}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,s),t}}}function o(e,t){return{kind:"schema",type:"literal",reference:o,expects:he(e),async:!1,literal:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===this.literal?s.typed=!0:w(this,"type",s,i),s}}}function Ye(e){return{kind:"schema",type:"nan",reference:Ye,expects:"NaN",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,s),t}}}function F(e,t){return{kind:"schema",type:"nullable",reference:F,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===null&&(this.default!==void 0&&(s.value=Ae(this,s,i)),s.value===null)?(s.typed=!0,s):this.wrapped["~run"](s,i)}}}function P(e){return{kind:"schema",type:"number",reference:P,expects:"number",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,s),t}}}function n(e,t){return{kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(c&&typeof c=="object"){s.typed=!0,s.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Ae(p),m=p["~run"]({value:y},i);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],s.issues?.push(_);if(s.issues||(s.issues=m.issues),i.abortEarly){s.typed=!1;break}}m.typed||(s.typed=!1),s.value[l]=m.value}else if(p.fallback!==void 0)s.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",s,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}}else w(this,"type",s,i);return s}}}function u(e,t){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return Q(this)},"~run"(s,i){return s.value===void 0&&(this.default!==void 0&&(s.value=Ae(this,s,i)),s.value===void 0)?(s.typed=!0,s):this.wrapped["~run"](s,i)}}}function T(e,t){return{kind:"schema",type:"picklist",reference:T,expects:We(e.map(he),"|"),async:!1,options:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){return this.options.includes(s.value)?s.typed=!0:w(this,"type",s,i),s}}}function V(e,t,s){return{kind:"schema",type:"record",reference:V,expects:"Object",async:!1,key:e,value:t,message:s,get"~standard"(){return Q(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){i.typed=!0,i.value={};for(let p in l)if(xn(l,p)){let y=l[p],m=this.key["~run"]({value:p},c);if(m.issues){let _={type:"object",origin:"key",input:l,key:p,value:y};for(let C of m.issues)C.path=[_],i.issues?.push(C);if(i.issues||(i.issues=m.issues),c.abortEarly){i.typed=!1;break}}let x=this.value["~run"]({value:y},c);if(x.issues){let _={type:"object",origin:"value",input:l,key:p,value:y};for(let C of x.issues)C.path?C.path.unshift(_):C.path=[_],i.issues?.push(C);if(i.issues||(i.issues=x.issues),c.abortEarly){i.typed=!1;break}}(!m.typed||!x.typed)&&(i.typed=!1),m.typed&&(i.value[m.value]=x.value)}}else w(this,"type",i,c);return i}}}function f(e,t){return{kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c=s.value;if(c&&typeof c=="object"){s.typed=!0,s.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Ae(p),m=p["~run"]({value:y},i);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],s.issues?.push(_);if(s.issues||(s.issues=m.issues),i.abortEarly){s.typed=!1;break}}m.typed||(s.typed=!1),s.value[l]=m.value}else if(p.fallback!==void 0)s.value[l]=_t(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",s,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}if(!s.issues||!i.abortEarly){for(let l in c)if(!(l in this.entries)){w(this,"key",s,i,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",s,i);return s}}}function r(e){return{kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,get"~standard"(){return Q(this)},"~run"(t,s){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,s),t}}}function kt(e){let t;if(e)for(let s of e)if(t)for(let i of s.issues)t.push(i);else t=s.issues;return t}function g(e,t){return{kind:"schema",type:"union",reference:g,expects:We(e.map(s=>s.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return Q(this)},"~run"(s,i){let c,l,p;for(let y of this.options){let m=y["~run"]({value:s.value},i);if(m.typed)if(m.issues)l?l.push(m):l=[m];else{c=m;break}else p?p.push(m):p=[m]}if(c)return c;if(l){if(l.length===1)return l[0];w(this,"type",s,i,{issues:kt(l)}),s.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",s,i,{issues:kt(p)})}return s}}}function Ce(){return{kind:"schema",type:"unknown",reference:Ce,expects:"unknown",async:!1,get"~standard"(){return Q(this)},"~run"(e){return e.typed=!0,e}}}function v(e,t,s){return{kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:s,get"~standard"(){return Q(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(C,b)=>{for(let L of C.options){if(L.type==="variant")_(L,new Set(b).add(L.key));else{let q=!0,A=0;for(let O of b){let H=L.entries[O];if(O in l?H["~run"]({typed:!1,value:l[O]},It).issues:H.type!=="exact_optional"&&H.type!=="optional"&&H.type!=="nullish"){q=!1,m!==O&&(y<A||y===A&&O in l&&!(m in l))&&(y=A,m=O,x=[]),m===O&&x.push(L.entries[O].expects);break}A++}if(q){let O=L["~run"]({value:l},c);(!p||!p.typed&&O.typed)&&(p=O)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",i,c,{input:l[m],expected:We(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",i,c);return i}}}function ie(e,t,s){let i=e["~run"]({value:t},Xe(s));if(i.issues)throw new Cn(i.issues);return i.value}function z(...e){return{...e[0],pipe:e,get"~standard"(){return Q(this)},"~run"(t,s){for(let i of e)if(i.kind!=="metadata"){if(t.issues&&(i.kind==="schema"||i.kind==="transformation")){t.typed=!1;break}(!t.issues||!s.abortEarly&&!s.abortPipeEarly)&&(t=i["~run"](t,s))}return t}}}function Pe(e,t,s){let i=e["~run"]({value:t},Xe(s));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}var le=z(r(),ce("NotionBlockId")),K=z(r(),ce("NotionDataSourceId")),U=z(r(),ce("NotionPageId")),Ct=z(r(),ce("NotionAgentId")),Pt=z(r(),ce("NotionSpaceId"));var Et=T(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),et=n({id:r(),name:r(),color:u(Et),description:u(r())}),Pn=n({id:r(),name:r(),color:u(Et),option_ids:E(r())}),En=n({synced_property_id:r(),synced_property_name:r()}),R=n({name:r(),description:u(r())}),On=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],Ot=T(On),jt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],tt=v("type",[n({...R.entries,type:o("title")}),n({...R.entries,type:o("rich_text")}),n({...R.entries,type:o("number")}),n({...R.entries,type:o("checkbox")}),n({...R.entries,type:o("url")}),n({...R.entries,type:o("email")}),n({...R.entries,type:o("phone_number")}),n({...R.entries,type:o("select"),options:E(et)}),n({...R.entries,type:o("multi_select"),options:E(et)}),n({...R.entries,type:o("status"),options:E(et),groups:E(Pn)}),n({...R.entries,type:o("date")}),n({...R.entries,type:o("people")}),n({...R.entries,type:o("files")}),n({...R.entries,type:o("unique_id")}),n({...R.entries,type:o("relation"),data_source_id:u(r()),dual_property:u(En)}),n({...R.entries,type:o("place")}),n({...R.entries,type:o("formula")}),n({...R.entries,type:o("rollup")}),n({...R.entries,type:o("button")}),n({...R.entries,type:o("verification")}),n({...R.entries,type:o("last_visited_time")}),n({...R.entries,type:o("location")}),n({...R.entries,type:o("created_time")}),n({...R.entries,type:o("last_edited_time")}),n({...R.entries,type:o("created_by")}),n({...R.entries,type:o("last_edited_by")})]);var Rt=n({id:K,table:r(),spaceId:u(Pt)}),Mt=n({id:u(K),propertiesById:V(r(),tt)}),$o=n({key:r(),collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:V(r(),u(r())),propertySchemasById:V(r(),tt)}),jn=n({collectionPointer:u(Rt),collectionSchema:u(Mt),propertyIdsByKey:u(V(r(),u(r())))}),me=V(r(),jn);var ge=T(["standard","high"]),Bt="standard";var Dt=n({type:o("contrastModeChanged"),contrastMode:ge});var Ne=n({unit:T(["year","month","week","day"]),value:P(),time:r(),defaultTimeZone:u(r())}),Rn=n({unit:T(["hour","minute"]),value:P()}),Ee=n({unit:o("none")}),rt=g([Ne,Rn]),wt=u(g([Ne,Ee])),qt=u(g([rt,Ee])),Mn=n({type:o("date"),start_date:r(),reminder:wt}),Bn=n({type:o("daterange"),start_date:r(),end_date:r(),reminder:wt}),Dn=n({type:o("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:qt}),wn=n({type:o("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:qt}),Tt=v("type",[Mn,Bn,Dn,wn]);var Ue=n({id:r(),table:r()});var ae=v("type",[n({type:o("page_id"),page_id:U}),n({type:o("data_source_id"),data_source_id:K}),n({type:o("workspace"),workspace:o(!0)}),n({type:o("block_id"),block_id:le}),n({type:o("agent_id"),agent_id:Ct}),n({type:o("unavailable")})]);var be=v("type",[n({type:o("unavailable")}),n({type:o("page"),id:U,parent:ae})]),qn=n({type:o("emoji"),emoji:r()}),Tn=n({type:o("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),Nt=n({type:o("external"),external:n({url:r()})}),Ut=n({type:o("file"),file:n({url:r(),expiry_time:u(r())})}),ze=v("type",[qn,Tn,Nt,Ut]),Le=v("type",[Nt,Ut]),Z=F(r()),At=V(r(),Ce()),nt=g([n({id:r(),name:u(r()),color:u(r()),description:u(Z)}),n({name:r(),id:u(r()),color:u(r()),description:u(Z)})]),ot={start:r(),end:u(Z),time_zone:u(Z),reminder:u(g([rt,Ee]))},An=g([n({...ot,start:z(r(),Je("T"))}),n({...ot,time_zone:r()}),n({...ot,reminder:u(g([Ne,Ee]))})]),Nn=g([n({object:u(o("user")),id:r()}),n({object:o("group"),id:r(),name:u(Z)})]),Un=n({id:r()}),Fn=g([n({type:o("external"),name:r(),external:n({url:r()})}),n({type:o("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),zn=n({lat:P(),lon:P(),name:u(Z),address:u(Z),aws_place_id:u(Z),google_place_id:u(Z)}),M={id:r()},Fe=F(n({...Ue.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Ft=v("type",[n({...M,type:o("title"),title:E(At)}),n({...M,type:o("rich_text"),rich_text:E(At)}),n({...M,type:o("number"),number:F(P())}),n({...M,type:o("url"),url:Z}),n({...M,type:o("email"),email:Z}),n({...M,type:o("phone_number"),phone_number:Z}),n({...M,type:o("checkbox"),checkbox:h()}),n({...M,type:o("select"),select:F(nt)}),n({...M,type:o("status"),status:F(nt)}),n({...M,type:o("multi_select"),multi_select:E(nt)}),n({...M,type:o("date"),date:F(An)}),n({...M,type:o("people"),people:E(Nn)}),n({...M,type:o("relation"),has_more:u(h()),relation:E(Un)}),n({...M,type:o("files"),files:E(Fn)}),n({...M,type:o("place"),place:F(zn)}),n({...M,type:o("created_time"),created_time:Z}),n({...M,type:o("last_edited_time"),last_edited_time:Z}),n({...M,type:o("created_by"),created_by:Fe}),n({...M,type:o("last_edited_by"),last_edited_by:Fe}),n({...M,type:o("last_visited_time"),last_visited_time:Z}),n({...M,type:o("unique_id"),unique_id:r()}),n({...M,type:o("button"),button:r()}),n({...M,type:o("formula"),formula:r()}),n({...M,type:o("location"),location:r()}),n({...M,type:o("rollup"),rollup:r()}),n({...M,type:o("verification"),verification:r()})]),Oe=V(r(),Ft),Ln=V(r(),F(Ft)),ne=n({object:o("page"),id:U,parent:ae,properties:Ln,created_by:u(Fe,null),last_edited_by:u(Fe,null),last_visited_time:u(F(r()),null),created_time:u(F(r()),null),last_edited_time:u(F(r()),null),icon:u(F(ze),null),cover:u(F(Le),null),url:u(F(r()),null),public_url:u(F(r()),null),is_archived:h(),in_trash:h()}),Se=n({object:o("page"),id:U,parent:ae,properties:Oe,created_time:u(r()),last_edited_time:u(r()),icon:u(ze),cover:u(Le),url:u(r()),public_url:u(r()),is_archived:h(),in_trash:h()});var Hn=r(),zt=n({code:Hn,message:r(),isRetryable:h()}),Lt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:zt})]),Ht=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:zt})]);var st=z(r(),ce("NotionUserId")),pe=n({object:o("user"),id:st,name:u(r()),avatar_url:F(r()),type:o("person"),person:n({email:r()})}),Vt=n({object:o("list"),results:E(pe),next_cursor:F(r()),has_more:h(),type:o("user"),user:V(r(),Ce())});var Gt=n({type:o("currentUserChanged"),currentUser:pe});var $t=n({type:o("dataSourcesChanged"),dataSources:n({bindings:me})});var Vn=r(),Qt=n({code:Vn,message:r(),isRetryable:h()}),Xt=n({type:o("getPage"),requestId:r(),pageId:U,dataSourceId:u(K)}),Wt=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:Qt})]),Jt=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:Qt})]);var Gn=r(),$n=n({code:Gn,message:r(),isRetryable:h()}),Kt=n({type:o("getUser"),requestId:r(),userId:st}),Zt=v("status",[n({type:o("getUserResult"),requestId:r(),status:o("success"),user:pe}),n({type:o("getUserResult"),requestId:r(),status:o("error"),error:$n})]);var Qn=v("type",[n({type:o("emoji"),emoji:r()}),n({type:o("external"),url:r()})]),Xn=n({name:r(),description:u(r()),type:Ot}),Wn=n({name:r(),description:u(r()),icon:u(Qn),properties:u(V(r(),Xn),{})}),ye=n({version:o(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:o("emoji"),emoji:r()})),dataSources:u(V(r(),Wn),{})});var ke=T(["light","dark"]);var Jn=r(),Kn=n({code:Jn,message:r(),isRetryable:h()});var He=v("status",[n({type:o("init"),initializationId:r(),status:o("success"),theme:ke,contrastMode:ge,blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe}),n({type:o("init"),initializationId:r(),status:o("error"),error:Kn})]);var Yt=n({type:o("invalidSandboxMessage"),reason:r()});var Zn=r(),Yn=n({code:Zn,message:r(),isRetryable:h()}),er=n({type:o("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(P())}),tr=v("status",[n({type:o("listUsersResult"),requestId:r(),status:o("success"),list:Vt}),n({type:o("listUsersResult"),requestId:r(),status:o("error"),error:Yn})]);var eo=r(),to=n({code:eo,message:r(),isRetryable:h()}),rr=n({type:o("openExternalUrl"),requestId:r(),url:r()}),nr=v("status",[n({type:o("openExternalUrlResult"),requestId:r(),status:o("success")}),n({type:o("openExternalUrlResult"),requestId:r(),status:o("error"),error:to})]);var ro=T(["side_peek","center_peek"]),no=r(),oo=n({code:no,message:r(),isRetryable:h()}),or=n({type:o("openPage"),requestId:r(),pageId:U,mode:ro}),sr=v("status",[n({type:o("openPageResult"),requestId:r(),status:o("success"),pageId:U}),n({type:o("openPageResult"),requestId:r(),status:o("error"),error:oo})]);var ir=n({type:o("pageChanged"),page:be});var ar=n({type:o("parentChanged"),parent:ae});var ur=g([r(),P(),h(),Tt,E(r()),E(Ue)]);var cr=n({id:U,is_archived:h(),in_trash:h(),propertiesById:V(r(),u(ur))});var so=r(),lr=n({code:so,message:r(),isRetryable:h()}),pr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:E(ne),hasMore:h()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:lr})]),fr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:E(g([ne,cr])),hasMore:h()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:lr})]);var mr=n({type:o("themeChanged"),theme:ke});var io=r(),yr=n({code:io,message:r(),isRetryable:h()}),vr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:ne}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:yr})]),dr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:g([ne,Se])}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:yr})]);var hr=v("type",[He,mr,Dt,ar,ir,Gt,$t,Zt,tr,sr,nr,Yt]),gr=v("type",[...hr.options,pr,Wt,Lt,vr]),vi=v("type",[...hr.options,fr,Jt,Ht,dr]);function br(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function Sr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function it(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function at(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:s}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${s}.`,isRetryable:!1}}function ut(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function kr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Ir(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function _r(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function xr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function Cr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Pr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function je(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function re(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function ct(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var ao=5e3,uo=5e3,co=5e3;function Er(e){let{prepareInit:t,sendInitMessage:s,warn:i,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:p=ao,initialStateTimeoutMs:y=uo,noInitResultTimeoutMs:m=co,stopHostWithFailure:x,onInitResult:_,onConnectionFailure:C}=e,b="waitingForConnect",L,q,A,O,H=!1,$=!1;function X(){L!==void 0&&(window.clearTimeout(L),L=void 0)}function ue(){q!==void 0&&(window.clearTimeout(q),q=void 0)}function W(){A!==void 0&&(window.clearTimeout(A),A=void 0)}function B(S){let{initializationId:I,error:J,phase:oe,source:N}=S;switch(b){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return re(b)}b="error",O=I,X(),ue(),s({type:"init",initializationId:I,status:"error",error:J}),C?.({...J,phase:oe,source:N})}async function G(S){if(b==="waitingForConnect"){b="preparingInit",O=S.initializationId,X(),q=window.setTimeout(()=>{if(b!=="preparingInit")return;let I=kr();i({...I,initializationId:S.initializationId}),B({initializationId:S.initializationId,error:I,phase:"init",source:"host"})},y);try{let I=await t(S);if(b!=="preparingInit")return;if(ue(),I.status==="error"){B({initializationId:S.initializationId,error:I.error,phase:"init",source:"host"});return}b="waitingForInitResult";let J={type:"init",initializationId:S.initializationId,status:"success",theme:I.initialState.theme,contrastMode:I.initialState.contrastMode??Bt,blockId:I.initialState.blockId,parent:I.initialState.parent,page:I.initialState.page,currentUser:I.initialState.currentUser,manifest:I.initialState.manifest,dataSources:I.initialState.dataSources};s(J),A=window.setTimeout(()=>{if(b!=="waitingForInitResult")return;b="error";let oe=Cr();C?.({...oe,phase:"initResult",source:"host"}),i({...oe,initializationId:S.initializationId})},m)}catch(I){if(b!=="preparingInit")return;i({message:"Failed to prepare custom block initialization",error:I}),B({initializationId:S.initializationId,error:je(),phase:"init",source:"host"})}}}function ee(S){if(b!=="stopped"&&b==="waitingForConnect"){if(!ct(S.bridgeProtocolVersion)){let I=it({currentBridgeProtocolVersion:S.bridgeProtocolVersion});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.bridgeProtocolVersion<l){let I=at({currentBridgeProtocolVersion:S.bridgeProtocolVersion,minBridgeProtocolVersion:l});B({initializationId:S.initializationId,error:I,phase:"connect",source:"host"});return}if(S.status==="error"){B({initializationId:S.initializationId,error:S.error,phase:"connect",source:"sandbox"});return}$=!0,G(S)}}function se(S){if(b==="stopped"||b!=="waitingForConnect")return"handled";let{initializationId:I,bridgeProtocolVersion:J}=S;if(I===void 0)return"nack";let oe=S.error;return J!==void 0&&(ct(J)?J<l&&(oe=at({currentBridgeProtocolVersion:J,minBridgeProtocolVersion:l})):oe=it({currentBridgeProtocolVersion:J})),B({initializationId:I,error:oe,phase:"connect",source:"host"}),"handled"}function D(S){let{initializationId:I,error:J}=S;b!=="waitingForInitResult"||I===void 0||I!==O||(X(),W(),b="error",i(J),C?.({...J,phase:"initResult",source:"host"}))}function te(){if(b!=="stopped"){if(H){x({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}H=!0,X(),b==="waitingForConnect"&&(L=window.setTimeout(()=>{if(b!=="waitingForConnect")return;b="error";let S=br();i(S),C?.({...S,phase:"connect",source:"host"})},p))}}function fe(S){if(b!=="waitingForInitResult"||S.initializationId!==O){i({message:"Ignored stale or unexpected initResult",payload:S});return}W(),b=S.status==="success"?"initialized":"error",S.status==="success"?c():C?.({...S.error,phase:"initResult",source:"sandbox"}),_?.(S)}function we(){b="stopped",X(),ue(),W()}return{get status(){return b},get hasConnectedSandbox(){return $},handleConnect:ee,handleInitResult:fe,handleInvalidConnect:se,handleInvalidInitResult:D,onIframeLoad:te,stop:we}}function lt({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function Or(e){let t=new AbortController,s=()=>t.abort();e.signal.addEventListener("abort",s,{once:!0});let i=new Promise((l,p)=>{t.signal.addEventListener("abort",()=>p(t.signal.reason),{once:!0})});e.signal.aborted&&t.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{t.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?lo(e.sandboxOrigin,t.signal):e.getPersistedManifest({signal:t.signal}),i]);if(t.signal.aborted)throw new Error("Manifest loading was cancelled.");return{status:"success",manifest:ie(ye,l)}}catch(l){return e.signal.aborted||e.onError(l),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(c),e.signal.removeEventListener("abort",s)}}async function lo(e,t){let s=new URL(e);if(!lt({url:s,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let i=await fetch(new URL("/manifest",s),{credentials:"omit",redirect:"error",cache:"no-store",signal:t});if(!i.ok)throw new Error(`Manifest request failed: HTTP ${i.status}.`);return i.json()}var de=class extends Error{};function pt(e){try{return po(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function po(e){let{start:t,end:s,time_zone:i,reminder:c}=e;if(!t.split("T")[0])throw new de("Date values must include a date.");let l=t.includes("T")||i!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),y=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,m=i?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=m?(Number(m[2]??0)*60+Number(m[3]??0))*(m[1]==="-"?-1:1):y,_=q=>{if(!q.split("T")[0])throw new de("Date values must include a date.");if(!q.includes("T"))return{date:q,time:"00:00"};let A=q.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(A)return{date:A[1],time:A[2]};if(!i||m){let $=new Date(new Date(q).getTime()+x*6e4).toISOString();return{date:$.slice(0,10),time:$.slice(11,16)}}let O=new Intl.DateTimeFormat("en-CA",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(q)),H=$=>O.find(X=>X.type===$)?.value;return{date:`${H("year")}-${H("month")}-${H("day")}`,time:`${H("hour")}:${H("minute")}`}},C=_(t),b=s?_(s):void 0;if(!l){if(c&&!("time"in c)&&c.unit!=="none")throw new de("Hour and minute reminders require a date with a time.");return b?{type:"daterange",start_date:C.date,end_date:b.date,reminder:c}:{type:"date",start_date:C.date,reminder:c}}let L=i??(y===0?"UTC":`UTC${y<0?"-":"+"}${Math.floor(Math.abs(y)/60)}${Math.abs(y)%60===0?"":`:${String(Math.abs(y)%60).padStart(2,"0")}`}`);return b?{type:"datetimerange",start_date:C.date,start_time:C.time,end_date:b.date,end_time:b.time,time_zone:L,reminder:c}:{type:"datetime",start_date:C.date,start_time:C.time,time_zone:L,reminder:c}}function Rr(e){return{...e,properties:Object.fromEntries(Object.values(e.properties).flatMap(t=>t?[[t.id,t]]:[])),icon:e.icon??void 0,cover:e.cover??void 0,created_time:e.created_time??void 0,last_edited_time:e.last_edited_time??void 0,url:e.url??void 0,public_url:e.public_url??void 0}}function Mr(e){let t={};for(let s of Object.values(e.properties))s&&(t[s.id]=fo(s));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:t}}function jr(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let s=t.text;return s&&typeof s=="object"&&"content"in s&&typeof s.content=="string"?s.content:""}).join("")}function ft(e){if(e==null||e==="")return;let t=new Date(e);if(Number.isFinite(t.getTime()))return{type:"datetime",start_date:t.toISOString().slice(0,10),start_time:t.toISOString().slice(11,16),time_zone:"UTC"}}function fo(e){switch(e.type){case"title":return jr(e.title);case"rich_text":return jr(e.rich_text);case"number":return e.number??void 0;case"checkbox":return e.checkbox;case"url":return e.url??"";case"email":return e.email??"";case"phone_number":return e.phone_number??"";case"select":return e.select?.name;case"status":return e.status?.name;case"multi_select":return e.multi_select.flatMap(t=>t.name??[]);case"date":return e.date?pt(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return ft(e.created_time);case"last_edited_time":return ft(e.last_edited_time);case"last_visited_time":return ft(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return re(e)}}function Br(e,t){if(t>=6||e.status==="error")return e;switch(e.type){case"queryDataSourceResult":return{...e,items:e.items.map(Mr)};case"getPageResult":case"createPageResult":case"updatePageResult":return{...e,page:Rr(e.page)};default:return re(e)}}function Dr(e,t){return e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"?e:Br(e,t)}var wr=n({theme:ke,contrastMode:u(ge),blockId:le,parent:ae,page:be,manifest:ye,dataSources:n({bindings:me}),currentUser:pe});function qr(e){if(e.length>2048||!URL.canParse(e))return;let t=new URL(e);if(!(t.protocol!=="http:"&&t.protocol!=="https:"||t.username!==""||t.password!==""||t.href.length>2048))return t.href}function Tr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Ar=n({code:r(),message:r(),isRetryable:h()});var Nr={type:o("connect"),initializationId:r(),bridgeProtocolVersion:P(),sdkVersion:r()},Ur=v("status",[n({status:o("success"),manifest:u(ye),...Nr}),n({status:o("error"),error:Ar,...Nr})]);var mo=v("type",[n({type:o("start")}),n({type:o("end")}),n({type:o("before"),blockId:le}),n({type:o("after"),blockId:le})]),yo=v("type",[n({type:o("page_id"),page_id:U}),n({type:o("data_source_id"),data_source_id:K})]),Fr=n({type:o("createPage"),requestId:r(),parent:yo,properties:Oe,position:u(mo)});var vo=r(),ho=n({code:vo,message:r(),isRetryable:h()}),zr=v("status",[n({type:o("initResult"),initializationId:r(),status:o("success"),initialHeight:u(z(P(),Ie(),xe(0)))}),n({type:o("initResult"),initializationId:r(),status:o("error"),error:ho})]);var Lr=n({type:o("invalidHostMessage"),reason:r()});var Hr=T(["ascending","descending"]);var Vr=z(U,Ke(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Ze(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),mt=g([f({contains:Vr}),f({does_not_contain:Vr})]),De=g([f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Be=g([r(),E(r())]),Gr=f({object:T(["user","group"]),id:z(r(),_e(1))}),go=g([f({contains:Gr}),f({does_not_contain:Gr}),De]),$r=f({object:o("user"),id:z(r(),_e(1),Te(2e3))}),bo=g([f({contains:$r}),f({does_not_contain:$r}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Re=g([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),De]),So=g([f({equals:P()}),f({does_not_equal:P()}),f({greater_than:P()}),f({less_than:P()}),f({greater_than_or_equal_to:P()}),f({less_than_or_equal_to:P()}),De]),ko=g([f({equals:h()}),f({does_not_equal:h()})]),Jr=g([f({equals:Be}),f({does_not_equal:Be}),De]),Qr=T(["To-do","In progress","Complete","Current","Future"]),Xr=g([Qr,z(E(Qr),_e(1),Te(5))]),Io=g([f({group_equals:Xr}),f({group_does_not_equal:Xr})]),_o=g([Jr,Io]),xo=g([f({contains:Be}),f({contains_all:Be}),f({does_not_contain:Be}),De]),Y=T(["start_date","end_date"]),Co=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Me=g([Co,r()]),Po=g([f({target:u(Y),equals:Me}),f({target:u(Y),before:Me}),f({target:u(Y),after:Me}),f({target:u(Y),on_or_before:Me}),f({target:u(Y),on_or_after:Me}),f({target:u(Y),this_week:f({})}),f({target:u(Y),past_week:f({})}),f({target:u(Y),past_month:f({})}),f({target:u(Y),past_year:f({})}),f({target:u(Y),next_week:f({})}),f({target:u(Y),next_month:f({})}),f({target:u(Y),next_year:f({})}),f({target:u(Y),is_empty:o(!0)}),f({target:u(Y),is_not_empty:o(!0)})]),Wr=g([f({propertyId:r(),relation:mt}),f({propertyId:r(),created_by:bo}),f({propertyId:r(),title:Re}),f({propertyId:r(),rich_text:Re}),f({propertyId:r(),url:Re}),f({propertyId:r(),email:Re}),f({propertyId:r(),phone_number:Re}),f({propertyId:r(),number:So}),f({propertyId:r(),checkbox:ko}),f({propertyId:r(),select:Jr}),f({propertyId:r(),multi_select:xo}),f({propertyId:r(),status:_o}),f({propertyId:r(),date:Po}),f({propertyId:r(),people:go})]),Eo=g([Wr,f({and:E(Wr)})]),yt=10,Oo=f({propertyId:r(),direction:Hr}),Kr=n({type:o("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:P(),filter:u(Eo),sorts:u(E(Oo))});var Zr=n({type:o("resize"),height:z(P(),Ie(),xe(0))});var Yr=n({type:o("unsubscribeDataSourceQuery"),subscriptionId:r()});var en=n({type:o("updatePage"),requestId:r(),pageId:U,dataSourceId:u(K),properties:u(Oe),icon:u(ze),cover:u(Le),archived:u(h())});var tn=v("type",[Ur,zr,Kr,Yr,Fr,Xt,Kt,er,or,rr,en,Zr,Lr]);function rn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function nn(e){let t=rn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:jo(t)}}}function jo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var on=n({initializationId:r()}),Ro=n({bridgeProtocolVersion:g([P(),Ye()])});function sn(e){let{iframe:t,sandboxOrigin:s,getInitStatus:i,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:C,onCreatePage:b,onGetPage:L,onOpenPage:q,onOpenExternalUrl:A,onGetUser:O,onListUsers:H,onUpdatePage:$,onResize:X}=e;function ue(W,B){c("warn",{message:"Ignored unsupported sandbox message",payload:vt(W),issues:B});let G=nn(W);if(G.incomingType==="connect"){let ee=Pe(on,W),se=Pe(Ro,W);if(p({initializationId:ee.success?ee.output.initializationId:void 0,error:Sr(),bridgeProtocolVersion:se.success?se.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let ee=Pe(on,W);y({initializationId:ee.success?ee.output.initializationId:void 0,error:Pr()})}G.nack!==void 0&&i()!=="stopped"&&l(G.nack)}return function(B){let G=B.source===t.contentWindow,ee=B.origin===s;if(!G||!ee)return;let se=Pe(tn,B.data);if(!se.success){ue(B.data,se.issues);return}let D=se.output;if(!Tr(D)&&i()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:vt(D)});return}switch(c("in",vt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":C(D);return;case"createPage":b(D);return;case"openPage":q(D);return;case"openExternalUrl":A(D);return;case"getPage":L(D);return;case"getUser":O(D);return;case"listUsers":H(D);return;case"updatePage":$(D);return;case"resize":X(D);return;case"invalidHostMessage":return;default:re(D)}}}function vt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ve=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let s={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:s,isRefreshing:!0,shouldRefreshAgain:!1}),s}isCurrent(t,s){return this.bySubscriptionId.get(t)?.token===s}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let s=[],i=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(i=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,s.push({message:c.message,token:c.token})}return i?s:void 0}finish(t,s){let i=this.bySubscriptionId.get(t);if(i?.token===s&&(i.isRefreshing=!1,!!i.shouldRefreshAgain))return i.shouldRefreshAgain=!1,i.isRefreshing=!0,{message:i.message,token:i.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function an(e,t){if(e===void 0)return;let s="and"in e?e.and:[e];for(let i of s){let c=Mo(i,t);if(c!==void 0)return c}}function Mo(e,t){if(!Object.hasOwn(t.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let s=t.propertiesById[e.propertyId],i=Object.keys(e).find(y=>y!=="propertyId");if(i!==s.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${i}" does not match property type "${s.type}".`,isRetryable:!1};if("status"in e&&s.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,_=(Array.isArray(m)?m:[m]).find(C=>!s.groups.some(b=>b.name===C));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!xt(mt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=Bo(e);if(c===void 0||s.type!==c.propertyType)return;let l=new Set(s.options.map(y=>y.name)),p=Do(c.operator).find(y=>!l.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function Bo(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let t=e.status;return"group_equals"in t||"group_does_not_equal"in t?void 0:{propertyType:"status",operator:t}}}function Do(e){let t;if("equals"in e)t=e.equals;else if("does_not_equal"in e)t=e.does_not_equal;else if("contains"in e)t=e.contains;else if("contains_all"in e)t=e.contains_all;else if("does_not_contain"in e)t=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:re(e);return Array.isArray(t)?t:[t]}var wo=new Set(jt);function un(e,t){if(e===void 0)return;if(e.length>yt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${yt} entries.`,isRetryable:!1};let s=new Set;for(let i of e){if(s.has(i.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${i.propertyId}".`,isRetryable:!1};if(s.add(i.propertyId),!Object.hasOwn(t.propertiesById,i.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${i.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[i.propertyId];if(!wo.has(c.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${c.type}".`,isRetryable:!1}}}var ln=5;function qo(e){let{iframe:t,prepareInitialState:s,handlers:i,onInitialized:c,onConnectionFailure:l,onLog:p,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:x,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b}=e,L=Math.max(x??3,3),q=new AbortController,A,O={},H=!1,$=new AbortController,X,ue,W=6,B=new Ve(a=>{y?.(a)});function G(a,k){p?.(a,k)}function ee(a){let k=N.status;switch(k){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return re(k)}let j=Dr(a,W);G("out",j),t.contentWindow?.postMessage(j,m)}function se(a){ee(ie(He,a))}function D(a){ee(a)}function te(a){let k=N.status;switch(k){case"initialized":ee(ie(gr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:re(k)}}async function fe(a,k){if(k===void 0)return;let j=await k(a);te({type:`${a.type}Result`,requestId:a.requestId,...j})}function we(a){let k=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};te(k)}async function S(a,k=B.subscribe(a)){try{let j=To(ue,a.dataSourceId),ve=Ao(a,j);if(ve!==void 0){B.isCurrent(a.subscriptionId,k)&&(B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:{status:"error",error:ve}}));return}let Ge=await i.queryDataSource(a);if(!B.isCurrent(a.subscriptionId,k))return;Ge.status==="error"&&!Ge.error.isRetryable&&B.unsubscribe(a.subscriptionId),we({subscriptionId:a.subscriptionId,response:Ge})}finally{let j=B.finish(a.subscriptionId,k);j!==void 0&&S(j.message,j.token)}}function I(a){N.status==="stopped"||N.status==="error"||(Object.assign(O,a),oe())}async function J(a){if(i.openExternalUrl===void 0||q.signal.aborted||A===a.requestId)return;if(A!==void 0){let j={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};te(j);return}let k=qr(a.url);if(k===void 0){let j={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};te(j);return}A=a.requestId;try{let j=await i.openExternalUrl({...a,url:k},{signal:q.signal});if(q.signal.aborted)return;let ve={type:"openExternalUrlResult",requestId:a.requestId,...j};te(ve)}catch(j){if(!q.signal.aborted)throw j}finally{A===a.requestId&&(A=void 0)}}function oe(){if(N.status!=="initialized")return;let a=O;O={},a.theme!==void 0&&te({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&te({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&te({type:"parentChanged",parent:a.parent}),a.page!==void 0&&te({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&te({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&te({type:"currentUserChanged",currentUser:a.currentUser})}let N=Er({async prepareInit(a){W=a.bridgeProtocolVersion;let k=await mn;return N.status!=="preparingInit"?k:fn(k)},sendInitMessage:se,warn:a=>G("warn",a),flushPendingHostStateChanges:oe,minBridgeProtocolVersion:L,noConnectTimeoutMs:_,initialStateTimeoutMs:C,noInitResultTimeoutMs:b,stopHostWithFailure:gt,onInitResult(a){a.status==="success"&&X!==void 0&&c?.({manifest:X,initialHeight:a.initialHeight})},onConnectionFailure:a=>{$.abort(),l?.(a)}});function fn(a){if(a.status==="error")return a;let k=ie(wr,{...a.initialState,...O});if(X=k.manifest,O={},W<ln&&k.page.type==="unavailable")return{status:"error",error:ut()};let j=pn(k.manifest,k.dataSources);return j!==void 0?{status:"error",error:j}:(ue=k.dataSources,H=!0,{status:"success",initialState:k})}let mn=yn().catch(a=>($.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:je()}));async function yn(){let a=await Or({...e,sandboxOrigin:m,signal:$.signal,onError:j=>{G("warn",{message:"Failed to load custom block manifest",error:j})}});if(a.status==="error")return a;if($.signal.aborted)return{status:"error",error:je()};let k=await s({manifest:a.manifest,signal:$.signal});return k.status==="error"?k:{status:"success",initialState:{...k.initialState,manifest:a.manifest}}}let dt=sn({iframe:t,sandboxOrigin:m,getInitStatus:()=>N.status,emit:G,sendNack:D,onInvalidConnect:N.handleInvalidConnect,onInvalidInitResult:N.handleInvalidInitResult,onConnect:N.handleConnect,onInitResult:N.handleInitResult,onQueryDataSource:S,onUnsubscribeDataSourceQuery:a=>B.unsubscribe(a.subscriptionId),onOpenExternalUrl:J,onCreatePage:a=>fe(a,i.createPage),onGetPage:a=>fe(a,i.getPage),onOpenPage:a=>fe(a,i.openPage),onGetUser:a=>fe(a,i.getUser),onListUsers:a=>fe(a,i.listUsers),onUpdatePage:a=>fe(a,i.updatePage),onResize:a=>i.resize?.(a)});window.addEventListener("message",dt),t.addEventListener("load",N.onIframeLoad);function ht(){q.abort(),$.abort(),window.removeEventListener("message",dt),t.removeEventListener("load",N.onIframeLoad),N.stop(),B.unsubscribeAll()}function gt(a){ht(),G("warn",a),l?.(a)}return{stop:ht,setTheme(a){I({theme:a})},setContrastMode(a){I({contrastMode:a})},setParent(a){I({parent:a})},setPage(a){if(a.type==="unavailable"&&W<ln&&(N.status==="preparingInit"&&H||N.status==="waitingForInitResult"||N.status==="initialized")){gt({...ut(),phase:"runtime",source:"host"});return}I({page:a})},setCurrentUser(a){I({currentUser:a})},setDataSources(a){let k={bindings:ie(me,a.bindings)};if(N.hasConnectedSandbox&&X!==void 0&&pn(X,k)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:k});return}ue=k,I({dataSources:k})},refreshQuery({dataSourceId:a}){if(N.status!=="initialized")return;let k=ie(K,a),j=B.refresh(k);if(j===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ve of j)S(ve.message,ve.token)}}}function To(e,t){return Object.values(e?.bindings??{}).find(s=>s.collectionPointer?.id===t)?.collectionSchema}function pn(e,t){for(let[s,i]of Object.entries(e.dataSources)){let c=t.bindings[s];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Ir();for(let[l,p]of Object.entries(i.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return _r();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return xr()}}}function Ao(e,t){return t===void 0?e.filter===void 0&&(e.sorts?.length??0)===0?void 0:{code:"data_source_schema_unavailable",message:"You cannot query this data source with filters or sorts because its schema is unavailable.",isRetryable:!1}:an(e.filter,t)??un(e.sorts,t)}function No(e){return ie(U,e)}export{de as InvalidNotionDateError,$e as LATEST_BRIDGE_PROTOCOL_VERSION,Qe as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,qo as createCustomBlockHost,vn as getAutoBoundPropertyIdsByKey,lt as isLocalCustomBlockUrl,pt as toNotionDateValue,No as toNotionPageId};
|
|
1
|
+
function On(e){let{manifestProperties:t,propertySchemasById:i}=e,s=[];for(let[c,l]of Object.entries(t)){let p=Rn({propertyKey:c,manifestProperty:l,propertySchemasById:i});p!==void 0&&s.push([c,p])}return Object.fromEntries(s)}function Rn(e){let{propertyKey:t,manifestProperty:i,propertySchemasById:s}=e,c=Pt(i.name),l=Object.entries(s).filter(([p,y])=>y.type===i.type&&(p===t||Pt(y.name)===c));return l.length===1?l[0][0]:void 0}function Pt(e){return e.trim().toLowerCase()}var Ne,jn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function et(e){return!e&&!Ne?jn:{lang:e?.lang??Ne?.lang,message:e?.message,abortEarly:e?.abortEarly??Ne?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Ne?.abortPipeEarly}}var Mn;function Bn(e){return Mn?.get(e)}var Dn;function wn(e){return Dn?.get(e)}var Tn;function qn(e,t){return Tn?.get(e)?.get(t)}function he(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function w(e,t,i,s,c){let l=c&&"input"in c?c.input:i.value,p=c?.expected??e.expects??null,y=c?.received??he(l),m={kind:e.kind,type:e.type,input:l,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},x=e.kind==="schema",_=c?.message??e.message??qn(e.reference,m.lang)??(x?wn(m.lang):null)??s.message??Bn(m.lang);_!==void 0&&(m.message=typeof _=="function"?_(m):_),x&&(i.typed=!1),i.issues?i.issues.push(m):i.issues=[m]}function An(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Nn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function tt(e,t){let i=[...new Set(e)];return i.length>1?`(${i.join(` ${t} `)})`:i[0]??"never"}function X(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},et())},e}var Un=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ae(e){return{kind:"transformation",type:"brand",reference:ae,async:!1,name:e,"~run"(t){return t}}}function xe(e){return{kind:"validation",type:"finite",reference:xe,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,i){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,i),t}}}function rt(e,t){let i=he(e);return{kind:"validation",type:"includes",reference:rt,async:!1,expects:i,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&w(this,"content",s,c,{received:`!${i}`}),s}}}function Ue(e,t){return{kind:"validation",type:"max_length",reference:Ue,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length>this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Ce(e,t){return{kind:"validation",type:"min_length",reference:Ce,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&i.value.length<this.requirement&&w(this,"length",i,s,{received:`${i.value.length}`}),i}}}function Pe(e,t){return{kind:"validation",type:"min_value",reference:Pe,async:!1,expects:`>=${e instanceof Date?e.toJSON():he(e)}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!(i.value>=this.requirement)&&w(this,"value",i,s,{received:i.value instanceof Date?i.value.toJSON():he(i.value)}),i}}}function nt(e,t){return{kind:"validation",type:"regex",reference:nt,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(i,s){return i.typed&&!this.requirement.test(i.value)&&w(this,"format",i,s),i}}}function ot(e){return{kind:"transformation",type:"transform",reference:ot,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var Ot={abortEarly:!0};function Rt(e,t,i){return typeof e.fallback=="function"?e.fallback(t,i):e.fallback}function Fe(e,t,i){return typeof e.default=="function"?e.default(t,i):e.default}function jt(e,t){return!e["~run"]({value:t},Ot).issues}function O(e,t){return X({kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:t,"~run"(i,s){let c=i.value;if(Array.isArray(c)){i.typed=!0,i.value=[];for(let l=0;l<c.length;l++){let p=c[l],y=this.item["~run"]({value:p},s);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:p};for(let x of y.issues)x.path?x.path.unshift(m):x.path=[m],i.issues?.push(x);if(i.issues||(i.issues=y.issues),s.abortEarly){i.typed=!1;break}}y.typed||(i.typed=!1),i.value.push(y.value)}}else w(this,"type",i,s);return i}})}function g(e){return X({kind:"schema",type:"boolean",reference:g,expects:"boolean",async:!1,message:e,"~run"(t,i){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,i),t}})}function o(e,t){return X({kind:"schema",type:"literal",reference:o,expects:he(e),async:!1,literal:e,message:t,"~run"(i,s){return An(i.value,this.literal)?i.typed=!0:w(this,"type",i,s),i}})}function it(e){return X({kind:"schema",type:"nan",reference:it,expects:"NaN",async:!1,message:e,"~run"(t,i){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function z(e,t){return X({kind:"schema",type:"nullable",reference:z,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===null&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===null)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function E(e){return X({kind:"schema",type:"number",reference:E,expects:"number",async:!1,message:e,"~run"(t,i){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,i),t}})}function n(e,t){return X({kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}}else w(this,"type",i,s);return i}})}function u(e,t){return X({kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(i,s){return i.value===void 0&&(this.default!==void 0&&(i.value=Fe(this,i,s)),i.value===void 0)?(i.typed=!0,i):this.wrapped["~run"](i,s)}})}function T(e,t){return X({kind:"schema",type:"picklist",reference:T,expects:tt(e.map(he),"|"),async:!1,options:e,message:t,"~run"(i,s){return this.options.includes(i.value)?i.typed=!0:w(this,"type",i,s),i}})}function $(e,t,i){return X({kind:"schema",type:"record",reference:$,expects:"Object",async:!1,key:e,value:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let p in l)if(Nn(l,p)){let y=l[p],m=this.key["~run"]({value:p},c);if(m.issues){let _={type:"object",origin:"key",input:l,key:p,value:y};for(let B of m.issues)B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=m.issues),c.abortEarly){s.typed=!1;break}}let x=this.value["~run"]({value:y},c);if(x.issues){let _={type:"object",origin:"value",input:l,key:p,value:y};for(let B of x.issues)B.path?B.path.unshift(_):B.path=[_],s.issues?.push(B);if(s.issues||(s.issues=x.issues),c.abortEarly){s.typed=!1;break}}(!m.typed||!x.typed)&&(s.typed=!1),m.typed&&(s.value[m.value]=x.value)}}else w(this,"type",s,c);return s}})}function f(e,t){return X({kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,"~run"(i,s){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let l in this.entries){let p=this.entries[l];if(l in c||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=l in c?c[l]:Fe(p),m=p["~run"]({value:y},s);if(m.issues){let x={type:"object",origin:"value",input:c,key:l,value:y};for(let _ of m.issues)_.path?_.path.unshift(x):_.path=[x],i.issues?.push(_);if(i.issues||(i.issues=m.issues),s.abortEarly){i.typed=!1;break}}m.typed||(i.typed=!1),i.value[l]=m.value}else if(p.fallback!==void 0)i.value[l]=Rt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(w(this,"key",i,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!i.issues||!s.abortEarly){for(let l in c)if(!Object.prototype.hasOwnProperty.call(this.entries,l)){w(this,"key",i,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else w(this,"type",i,s);return i}})}function r(e){return X({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,i){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,i),t}})}function Et(e){let t;if(e)for(let i of e)if(t)for(let s of i.issues)t.push(s);else t=i.issues;return t}function b(e,t){return X({kind:"schema",type:"union",reference:b,expects:tt(e.map(i=>i.expects),"|"),async:!1,options:e,message:t,"~run"(i,s){let c,l,p;for(let y of this.options){let m=y["~run"]({value:i.value},s);if(m.typed)if(m.issues)l?l.push(m):l=[m];else{c=m;break}else p?p.push(m):p=[m]}if(c)return c;if(l){if(l.length===1)return l[0];w(this,"type",i,s,{issues:Et(l)}),i.typed=!0}else{if(p?.length===1)return p[0];w(this,"type",i,s,{issues:Et(p)})}return i}})}function Ee(){return X({kind:"schema",type:"unknown",reference:Ee,expects:"unknown",async:!1,"~run"(e){return e.typed=!0,e}})}function v(e,t,i){return X({kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:i,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let p,y=0,m=this.key,x=[],_=(B,Q)=>{for(let H of B.options){if(H.type==="variant")_(H,new Set(Q).add(H.key));else{let h=!0,q=0;for(let R of Q){let U=H.entries[R];if(R in l?U["~run"]({typed:!1,value:l[R]},Ot).issues:U.type!=="exact_optional"&&U.type!=="optional"&&U.type!=="nullish"){h=!1,m!==R&&(y<q||y===q&&R in l&&!(m in l))&&(y=q,m=R,x=[]),m===R&&x.push(H.entries[R].expects);break}q++}if(h){let R=H["~run"]({value:l},c);(!p||!p.typed&&R.typed)&&(p=R)}}if(p&&!p.issues)break}};if(_(this,new Set([this.key])),p)return p;w(this,"type",s,c,{input:l[m],expected:tt(x,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else w(this,"type",s,c);return s}})}function Mt(e,t){let i={...e.entries};for(let s of t)delete i[s];return X({...e,entries:i})}function ie(e,t,i){let s=e["~run"]({value:t},et(i));if(s.issues)throw new Un(s.issues);return s.value}function V(...e){return X({...e[0],pipe:e,"~run"(t,i){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!i.abortEarly&&!i.abortPipeEarly)&&(t=s["~run"](t,i))}return t}})}function ge(e,t,i){let s=e["~run"]({value:t},et(i));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var ue=V(r(),ae("NotionBlockId")),K=V(r(),ae("NotionDataSourceId")),N=V(r(),ae("NotionPageId")),Bt=V(r(),ae("NotionAgentId")),Dt=V(r(),ae("NotionSpaceId"));var wt=T(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),st=n({id:r(),name:r(),color:u(wt),description:u(r())}),Fn=n({id:r(),name:r(),color:u(wt),option_ids:O(r())}),zn=n({synced_property_id:r(),synced_property_name:r()}),j=n({name:r(),description:u(r())}),Hn=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],Tt=T(Hn),qt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],at=v("type",[n({...j.entries,type:o("title")}),n({...j.entries,type:o("rich_text")}),n({...j.entries,type:o("number")}),n({...j.entries,type:o("checkbox")}),n({...j.entries,type:o("url")}),n({...j.entries,type:o("email")}),n({...j.entries,type:o("phone_number")}),n({...j.entries,type:o("select"),options:O(st)}),n({...j.entries,type:o("multi_select"),options:O(st)}),n({...j.entries,type:o("status"),options:O(st),groups:O(Fn)}),n({...j.entries,type:o("date")}),n({...j.entries,type:o("people")}),n({...j.entries,type:o("files")}),n({...j.entries,type:o("unique_id")}),n({...j.entries,type:o("relation"),data_source_id:u(r()),dual_property:u(zn)}),n({...j.entries,type:o("place")}),n({...j.entries,type:o("formula")}),n({...j.entries,type:o("rollup")}),n({...j.entries,type:o("button")}),n({...j.entries,type:o("verification")}),n({...j.entries,type:o("last_visited_time")}),n({...j.entries,type:o("location")}),n({...j.entries,type:o("created_time")}),n({...j.entries,type:o("last_edited_time")}),n({...j.entries,type:o("created_by")}),n({...j.entries,type:o("last_edited_by")})]);var At={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var Nt=n({id:K,table:r(),spaceId:u(Dt)}),Ut=n({id:u(K),propertiesById:$(r(),at)}),ai=n({key:r(),collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:$(r(),u(r())),propertySchemasById:$(r(),at)}),Ln=n({collectionPointer:u(Nt),collectionSchema:u(Ut),propertyIdsByKey:u($(r(),u(r())))}),me=$(r(),Ln);var be=T(["standard","high"]),Ft="standard";var zt=n({type:o("contrastModeChanged"),contrastMode:be});var ze=n({unit:T(["year","month","week","day"]),value:E(),time:r(),defaultTimeZone:u(r())}),Vn=n({unit:T(["hour","minute"]),value:E()}),Oe=n({unit:o("none")}),ut=b([ze,Vn]),Ht=u(b([ze,Oe])),Lt=u(b([ut,Oe])),Gn=n({type:o("date"),start_date:r(),reminder:Ht}),$n=n({type:o("daterange"),start_date:r(),end_date:r(),reminder:Ht}),Qn=n({type:o("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:Lt}),Wn=n({type:o("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:Lt}),Vt=v("type",[Gn,$n,Qn,Wn]);var He=n({id:r(),table:r()});var se=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K}),n({type:o("workspace"),workspace:o(!0)}),n({type:o("block_id"),block_id:ue}),n({type:o("agent_id"),agent_id:Bt}),n({type:o("unavailable")})]);var Se=v("type",[n({type:o("unavailable")}),n({type:o("page"),id:N,parent:se})]),Xn=n({type:o("emoji"),emoji:r()}),Kn=n({type:o("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),$t=n({type:o("external"),external:n({url:r()})}),Qt=n({type:o("file"),file:n({url:r(),expiry_time:u(r())})}),Ve=v("type",[Xn,Kn,$t,Qt]),Ge=v("type",[$t,Qt]),Z=z(r()),Gt=$(r(),Ee()),ct=b([n({id:r(),name:u(r()),color:u(r()),description:u(Z)}),n({name:r(),id:u(r()),color:u(r()),description:u(Z)})]),lt={start:r(),end:u(Z),time_zone:u(Z),reminder:u(b([ut,Oe]))},Zn=b([n({...lt,start:V(r(),rt("T"))}),n({...lt,time_zone:r()}),n({...lt,reminder:u(b([ze,Oe]))})]),Jn=b([n({object:u(o("user")),id:r()}),n({object:o("group"),id:r(),name:u(Z)})]),Yn=n({id:r()}),eo=b([n({type:o("external"),name:r(),external:n({url:r()})}),n({type:o("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),to=n({lat:E(),lon:E(),name:u(Z),address:u(Z),aws_place_id:u(Z),google_place_id:u(Z)}),M={id:r()},Le=z(n({...He.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Wt=v("type",[n({...M,type:o("title"),title:O(Gt)}),n({...M,type:o("rich_text"),rich_text:O(Gt)}),n({...M,type:o("number"),number:z(E())}),n({...M,type:o("url"),url:Z}),n({...M,type:o("email"),email:Z}),n({...M,type:o("phone_number"),phone_number:Z}),n({...M,type:o("checkbox"),checkbox:g()}),n({...M,type:o("select"),select:z(ct)}),n({...M,type:o("status"),status:z(ct)}),n({...M,type:o("multi_select"),multi_select:O(ct)}),n({...M,type:o("date"),date:z(Zn)}),n({...M,type:o("people"),people:O(Jn)}),n({...M,type:o("relation"),has_more:u(g()),relation:O(Yn)}),n({...M,type:o("files"),files:O(eo)}),n({...M,type:o("place"),place:z(to)}),n({...M,type:o("created_time"),created_time:Z}),n({...M,type:o("last_edited_time"),last_edited_time:Z}),n({...M,type:o("created_by"),created_by:Le}),n({...M,type:o("last_edited_by"),last_edited_by:Le}),n({...M,type:o("last_visited_time"),last_visited_time:Z}),n({...M,type:o("unique_id"),unique_id:r()}),n({...M,type:o("button"),button:r()}),n({...M,type:o("formula"),formula:r()}),n({...M,type:o("location"),location:r()}),n({...M,type:o("rollup"),rollup:r()}),n({...M,type:o("verification"),verification:r()})]),Re=$(r(),Wt),ro=$(r(),z(Wt)),re=n({object:o("page"),id:N,parent:se,properties:ro,created_by:u(Le,null),last_edited_by:u(Le,null),last_visited_time:u(z(r()),null),created_time:u(z(r()),null),last_edited_time:u(z(r()),null),icon:u(z(Ve),null),cover:u(z(Ge),null),url:u(z(r()),null),public_url:u(z(r()),null),is_archived:g(),in_trash:g()}),ke=n({object:o("page"),id:N,parent:se,properties:Re,created_time:u(r()),last_edited_time:u(r()),icon:u(Ve),cover:u(Ge),url:u(r()),public_url:u(r()),is_archived:g(),in_trash:g()});var no=r(),Xt=n({code:no,message:r(),isRetryable:g()}),Kt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]),Zt=v("status",[n({type:o("createPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("createPageResult"),requestId:r(),status:o("error"),error:Xt})]);var pt=V(r(),ae("NotionUserId")),ce=n({object:o("user"),id:pt,name:u(r()),avatar_url:z(r()),type:o("person"),person:n({email:r()})}),Jt=n({object:o("list"),results:O(ce),next_cursor:z(r()),has_more:g(),type:o("user"),user:$(r(),Ee())});var Yt=n({type:o("currentUserChanged"),currentUser:ce});var er=n({type:o("dataSourcesChanged"),dataSources:n({bindings:me})});var oo=r(),tr=n({code:oo,message:r(),isRetryable:g()}),rr=n({type:o("getPage"),requestId:r(),pageId:N,dataSourceId:u(K)}),nr=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]),or=v("status",[n({type:o("getPageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("getPageResult"),requestId:r(),status:o("error"),error:tr})]);var io=r(),so=n({code:io,message:r(),isRetryable:g()}),ir=n({type:o("getUser"),requestId:r(),userId:pt}),sr=v("status",[n({type:o("getUserResult"),requestId:r(),status:o("success"),user:ce}),n({type:o("getUserResult"),requestId:r(),status:o("error"),error:so})]);var ao=v("type",[n({type:o("emoji"),emoji:r()}),n({type:o("external"),url:r()})]),uo=n({name:r(),description:u(r()),type:Tt}),co=n({name:r(),description:u(r()),icon:u(ao),properties:u($(r(),uo),{})}),ve=n({version:o(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:o("emoji"),emoji:r()})),dataSources:u($(r(),co),{})});var Ie=T(["light","dark"]);var lo=r(),$e=n({code:lo,message:r(),isRetryable:g()}),je=class extends Error{constructor(t){super(t.message),this.name="CustomBlockInitializationError",this.code=t.code,this.isRetryable=t.isRetryable}code;isRetryable},Qe=v("status",[n({type:o("init"),initializationId:r(),status:o("success"),theme:Ie,contrastMode:be,blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),n({type:o("init"),initializationId:r(),status:o("error"),error:$e})]);var ar=n({type:o("invalidSandboxMessage"),reason:r()});var po=r(),fo=n({code:po,message:r(),isRetryable:g()}),ur=n({type:o("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(E())}),cr=v("status",[n({type:o("listUsersResult"),requestId:r(),status:o("success"),list:Jt}),n({type:o("listUsersResult"),requestId:r(),status:o("error"),error:fo})]);var mo=r(),yo=n({code:mo,message:r(),isRetryable:g()}),lr=n({type:o("openExternalUrl"),requestId:r(),url:r()}),pr=v("status",[n({type:o("openExternalUrlResult"),requestId:r(),status:o("success")}),n({type:o("openExternalUrlResult"),requestId:r(),status:o("error"),error:yo})]);var vo=T(["side_peek","center_peek"]),ho=r(),go=n({code:ho,message:r(),isRetryable:g()}),fr=n({type:o("openPage"),requestId:r(),pageId:N,mode:vo}),mr=v("status",[n({type:o("openPageResult"),requestId:r(),status:o("success"),pageId:N}),n({type:o("openPageResult"),requestId:r(),status:o("error"),error:go})]);var yr=n({type:o("pageChanged"),page:Se});var vr=n({type:o("parentChanged"),parent:se});var dr=b([r(),E(),g(),Vt,O(r()),O(He)]);var hr=n({id:N,is_archived:g(),in_trash:g(),propertiesById:$(r(),u(dr))});var bo=r(),gr=n({code:bo,message:r(),isRetryable:g()}),br=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(re),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]),Sr=v("status",[n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("success"),items:O(b([re,hr])),hasMore:g()}),n({type:o("queryDataSourceResult"),subscriptionId:r(),status:o("error"),error:gr})]);var kr=n({type:o("themeChanged"),theme:Ie});var So=r(),Ir=n({code:So,message:r(),isRetryable:g()}),_r=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:re}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]),xr=v("status",[n({type:o("updatePageResult"),requestId:r(),status:o("success"),page:b([re,ke])}),n({type:o("updatePageResult"),requestId:r(),status:o("error"),error:Ir})]);var Cr=v("type",[Qe,kr,zt,vr,yr,Yt,er,sr,cr,mr,pr,ar]),Pr=v("type",[...Cr.options,br,nr,Kt,_r]),js=v("type",[...Cr.options,Sr,or,Zt,xr]);function Er(e){return{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([t,i])=>[t,{...i,collectionSchema:{...i.collectionSchema,propertiesById:{...i.collectionSchema?.propertiesById,...At}}}]))}}}var de=class extends Error{};function ft(e){try{return ko(e)}catch(t){throw t instanceof RangeError?new de(t.message):t}}function ko(e){let{start:t,end:i,time_zone:s,reminder:c}=e;if(!t.split("T")[0])throw new de("Date values must include a date.");let l=t.includes("T")||s!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),y=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,m=s?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=m?(Number(m[2]??0)*60+Number(m[3]??0))*(m[1]==="-"?-1:1):y,_=h=>{if(!h.split("T")[0])throw new de("Date values must include a date.");if(!h.includes("T"))return{date:h,time:"00:00"};let q=h.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(q)return{date:q[1],time:q[2]};if(!s||m){let A=new Date(new Date(h).getTime()+x*6e4).toISOString();return{date:A.slice(0,10),time:A.slice(11,16)}}let R=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(h)),U=A=>R.find(te=>te.type===A)?.value;return{date:`${U("year")}-${U("month")}-${U("day")}`,time:`${U("hour")}:${U("minute")}`}},B=_(t),Q=i?_(i):void 0;if(!l){if(c&&!("time"in c)&&c.unit!=="none")throw new de("Hour and minute reminders require a date with a time.");return Q?{type:"daterange",start_date:B.date,end_date:Q.date,reminder:c}:{type:"date",start_date:B.date,reminder:c}}let H=s??(y===0?"UTC":`UTC${y<0?"-":"+"}${Math.floor(Math.abs(y)/60)}${Math.abs(y)%60===0?"":`:${String(Math.abs(y)%60).padStart(2,"0")}`}`);return Q?{type:"datetimerange",start_date:B.date,start_time:B.time,end_date:Q.date,end_time:Q.time,time_zone:H,reminder:c}:{type:"datetime",start_date:B.date,start_time:B.time,time_zone:H,reminder:c}}function ee(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function Rr(e){return{...e,properties:Object.fromEntries(Object.values(e.properties).flatMap(t=>t?[[t.id,t]]:[])),icon:e.icon??void 0,cover:e.cover??void 0,created_time:e.created_time??void 0,last_edited_time:e.last_edited_time??void 0,url:e.url??void 0,public_url:e.public_url??void 0}}function jr(e){let t={};for(let i of Object.values(e.properties))i&&(t[i.id]=Io(i));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:{...t,created_time:Me(e.created_time),last_edited_time:Me(e.last_edited_time),created_by:e.created_by?[e.created_by]:void 0,last_edited_by:e.last_edited_by?[e.last_edited_by]:void 0}}}function Or(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let i=t.text;return i&&typeof i=="object"&&"content"in i&&typeof i.content=="string"?i.content:""}).join("")}function Me(e){if(e==null||e==="")return;let t=new Date(e);if(Number.isFinite(t.getTime()))return{type:"datetime",start_date:t.toISOString().slice(0,10),start_time:t.toISOString().slice(11,16),time_zone:"UTC"}}function Io(e){switch(e.type){case"title":return Or(e.title);case"rich_text":return Or(e.rich_text);case"number":return e.number??void 0;case"checkbox":return e.checkbox;case"url":return e.url??"";case"email":return e.email??"";case"phone_number":return e.phone_number??"";case"select":return e.select?.name;case"status":return e.status?.name;case"multi_select":return e.multi_select.flatMap(t=>t.name??[]);case"date":return e.date?ft(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return Me(e.created_time);case"last_edited_time":return Me(e.last_edited_time);case"last_visited_time":return Me(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return ee(e)}}function Be(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,i])=>{switch(i?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];case"title":case"rich_text":case"number":case"url":case"email":case"phone_number":case"checkbox":case"select":case"status":case"multi_select":case"date":case"people":case"relation":case"files":case"place":case"created_time":case"last_edited_time":case"created_by":case"last_edited_by":case"last_visited_time":case void 0:return[t,i];default:return ee(i)}}))}}function Mr(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(jr)}:{...e,page:Rr(Be(e.page))}}function Br(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(Be)}:{...e,page:Be(e.page)}}function Dr(e,t){return e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged"?t<5?Er(e):e:e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"||e.status==="error"?e:t<6?Mr(e):t<7?Br(e):e}function wr(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}function We({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&wr(e)}function Tr(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function qr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function mt(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function yt(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:i}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${i}.`,isRetryable:!1}}function vt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Ar(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Nr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function Ur(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function Fr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function zr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function Hr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Xe(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function dt(){return{code:"invalid_local_preview_url",message:"Local custom blocks require an HTTP(S) URL on localhost, a .localhost subdomain, or 127.0.0.1, without credentials and on a different origin from the host.",isRetryable:!1}}function ht(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Co=5e3,Po=5e3,Eo=5e3;function Lr(e){let{manifestSource:t,prepareInit:i,sendInitMessage:s,warn:c,flushPendingHostStateChanges:l,minBridgeProtocolVersion:p,noConnectTimeoutMs:y=Co,initialStateTimeoutMs:m=Po,noInitResultTimeoutMs:x=Eo,stopHostWithFailure:_,onInitResult:B,onInitSent:Q,onConnectionFailure:H}=e,h="waitingForConnect",q,R,U,A,te=!1,le=!1;function W(){q!==void 0&&(window.clearTimeout(q),q=void 0)}function F(){R!==void 0&&(window.clearTimeout(R),R=void 0)}function G(){U!==void 0&&(window.clearTimeout(U),U=void 0)}function L(k){let{initializationId:C,error:I,phase:oe,source:Ze}=k;switch(h){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"failed":case"stopped":return;default:return ee(h)}h="failed",A=C,W(),F(),s({type:"init",initializationId:C,status:"error",error:I}),H({...I,phase:oe,source:Ze})}async function ne(k){if(h==="waitingForConnect"){h="preparingInit",A=k.initializationId,W(),R=window.setTimeout(()=>{if(h!=="preparingInit")return;let C=Ar();c({...C,initializationId:k.initializationId}),L({initializationId:k.initializationId,error:C,phase:"init",source:"host"})},m);try{let C=await i(k);if(h!=="preparingInit")return;if(F(),C.status==="error"){L({initializationId:k.initializationId,error:C.error,phase:"init",source:"host"});return}h="waitingForInitResult";let I={type:"init",initializationId:k.initializationId,status:"success",theme:C.initialState.theme,contrastMode:C.initialState.contrastMode??Ft,blockId:C.initialState.blockId,parent:C.initialState.parent,page:C.initialState.page,currentUser:C.initialState.currentUser,manifest:C.initialState.manifest,dataSources:C.initialState.dataSources};if(s(I),h!=="waitingForInitResult"||(Q(),h!=="waitingForInitResult"))return;U=window.setTimeout(()=>{if(h!=="waitingForInitResult")return;h="failed";let oe=zr();H({...oe,phase:"initResult",source:"host"}),c({...oe,initializationId:k.initializationId})},x)}catch(C){if(h!=="preparingInit")return;c({message:"Failed to prepare custom block initialization",error:C}),L({initializationId:k.initializationId,error:Xe(),phase:"init",source:"host"})}}}function D(k){if(h!=="stopped"&&h==="waitingForConnect"){if(!ht(k.bridgeProtocolVersion)){let C=mt({currentBridgeProtocolVersion:k.bridgeProtocolVersion});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.bridgeProtocolVersion<p){let C=yt({currentBridgeProtocolVersion:k.bridgeProtocolVersion,minBridgeProtocolVersion:p});L({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.status==="error"&&(t==="sandbox"||k.error.code!=="manifest_invalid")){L({initializationId:k.initializationId,error:k.error,phase:"connect",source:"sandbox"});return}le=!0,ne(k)}}function Y(k){if(h==="stopped"||h!=="waitingForConnect")return"handled";let{initializationId:C,bridgeProtocolVersion:I}=k;if(C===void 0)return"nack";let oe=k.error;return I!==void 0&&(ht(I)?I<p&&(oe=yt({currentBridgeProtocolVersion:I,minBridgeProtocolVersion:p})):oe=mt({currentBridgeProtocolVersion:I})),L({initializationId:C,error:oe,phase:"connect",source:"host"}),"handled"}function pe(k){let{initializationId:C,error:I}=k;h!=="waitingForInitResult"||C===void 0||C!==A||(W(),G(),h="failed",c(I),H({...I,phase:"initResult",source:"host"}))}function Ae(){if(h!=="stopped"){if(te){_({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}te=!0,W(),h==="waitingForConnect"&&(q=window.setTimeout(()=>{if(h!=="waitingForConnect")return;h="failed";let k=Tr();c(k),H({...k,phase:"connect",source:"host"})},y))}}function _e(k){if(h!=="waitingForInitResult"||k.initializationId!==A){c({message:"Ignored stale or unexpected initResult",payload:k});return}G(),h=k.status==="success"?"initialized":"failed",k.status==="success"?l():H({...k.error,phase:"initResult",source:"sandbox"}),B(k)}function fe(){h="stopped",W(),F(),G()}return{get status(){return h},get hasConnectedSandbox(){return le},handleConnect:D,handleInitResult:_e,handleInvalidConnect:Y,handleInvalidInitResult:pe,onIframeLoad:Ae,stop:fe}}async function Vr(e){return e.manifestSource==="host"?e.hostManifest:e.connectManifest!==void 0?{status:"success",manifest:e.connectManifest}:{status:"error",error:{code:"manifest_unavailable",message:"The sandbox did not provide a manifest in connect.",isRetryable:!1}}}var Gr=v("status",[n({status:o("success"),manifest:ve}),n({status:o("error"),error:$e})]),gt=n({theme:Ie,contrastMode:u(be),blockId:ue,parent:se,page:Se,manifest:ve,dataSources:n({bindings:me}),currentUser:ce}),$r=v("status",[n({status:o("success"),initialState:Mt(gt,["manifest"])}),n({status:o("error"),error:$e})]);function Qr(e){if(e.length>2048||!URL.canParse(e))return;let t=new URL(e);if(!(t.protocol!=="http:"&&t.protocol!=="https:"||t.username!==""||t.password!==""||t.href.length>2048))return t.href}function Wr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Xr=n({code:r(),message:r(),isRetryable:g()});var Kr={type:o("connect"),initializationId:r(),bridgeProtocolVersion:E(),sdkVersion:r()},Zr=v("status",[n({status:o("success"),manifest:u(ve),...Kr}),n({status:o("error"),error:Xr,...Kr})]);var Oo=v("type",[n({type:o("start")}),n({type:o("end")}),n({type:o("before"),blockId:ue}),n({type:o("after"),blockId:ue})]),Ro=v("type",[n({type:o("page_id"),page_id:N}),n({type:o("data_source_id"),data_source_id:K})]),Jr=n({type:o("createPage"),requestId:r(),parent:Ro,properties:Re,position:u(Oo)});var jo=r(),Mo=n({code:jo,message:r(),isRetryable:g()}),Yr=v("status",[n({type:o("initResult"),initializationId:r(),status:o("success"),initialHeight:u(V(E(),xe(),Pe(0)))}),n({type:o("initResult"),initializationId:r(),status:o("error"),error:Mo})]);var en=n({type:o("invalidHostMessage"),reason:r()});var tn=T(["ascending","descending"]);var rn=V(N,nt(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),ot(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),bt=b([f({contains:rn}),f({does_not_contain:rn})]),qe=b([f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),Te=b([r(),O(r())]),nn=f({object:T(["user","group"]),id:V(r(),Ce(1))}),Bo=b([f({contains:nn}),f({does_not_contain:nn}),qe]),on=f({object:o("user"),id:V(r(),Ce(1),Ue(2e3))}),Do=b([f({contains:on}),f({does_not_contain:on}),f({is_empty:o(!0)}),f({is_not_empty:o(!0)})]),De=b([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),qe]),wo=b([f({equals:E()}),f({does_not_equal:E()}),f({greater_than:E()}),f({less_than:E()}),f({greater_than_or_equal_to:E()}),f({less_than_or_equal_to:E()}),qe]),To=b([f({equals:g()}),f({does_not_equal:g()})]),cn=b([f({equals:Te}),f({does_not_equal:Te}),qe]),sn=T(["To-do","In progress","Complete","Current","Future"]),an=b([sn,V(O(sn),Ce(1),Ue(5))]),qo=b([f({group_equals:an}),f({group_does_not_equal:an})]),Ao=b([cn,qo]),No=b([f({contains:Te}),f({contains_all:Te}),f({does_not_contain:Te}),qe]),J=T(["start_date","end_date"]),Uo=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),we=b([Uo,r()]),Fo=b([f({target:u(J),equals:we}),f({target:u(J),before:we}),f({target:u(J),after:we}),f({target:u(J),on_or_before:we}),f({target:u(J),on_or_after:we}),f({target:u(J),this_week:f({})}),f({target:u(J),past_week:f({})}),f({target:u(J),past_month:f({})}),f({target:u(J),past_year:f({})}),f({target:u(J),next_week:f({})}),f({target:u(J),next_month:f({})}),f({target:u(J),next_year:f({})}),f({target:u(J),is_empty:o(!0)}),f({target:u(J),is_not_empty:o(!0)})]),un=b([f({propertyId:r(),relation:bt}),f({propertyId:r(),created_by:Do}),f({propertyId:r(),title:De}),f({propertyId:r(),rich_text:De}),f({propertyId:r(),url:De}),f({propertyId:r(),email:De}),f({propertyId:r(),phone_number:De}),f({propertyId:r(),number:wo}),f({propertyId:r(),checkbox:To}),f({propertyId:r(),select:cn}),f({propertyId:r(),multi_select:No}),f({propertyId:r(),status:Ao}),f({propertyId:r(),date:Fo}),f({propertyId:r(),people:Bo})]),zo=b([un,f({and:O(un)})]),St=10,Ho=f({propertyId:r(),direction:tn}),ln=n({type:o("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:E(),filter:u(zo),sorts:u(O(Ho))});var pn=n({type:o("resize"),height:V(E(),xe(),Pe(0))});var fn=n({type:o("unsubscribeDataSourceQuery"),subscriptionId:r()});var mn=n({type:o("updatePage"),requestId:r(),pageId:N,dataSourceId:u(K),properties:u(Re),icon:u(Ve),cover:u(Ge),archived:u(g())});var yn=v("type",[Zr,Yr,ln,fn,Jr,rr,ir,ur,fr,lr,mn,pn,en]);function vn(e){return ge(yn,e)}function dn(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function hn(e){let t=dn(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:Lo(t)}}}function Lo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var gn=n({initializationId:r()}),Vo=n({bridgeProtocolVersion:b([E(),it()])});function bn(e){let{iframe:t,sandboxOrigin:i,getInitStatus:s,emit:c,sendNack:l,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:x,onQueryDataSource:_,onUnsubscribeDataSourceQuery:B,onCreatePage:Q,onGetPage:H,onOpenPage:h,onOpenExternalUrl:q,onGetUser:R,onListUsers:U,onUpdatePage:A,onResize:te}=e;function le(W,F){c("warn",{message:"Ignored unsupported sandbox message",payload:kt(W),issues:F});let G=hn(W);if(G.incomingType==="connect"){let L=ge(gn,W),ne=ge(Vo,W);if(p({initializationId:L.success?L.output.initializationId:void 0,error:qr(),bridgeProtocolVersion:ne.success?ne.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let L=ge(gn,W);y({initializationId:L.success?L.output.initializationId:void 0,error:Hr()})}G.nack!==void 0&&s()!=="stopped"&&l(G.nack)}return function(F){let G=F.source===t.contentWindow,L=F.origin===i;if(!G||!L)return;let ne=vn(F.data);if(!ne.success){le(F.data,ne.issues);return}let D=ne.output;if(!Wr(D)&&s()!=="initialized"){c("warn",{message:`Ignored ${D.type} before initialization completed`,payload:kt(D)});return}switch(c("in",kt(D)),D.type){case"connect":m(D);return;case"initResult":x(D);return;case"queryDataSource":_(D);return;case"unsubscribeDataSourceQuery":B(D);return;case"createPage":Q(D);return;case"openPage":h(D);return;case"openExternalUrl":q(D);return;case"getPage":H(D);return;case"getUser":R(D);return;case"listUsers":U(D);return;case"updatePage":A(D);return;case"resize":te(D);return;case"invalidHostMessage":return;default:ee(D)}}}function kt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Ke=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let i={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:i,isRefreshing:!0,shouldRefreshAgain:!1}),i}isCurrent(t,i){return this.bySubscriptionId.get(t)?.token===i}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let i=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,i.push({message:c.message,token:c.token})}return s?i:void 0}finish(t,i){let s=this.bySubscriptionId.get(t);if(s?.token===i&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function Sn(e,t){if(e===void 0)return;let i="and"in e?e.and:[e];for(let s of i){let c=Go(s,t);if(c!==void 0)return c}}function Go(e,t){if(!Object.hasOwn(t.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let i=t.propertiesById[e.propertyId],s=Object.keys(e).find(y=>y!=="propertyId");if(s!==i.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${i.type}".`,isRetryable:!1};if("status"in e&&i.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,_=(Array.isArray(m)?m:[m]).find(B=>!i.groups.some(Q=>Q.name===B));return _===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${_}".`,isRetryable:!1}}}if("relation"in e&&!jt(bt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=$o(e);if(c===void 0||i.type!==c.propertyType)return;let l=new Set(i.options.map(y=>y.name)),p=Qo(c.operator).find(y=>!l.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function $o(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let t=e.status;return"group_equals"in t||"group_does_not_equal"in t?void 0:{propertyType:"status",operator:t}}}function Qo(e){let t;if("equals"in e)t=e.equals;else if("does_not_equal"in e)t=e.does_not_equal;else if("contains"in e)t=e.contains;else if("contains_all"in e)t=e.contains_all;else if("does_not_contain"in e)t=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:ee(e);return Array.isArray(t)?t:[t]}var Wo=new Set(qt);function kn(e,t){if(e===void 0)return;if(e.length>St)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${St} entries.`,isRetryable:!1};let i=new Set;for(let s of e){if(i.has(s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${s.propertyId}".`,isRetryable:!1};if(i.add(s.propertyId),!Object.hasOwn(t.propertiesById,s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${s.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[s.propertyId];if(!Wo.has(c.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${c.type}".`,isRetryable:!1}}}var _n=5;function Ko(e){let{iframe:t,prepareInitialState:i,handlers:s,onStatusChange:c,onLog:l,onQueryUnsubscribed:p,minBridgeProtocolVersion:y,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_}=e,B=Zo(e.sandboxUrl,e.manifestSource),Q=B.origin,H=Math.max(y??3,3),h=new AbortController,q,R={},U=!1,A=new AbortController,te,le,W=8,F=new Ke(a=>{p?.(a)});function G(a,S){l?.(a,S)}function L(a){let S=I.status;switch(S){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"failed":break;case"stopped":return;default:return ee(S)}let P=Dr(a,W);G("out",P),t.contentWindow?.postMessage(P,Q)}function ne(a){L(ie(Qe,a))}function D(a){L(a)}function Y(a){let S=I.status;switch(S){case"initialized":L(ie(Pr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"failed":case"stopped":return;default:ee(S)}}async function pe(a,S){if(S===void 0)return;let P=await S(a);Y({type:`${a.type}Result`,requestId:a.requestId,...P})}function Ae(a){let S=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};Y(S)}async function _e(a,S=F.subscribe(a)){try{let P=Jo(le,a.dataSourceId),ye=Yo(a,P);if(ye!==void 0){F.isCurrent(a.subscriptionId,S)&&(F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:{status:"error",error:ye}}));return}let Ye=await s.queryDataSource(a);if(!F.isCurrent(a.subscriptionId,S))return;Ye.status==="error"&&!Ye.error.isRetryable&&F.unsubscribe(a.subscriptionId),Ae({subscriptionId:a.subscriptionId,response:Ye})}finally{let P=F.finish(a.subscriptionId,S);P!==void 0&&_e(P.message,P.token)}}function fe(a){I.status==="stopped"||I.status==="failed"||(Object.assign(R,a),C())}async function k(a){if(s.openExternalUrl===void 0||h.signal.aborted||q===a.requestId)return;if(q!==void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};Y(P);return}let S=Qr(a.url);if(S===void 0){let P={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};Y(P);return}q=a.requestId;try{let P=await s.openExternalUrl({...a,url:S},{signal:h.signal});if(h.signal.aborted)return;let ye={type:"openExternalUrlResult",requestId:a.requestId,...P};Y(ye)}catch(P){if(!h.signal.aborted)throw P}finally{q===a.requestId&&(q=void 0)}}function C(){if(I.status!=="initialized")return;let a=R;R={},a.theme!==void 0&&Y({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&Y({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&Y({type:"parentChanged",parent:a.parent}),a.page!==void 0&&Y({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&Y({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&Y({type:"currentUserChanged",currentUser:a.currentUser})}let I=Lr({manifestSource:e.manifestSource,async prepareInit(a){let S=a.status==="success"?a.manifest:void 0;W=a.bridgeProtocolVersion,c({status:"preparingInit",localManifest:We({url:B,hostOrigin:window.location.origin})?S:void 0,bridgeProtocolVersion:a.bridgeProtocolVersion,sdkVersion:a.sdkVersion});let P=await(Cn??_t(S));return I.status!=="preparingInit"?P:oe(P)},sendInitMessage:ne,onInitSent:()=>c({status:"waitingForInitResult"}),warn:a=>G("warn",a),flushPendingHostStateChanges:C,minBridgeProtocolVersion:H,noConnectTimeoutMs:m,initialStateTimeoutMs:x,noInitResultTimeoutMs:_,stopHostWithFailure:Ct,onInitResult(a){a.status==="success"&&te!==void 0&&c({status:"initialized",resolvedManifest:te,initialHeight:a.initialHeight})},onConnectionFailure:a=>{A.abort(),c({status:"failed",error:a})}});function oe(a){if(a.status==="error")return a;let S=ie(gt,{...a.initialState,...R});if(te=S.manifest,R={},W<_n&&S.page.type==="unavailable")return{status:"error",error:vt()};let P=xn(S.manifest,S.dataSources);return P!==void 0?{status:"error",error:P}:(le=S.dataSources,U=!0,{status:"success",initialState:S})}let Ze=Pn().catch(It),Cn=e.manifestSource==="host"?_t(void 0).catch(It):void 0;async function Pn(){A.signal.throwIfAborted();let a=await e.getPersistedManifest({signal:A.signal});return A.signal.throwIfAborted(),ie(Gr,a)}function It(a){return A.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Xe()}}async function _t(a){A.signal.throwIfAborted();let S=await Vr({manifestSource:e.manifestSource,hostManifest:Ze,connectManifest:a});if(A.signal.throwIfAborted(),S.status==="error")return S;let P=ie($r,await i({manifest:S.manifest,signal:A.signal}));return P.status==="error"?P:{status:"success",initialState:{...P.initialState,manifest:S.manifest}}}let xt=bn({iframe:t,sandboxOrigin:Q,getInitStatus:()=>I.status,emit:G,sendNack:D,onInvalidConnect:I.handleInvalidConnect,onInvalidInitResult:I.handleInvalidInitResult,onConnect:I.handleConnect,onInitResult:I.handleInitResult,onQueryDataSource:_e,onUnsubscribeDataSourceQuery:a=>F.unsubscribe(a.subscriptionId),onOpenExternalUrl:k,onCreatePage:a=>pe(a,s.createPage),onGetPage:a=>pe(a,s.getPage),onOpenPage:a=>pe(a,s.openPage),onGetUser:a=>pe(a,s.getUser),onListUsers:a=>pe(a,s.listUsers),onUpdatePage:a=>pe(a,s.updatePage),onResize:a=>s.resize?.(a)});window.addEventListener("message",xt),t.addEventListener("load",I.onIframeLoad);function Je(){h.abort(),A.abort(),window.removeEventListener("message",xt),t.removeEventListener("load",I.onIframeLoad),I.stop(),F.unsubscribeAll()}function En(){let a=I.status;Je(),a!=="stopped"&&a!=="failed"&&c({status:"stopped"})}function Ct(a){if(I.status!=="stopped"){if(I.status==="failed"){Je();return}Je(),G("warn",a),c({status:"failed",error:a})}}return c({status:"waitingForConnect"}),{stop:En,setTheme(a){fe({theme:a})},setContrastMode(a){fe({contrastMode:a})},setParent(a){fe({parent:a})},setPage(a){if(a.type==="unavailable"&&W<_n&&(I.status==="preparingInit"&&U||I.status==="waitingForInitResult"||I.status==="initialized")){Ct({...vt(),phase:"runtime",source:"host"});return}fe({page:a})},setCurrentUser(a){fe({currentUser:a})},setDataSources(a){let S={bindings:ie(me,a.bindings)};if(I.hasConnectedSandbox&&te!==void 0&&xn(te,S)!==void 0){G("warn",{message:"Ignored invalid data source bindings update",payload:S});return}le=S,fe({dataSources:S})},refreshQuery({dataSourceId:a}){if(I.status!=="initialized")return;let S=ie(K,a),P=F.refresh(S);if(P===void 0){G("warn",`No active query exists for data source "${a}"`);return}for(let ye of P)_e(ye.message,ye.token)}}}function Zo(e,t){let i;try{i=new URL(e)}catch(s){throw t==="host"?s:new je(dt())}if(t==="sandbox"&&!We({url:i,hostOrigin:window.location.origin}))throw new je(dt());return i}function Jo(e,t){return Object.values(e?.bindings??{}).find(i=>i.collectionPointer?.id===t)?.collectionSchema}function xn(e,t){for(let[i,s]of Object.entries(e.dataSources)){let c=t.bindings[i];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return Nr();for(let[l,p]of Object.entries(s.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return Ur();if(c.collectionSchema.propertiesById[y]?.type!==p.type)return Fr()}}}function Yo(e,t){return t===void 0?e.filter===void 0&&(e.sorts?.length??0)===0?void 0:{code:"data_source_schema_unavailable",message:"You cannot query this data source with filters or sorts because its schema is unavailable.",isRetryable:!1}:Sn(e.filter,t)??kn(e.sorts,t)}function ei(e){return ie(N,e)}export{de as InvalidNotionDateError,Ko as createCustomBlockHost,On as getAutoBoundPropertyIdsByKey,We as isAllowedLocalPreviewUrl,ft as toNotionDateValue,ei as toNotionPageId};
|