@notionhq/custom-blocks-host 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -5
- package/dist/browser.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/lifecycle/legacyPage.d.ts +70 -0
- package/dist/lifecycle/legacyPage.d.ts.map +1 -0
- package/dist/lifecycle/legacyPage.js +171 -0
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +2 -2
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +1 -1
- package/dist/lifecycle/normalizeHostToSandboxMessage.js +8 -30
- package/dist/lifecycle/normalizePage.d.ts +7 -0
- package/dist/lifecycle/normalizePage.d.ts.map +1 -0
- package/dist/lifecycle/normalizePage.js +22 -0
- package/dist/messages/types.d.ts +1 -2
- package/dist/messages/types.d.ts.map +1 -1
- package/dist/protocol/dataSources/dataSourcePage.d.ts +1 -162
- package/dist/protocol/dataSources/dataSourcePage.js +1 -9
- package/dist/protocol/messages/createPage.js +2 -2
- package/dist/protocol/messages/createPageResult.d.ts +468 -1
- package/dist/protocol/messages/createPageResult.js +17 -2
- package/dist/protocol/messages/getPage.d.ts +468 -1
- package/dist/protocol/messages/getPage.js +18 -3
- package/dist/protocol/messages/hostToSandbox.d.ts +2398 -159
- package/dist/protocol/messages/hostToSandbox.js +22 -12
- package/dist/protocol/messages/queryDataSourceResult.d.ts +312 -2
- package/dist/protocol/messages/queryDataSourceResult.js +18 -5
- package/dist/protocol/messages/sandboxToHost.d.ts +2 -0
- package/dist/protocol/messages/updatePage.d.ts +1 -0
- package/dist/protocol/messages/updatePage.js +4 -3
- package/dist/protocol/messages/updatePageResult.d.ts +467 -1
- package/dist/protocol/messages/updatePageResult.js +16 -2
- package/dist/protocol/pages/page.d.ts +386 -6
- package/dist/protocol/pages/page.js +23 -2
- package/dist/protocol/protocolVersion.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -4
- package/src/lifecycle/legacyPage.ts +208 -0
- package/src/lifecycle/normalizeHostToSandboxMessage.ts +18 -35
- package/src/lifecycle/normalizePage.ts +35 -0
- package/src/messages/types.ts +1 -1
package/README.md
CHANGED
|
@@ -156,11 +156,6 @@ validates filters and sorts against actual database properties in `collectionSch
|
|
|
156
156
|
before invoking `queryDataSource`. Status group names and option names must match the bound schema.
|
|
157
157
|
Sorts retain their order and contain at most ten unique properties.
|
|
158
158
|
|
|
159
|
-
The SDK exposes synthetic metadata through its separate `propertySchemasById` read map. For
|
|
160
|
-
protocols 3 and 4, the host adds synthetic metadata to outgoing `collectionSchema` payloads.
|
|
161
|
-
Protocol 5 SDKs add those read schemas themselves. Host query validation always uses the actual
|
|
162
|
-
database schema.
|
|
163
|
-
|
|
164
159
|
### External navigation
|
|
165
160
|
|
|
166
161
|
The `openExternalUrl` handler receives an `AbortSignal` and a normalized, absolute HTTP or HTTPS URL
|
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ue=6,Wr=6;function Jr(e){let{manifestProperties:n,propertySchemasById:o}=e,i=[];for(let[c,l]of Object.entries(n)){let f=Kr({propertyKey:c,manifestProperty:l,propertySchemasById:o});f!==void 0&&i.push([c,f])}return Object.fromEntries(i)}function Kr(e){let{propertyKey:n,manifestProperty:o,propertySchemasById:i}=e,c=ct(o.name),l=Object.entries(i).filter(([f,y])=>y.type===o.type&&(f===n||ct(y.name)===c));return l.length===1?l[0][0]:void 0}function ct(e){return e.trim().toLowerCase()}var Me,Yr={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Fe(e){return!e&&!Me?Yr:{lang:e?.lang??Me?.lang,message:e?.message,abortEarly:e?.abortEarly??Me?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Me?.abortPipeEarly}}var Zr;function en(e){return Zr?.get(e)}var tn;function rn(e){return tn?.get(e)}var nn;function on(e,n){return nn?.get(e)?.get(n)}function be(e){let n=typeof e;return n==="string"?`"${e}"`:n==="number"||n==="bigint"||n==="boolean"?`${e}`:n==="object"||n==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":n}function M(e,n,o,i,c){let l=c&&"input"in c?c.input:o.value,f=c?.expected??e.expects??null,y=c?.received??be(l),m={kind:e.kind,type:e.type,input:l,expected:f,received:y,message:`Invalid ${n}: ${f?`Expected ${f} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},_=e.kind==="schema",x=c?.message??e.message??on(e.reference,m.lang)??(_?rn(m.lang):null)??i.message??en(m.lang);x!==void 0&&(m.message=typeof x=="function"?x(m):x),_&&(o.typed=!1),o.issues?o.issues.push(m):o.issues=[m]}var lt=new WeakMap;function H(e){let n=lt.get(e);return n||(n={version:1,vendor:"valibot",validate(o){return e["~run"]({value:o},Fe())}},lt.set(e,n)),n}function sn(e,n){return Object.prototype.hasOwnProperty.call(e,n)&&n!=="__proto__"&&n!=="prototype"&&n!=="constructor"}function ze(e,n){let o=[...new Set(e)];return o.length>1?`(${o.join(` ${n} `)})`:o[0]??"never"}var an=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ie(e){return{kind:"transformation",type:"brand",reference:ie,async:!1,name:e,"~run"(n){return n}}}function ke(e){return{kind:"validation",type:"finite",reference:ke,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(n,o){return n.typed&&!this.requirement(n.value)&&M(this,"finite",n,o),n}}}function De(e,n){return{kind:"validation",type:"max_length",reference:De,async:!1,expects:`<=${e}`,requirement:e,message:n,"~run"(o,i){return o.typed&&o.value.length>this.requirement&&M(this,"length",o,i,{received:`${o.value.length}`}),o}}}function Se(e,n){return{kind:"validation",type:"min_length",reference:Se,async:!1,expects:`>=${e}`,requirement:e,message:n,"~run"(o,i){return o.typed&&o.value.length<this.requirement&&M(this,"length",o,i,{received:`${o.value.length}`}),o}}}function Ie(e,n){return{kind:"validation",type:"min_value",reference:Ie,async:!1,expects:`>=${e instanceof Date?e.toJSON():be(e)}`,requirement:e,message:n,"~run"(o,i){return o.typed&&!(o.value>=this.requirement)&&M(this,"value",o,i,{received:o.value instanceof Date?o.value.toJSON():be(o.value)}),o}}}function He(e,n){return{kind:"validation",type:"regex",reference:He,async:!1,expects:`${e}`,requirement:e,message:n,"~run"(o,i){return o.typed&&!this.requirement.test(o.value)&&M(this,"format",o,i),o}}}function Le(e){return{kind:"transformation",type:"transform",reference:Le,async:!1,operation:e,"~run"(n){return n.value=this.operation(n.value),n}}}var ft={abortEarly:!0};function mt(e,n,o){return typeof e.fallback=="function"?e.fallback(n,o):e.fallback}function we(e,n,o){return typeof e.default=="function"?e.default(n,o):e.default}function yt(e,n){return!e["~run"]({value:n},ft).issues}function O(e,n){return{kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){let c=o.value;if(Array.isArray(c)){o.typed=!0,o.value=[];for(let l=0;l<c.length;l++){let f=c[l],y=this.item["~run"]({value:f},i);if(y.issues){let m={type:"array",origin:"value",input:c,key:l,value:f};for(let _ of y.issues)_.path?_.path.unshift(m):_.path=[m],o.issues?.push(_);if(o.issues||(o.issues=y.issues),i.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value.push(y.value)}}else M(this,"type",o,i);return o}}}function d(e){return{kind:"schema",type:"boolean",reference:d,expects:"boolean",async:!1,message:e,get"~standard"(){return H(this)},"~run"(n,o){return typeof n.value=="boolean"?n.typed=!0:M(this,"type",n,o),n}}}function s(e,n){return{kind:"schema",type:"literal",reference:s,expects:be(e),async:!1,literal:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){return o.value===this.literal?o.typed=!0:M(this,"type",o,i),o}}}function Ge(e){return{kind:"schema",type:"nan",reference:Ge,expects:"NaN",async:!1,message:e,get"~standard"(){return H(this)},"~run"(n,o){return Number.isNaN(n.value)?n.typed=!0:M(this,"type",n,o),n}}}function Z(e,n){return{kind:"schema",type:"nullable",reference:Z,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:n,get"~standard"(){return H(this)},"~run"(o,i){return o.value===null&&(this.default!==void 0&&(o.value=we(this,o,i)),o.value===null)?(o.typed=!0,o):this.wrapped["~run"](o,i)}}}function C(e){return{kind:"schema",type:"number",reference:C,expects:"number",async:!1,message:e,get"~standard"(){return H(this)},"~run"(n,o){return typeof n.value=="number"&&!isNaN(n.value)?n.typed=!0:M(this,"type",n,o),n}}}function r(e,n){return{kind:"schema",type:"object",reference:r,expects:"Object",async:!1,entries:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.value={};for(let l in this.entries){let f=this.entries[l];if(l in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let y=l in c?c[l]:we(f),m=f["~run"]({value:y},i);if(m.issues){let _={type:"object",origin:"value",input:c,key:l,value:y};for(let x of m.issues)x.path?x.path.unshift(_):x.path=[_],o.issues?.push(x);if(o.issues||(o.issues=m.issues),i.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[l]=m.value}else if(f.fallback!==void 0)o.value[l]=mt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(M(this,"key",o,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}}else M(this,"type",o,i);return o}}}function u(e,n){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:n,get"~standard"(){return H(this)},"~run"(o,i){return o.value===void 0&&(this.default!==void 0&&(o.value=we(this,o,i)),o.value===void 0)?(o.typed=!0,o):this.wrapped["~run"](o,i)}}}function D(e,n){return{kind:"schema",type:"picklist",reference:D,expects:ze(e.map(be),"|"),async:!1,options:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){return this.options.includes(o.value)?o.typed=!0:M(this,"type",o,i),o}}}function N(e,n,o){return{kind:"schema",type:"record",reference:N,expects:"Object",async:!1,key:e,value:n,message:o,get"~standard"(){return H(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){i.typed=!0,i.value={};for(let f in l)if(sn(l,f)){let y=l[f],m=this.key["~run"]({value:f},c);if(m.issues){let x={type:"object",origin:"key",input:l,key:f,value:y};for(let w of m.issues)w.path=[x],i.issues?.push(w);if(i.issues||(i.issues=m.issues),c.abortEarly){i.typed=!1;break}}let _=this.value["~run"]({value:y},c);if(_.issues){let x={type:"object",origin:"value",input:l,key:f,value:y};for(let w of _.issues)w.path?w.path.unshift(x):w.path=[x],i.issues?.push(w);if(i.issues||(i.issues=_.issues),c.abortEarly){i.typed=!1;break}}(!m.typed||!_.typed)&&(i.typed=!1),m.typed&&(i.value[m.value]=_.value)}}else M(this,"type",i,c);return i}}}function p(e,n){return{kind:"schema",type:"strict_object",reference:p,expects:"Object",async:!1,entries:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){let c=o.value;if(c&&typeof c=="object"){o.typed=!0,o.value={};for(let l in this.entries){let f=this.entries[l];if(l in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let y=l in c?c[l]:we(f),m=f["~run"]({value:y},i);if(m.issues){let _={type:"object",origin:"value",input:c,key:l,value:y};for(let x of m.issues)x.path?x.path.unshift(_):x.path=[_],o.issues?.push(x);if(o.issues||(o.issues=m.issues),i.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[l]=m.value}else if(f.fallback!==void 0)o.value[l]=mt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(M(this,"key",o,i,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),i.abortEarly))break}if(!o.issues||!i.abortEarly){for(let l in c)if(!(l in this.entries)){M(this,"key",o,i,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else M(this,"type",o,i);return o}}}function t(e){return{kind:"schema",type:"string",reference:t,expects:"string",async:!1,message:e,get"~standard"(){return H(this)},"~run"(n,o){return typeof n.value=="string"?n.typed=!0:M(this,"type",n,o),n}}}function pt(e){let n;if(e)for(let o of e)if(n)for(let i of o.issues)n.push(i);else n=o.issues;return n}function I(e,n){return{kind:"schema",type:"union",reference:I,expects:ze(e.map(o=>o.expects),"|"),async:!1,options:e,message:n,get"~standard"(){return H(this)},"~run"(o,i){let c,l,f;for(let y of this.options){let m=y["~run"]({value:o.value},i);if(m.typed)if(m.issues)l?l.push(m):l=[m];else{c=m;break}else f?f.push(m):f=[m]}if(c)return c;if(l){if(l.length===1)return l[0];M(this,"type",o,i,{issues:pt(l)}),o.typed=!0}else{if(f?.length===1)return f[0];M(this,"type",o,i,{issues:pt(f)})}return o}}}function xe(){return{kind:"schema",type:"unknown",reference:xe,expects:"unknown",async:!1,get"~standard"(){return H(this)},"~run"(e){return e.typed=!0,e}}}function h(e,n,o){return{kind:"schema",type:"variant",reference:h,expects:"Object",async:!1,key:e,options:n,message:o,get"~standard"(){return H(this)},"~run"(i,c){let l=i.value;if(l&&typeof l=="object"){let f,y=0,m=this.key,_=[],x=(w,S)=>{for(let L of w.options){if(L.type==="variant")x(L,new Set(S).add(L.key));else{let G=!0,U=0;for(let j of S){let Y=L.entries[j];if(j in l?Y["~run"]({typed:!1,value:l[j]},ft).issues:Y.type!=="exact_optional"&&Y.type!=="optional"&&Y.type!=="nullish"){G=!1,m!==j&&(y<U||y===U&&j in l&&!(m in l))&&(y=U,m=j,_=[]),m===j&&_.push(L.entries[j].expects);break}U++}if(G){let j=L["~run"]({value:l},c);(!f||!f.typed&&j.typed)&&(f=j)}}if(f&&!f.issues)break}};if(x(this,new Set([this.key])),f)return f;M(this,"type",i,c,{input:l[m],expected:ze(_,"|"),path:[{type:"object",origin:"value",input:l,key:m,value:l[m]}]})}else M(this,"type",i,c);return i}}}function oe(e,n,o){let i=e["~run"]({value:n},Fe(o));if(i.issues)throw new an(i.issues);return i.value}function z(...e){return{...e[0],pipe:e,get"~standard"(){return H(this)},"~run"(n,o){for(let i of e)if(i.kind!=="metadata"){if(n.issues&&(i.kind==="schema"||i.kind==="transformation")){n.typed=!1;break}(!n.issues||!o.abortEarly&&!o.abortPipeEarly)&&(n=i["~run"](n,o))}return n}}}function _e(e,n,o){let i=e["~run"]({value:n},Fe(o));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}var ae=z(t(),ie("NotionBlockId")),re=z(t(),ie("NotionDataSourceId")),A=z(t(),ie("NotionPageId")),vt=z(t(),ie("NotionAgentId")),dt=z(t(),ie("NotionSpaceId"));var ht=D(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),Ve=r({id:t(),name:t(),color:u(ht),description:u(t())}),un=r({id:t(),name:t(),color:u(ht),option_ids:O(t())}),cn=r({synced_property_id:t(),synced_property_name:t()}),P=r({name:t(),description:u(t())}),ln=["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"],gt=D(ln),bt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],$e=h("type",[r({...P.entries,type:s("title")}),r({...P.entries,type:s("rich_text")}),r({...P.entries,type:s("number")}),r({...P.entries,type:s("checkbox")}),r({...P.entries,type:s("url")}),r({...P.entries,type:s("email")}),r({...P.entries,type:s("phone_number")}),r({...P.entries,type:s("select"),options:O(Ve)}),r({...P.entries,type:s("multi_select"),options:O(Ve)}),r({...P.entries,type:s("status"),options:O(Ve),groups:O(un)}),r({...P.entries,type:s("date")}),r({...P.entries,type:s("people")}),r({...P.entries,type:s("files")}),r({...P.entries,type:s("unique_id")}),r({...P.entries,type:s("relation"),data_source_id:u(t()),dual_property:u(cn)}),r({...P.entries,type:s("place")}),r({...P.entries,type:s("formula")}),r({...P.entries,type:s("rollup")}),r({...P.entries,type:s("button")}),r({...P.entries,type:s("verification")}),r({...P.entries,type:s("last_visited_time")}),r({...P.entries,type:s("location")}),r({...P.entries,type:s("created_time")}),r({...P.entries,type:s("last_edited_time")}),r({...P.entries,type:s("created_by")}),r({...P.entries,type:s("last_edited_by")})]);var kt={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 St=r({id:re,table:t(),spaceId:u(dt)}),It=r({id:u(re),propertiesById:N(t(),$e)}),Bo=r({key:t(),collectionPointer:u(St),collectionSchema:u(It),propertyIdsByKey:N(t(),u(t())),propertySchemasById:N(t(),$e)}),pn=r({collectionPointer:u(St),collectionSchema:u(It),propertyIdsByKey:u(N(t(),u(t())))}),fe=N(t(),pn);var ve=D(["standard","high"]),xt="standard";var _t=r({type:s("contrastModeChanged"),contrastMode:ve});var qe=r({id:t(),table:t()});var ue=h("type",[r({type:s("page_id"),page_id:A}),r({type:s("data_source_id"),data_source_id:re}),r({type:s("workspace"),workspace:s(!0)}),r({type:s("block_id"),block_id:ae}),r({type:s("agent_id"),agent_id:vt}),r({type:s("unavailable")})]);var de=h("type",[r({type:s("unavailable")}),r({type:s("page"),id:A,parent:ue})]),fn=r({type:s("emoji"),emoji:t()}),mn=r({type:s("custom_emoji"),custom_emoji:r({id:t(),name:u(t()),url:u(t())})}),Ot=r({type:s("external"),external:r({url:t()})}),Pt=r({type:s("file"),file:r({url:t(),expiry_time:u(t())})}),Xe=h("type",[fn,mn,Ot,Pt]),We=h("type",[Ot,Pt]),Q=Z(t()),Ct=N(t(),xe()),Qe=I([r({id:t(),name:u(t()),color:u(t()),description:u(Q)}),r({name:t(),id:u(t()),color:u(t()),description:u(Q)})]),yn=r({start:t(),end:u(Q),time_zone:u(Q)}),vn=I([r({object:u(s("user")),id:t()}),r({object:s("group"),id:t(),name:u(Q)})]),dn=r({id:t()}),hn=I([r({type:s("external"),name:t(),external:r({url:t()})}),r({type:s("file"),name:t(),file:r({url:t(),expiry_time:u(t())})})]),gn=r({lat:C(),lon:C(),name:u(Q),address:u(Q),aws_place_id:u(Q),google_place_id:u(Q)}),T={id:t()},Et=Z(r({...qe.entries,table:D(["notion_user","bot","organization_bot"]),spaceId:u(t())})),Je=h("type",[r({...T,type:s("title"),title:O(Ct)}),r({...T,type:s("rich_text"),rich_text:O(Ct)}),r({...T,type:s("number"),number:Z(C())}),r({...T,type:s("url"),url:Q}),r({...T,type:s("email"),email:Q}),r({...T,type:s("phone_number"),phone_number:Q}),r({...T,type:s("checkbox"),checkbox:d()}),r({...T,type:s("select"),select:Z(Qe)}),r({...T,type:s("status"),status:Z(Qe)}),r({...T,type:s("multi_select"),multi_select:O(Qe)}),r({...T,type:s("date"),date:Z(yn)}),r({...T,type:s("people"),people:O(vn)}),r({...T,type:s("relation"),has_more:u(d()),relation:O(dn)}),r({...T,type:s("files"),files:O(hn)}),r({...T,type:s("place"),place:Z(gn)}),r({...T,type:s("created_time"),created_time:Q}),r({...T,type:s("last_edited_time"),last_edited_time:Q}),r({...T,type:s("created_by"),created_by:Et}),r({...T,type:s("last_edited_by"),last_edited_by:Et}),r({...T,type:s("last_visited_time"),last_visited_time:Q})]),Ce=N(t(),Je),he=r({object:s("page"),id:A,parent:ue,properties:Ce,created_time:u(t()),last_edited_time:u(t()),icon:u(Xe),cover:u(We),url:u(t()),public_url:u(t()),is_archived:d(),in_trash:d()});var bn=t(),kn=r({code:bn,message:t(),isRetryable:d()}),jt=h("status",[r({type:s("createPageResult"),requestId:t(),status:s("success"),page:he}),r({type:s("createPageResult"),requestId:t(),status:s("error"),error:kn})]);var Ke=z(t(),ie("NotionUserId")),ce=r({object:s("user"),id:Ke,name:u(t()),avatar_url:Z(t()),type:s("person"),person:r({email:t()})}),Bt=r({object:s("list"),results:O(ce),next_cursor:Z(t()),has_more:d(),type:s("user"),user:N(t(),xe())});var Rt=r({type:s("currentUserChanged"),currentUser:ce});var Mt=r({type:s("dataSourcesChanged"),dataSources:r({bindings:fe})});var Sn=t(),In=r({code:Sn,message:t(),isRetryable:d()}),Dt=r({type:s("getPage"),requestId:t(),pageId:A}),wt=h("status",[r({type:s("getPageResult"),requestId:t(),status:s("success"),page:he}),r({type:s("getPageResult"),requestId:t(),status:s("error"),error:In})]);var xn=t(),_n=r({code:xn,message:t(),isRetryable:d()}),qt=r({type:s("getUser"),requestId:t(),userId:Ke}),At=h("status",[r({type:s("getUserResult"),requestId:t(),status:s("success"),user:ce}),r({type:s("getUserResult"),requestId:t(),status:s("error"),error:_n})]);var Cn=h("type",[r({type:s("emoji"),emoji:t()}),r({type:s("external"),url:t()})]),En=r({name:t(),description:u(t()),type:gt}),On=r({name:t(),description:u(t()),icon:u(Cn),properties:u(N(t(),En),{})}),me=r({version:s(1),name:u(t()),description:u(t()),slashCommand:u(t()),icon:u(r({type:s("emoji"),emoji:t()})),dataSources:u(N(t(),On),{})});var ge=D(["light","dark"]);var Pn=t(),jn=r({code:Pn,message:t(),isRetryable:d()});var Ae=h("status",[r({type:s("init"),initializationId:t(),status:s("success"),theme:ge,contrastMode:ve,blockId:ae,parent:ue,page:de,manifest:me,dataSources:r({bindings:fe}),currentUser:ce}),r({type:s("init"),initializationId:t(),status:s("error"),error:jn})]);var Tt=r({type:s("invalidSandboxMessage"),reason:t()});var Bn=t(),Rn=r({code:Bn,message:t(),isRetryable:d()}),Nt=r({type:s("listUsers"),requestId:t(),startCursor:u(t()),pageSize:u(C())}),Ut=h("status",[r({type:s("listUsersResult"),requestId:t(),status:s("success"),list:Bt}),r({type:s("listUsersResult"),requestId:t(),status:s("error"),error:Rn})]);var Mn=t(),Dn=r({code:Mn,message:t(),isRetryable:d()}),Ft=r({type:s("openExternalUrl"),requestId:t(),url:t()}),zt=h("status",[r({type:s("openExternalUrlResult"),requestId:t(),status:s("success")}),r({type:s("openExternalUrlResult"),requestId:t(),status:s("error"),error:Dn})]);var wn=D(["side_peek","center_peek"]),qn=t(),An=r({code:qn,message:t(),isRetryable:d()}),Ht=r({type:s("openPage"),requestId:t(),pageId:A,mode:wn}),Lt=h("status",[r({type:s("openPageResult"),requestId:t(),status:s("success"),pageId:A}),r({type:s("openPageResult"),requestId:t(),status:s("error"),error:An})]);var Gt=r({type:s("pageChanged"),page:de});var Vt=r({type:s("parentChanged"),parent:ue});var $t=r({unit:D(["year","month","week","day"]),value:C(),time:t(),defaultTimeZone:u(t())}),Tn=r({unit:D(["hour","minute"]),value:C()}),Qt=r({unit:s("none")}),Nn=I([$t,Tn]),Xt=u(I([$t,Qt])),Wt=u(I([Nn,Qt])),Un=r({type:s("date"),start_date:t(),reminder:Xt}),Fn=r({type:s("daterange"),start_date:t(),end_date:t(),reminder:Xt}),zn=r({type:s("datetime"),start_date:t(),start_time:t(),time_zone:u(t()),reminder:Wt}),Hn=r({type:s("datetimerange"),start_date:t(),start_time:t(),end_date:t(),end_time:t(),time_zone:u(t()),reminder:Wt}),Jt=h("type",[Un,Fn,zn,Hn]);var Kt=I([t(),C(),d(),Jt,O(t()),O(qe)]);var Yt=r({id:A,is_archived:d(),in_trash:d(),propertiesById:N(t(),u(Kt))}),Zt=r({id:A,is_archived:d(),in_trash:d(),properties:N(t(),u(Je))});var Ln=t(),Gn=r({code:Ln,message:t(),isRetryable:d()}),er=h("status",[r({type:s("queryDataSourceResult"),subscriptionId:t(),status:s("success"),items:O(I([Zt,Yt])),hasMore:d()}),r({type:s("queryDataSourceResult"),subscriptionId:t(),status:s("error"),error:Gn})]);var tr=r({type:s("themeChanged"),theme:ge});var Vn=t(),$n=r({code:Vn,message:t(),isRetryable:d()}),rr=h("status",[r({type:s("updatePageResult"),requestId:t(),status:s("success"),page:he}),r({type:s("updatePageResult"),requestId:t(),status:s("error"),error:$n})]);var nr=h("type",[Ae,tr,_t,Vt,Gt,Rt,Mt,er,jt,wt,At,Ut,Lt,zt,rr,Tt]);function or(){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 Ye(e){let{currentBridgeProtocolVersion:n}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${n}`,isRetryable:!1}}function Ze(e){let{currentBridgeProtocolVersion:n,minBridgeProtocolVersion:o}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${n} is not supported. Minimum supported version is ${o}.`,isRetryable:!1}}function et(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function ir(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function ar(){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 cr(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function lr(){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 Ee(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function le(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function tt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Qn=5e3,Xn=5e3,Wn=5e3;function fr(e){let{prepareInit:n,sendInitMessage:o,warn:i,flushPendingHostStateChanges:c,minBridgeProtocolVersion:l,noConnectTimeoutMs:f=Qn,initialStateTimeoutMs:y=Xn,noInitResultTimeoutMs:m=Wn,stopHostWithFailure:_,onInitResult:x,onConnectionFailure:w}=e,S="waitingForConnect",L,G,U,j,Y=!1,ee=!1;function W(){L!==void 0&&(window.clearTimeout(L),L=void 0)}function se(){G!==void 0&&(window.clearTimeout(G),G=void 0)}function V(){U!==void 0&&(window.clearTimeout(U),U=void 0)}function B(g){let{initializationId:k,error:$,phase:te,source:q}=g;switch(S){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return le(S)}S="error",j=k,W(),se(),o({type:"init",initializationId:k,status:"error",error:$}),w?.({...$,phase:te,source:q})}async function F(g){if(S==="waitingForConnect"){S="preparingInit",j=g.initializationId,W(),G=window.setTimeout(()=>{if(S!=="preparingInit")return;let k=ir();i({...k,initializationId:g.initializationId}),B({initializationId:g.initializationId,error:k,phase:"init",source:"host"})},y);try{let k=await n(g);if(S!=="preparingInit")return;if(se(),k.status==="error"){B({initializationId:g.initializationId,error:k.error,phase:"init",source:"host"});return}S="waitingForInitResult";let $={type:"init",initializationId:g.initializationId,status:"success",theme:k.initialState.theme,contrastMode:k.initialState.contrastMode??xt,blockId:k.initialState.blockId,parent:k.initialState.parent,page:k.initialState.page,currentUser:k.initialState.currentUser,manifest:k.initialState.manifest,dataSources:k.initialState.dataSources};o($),U=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let te=lr();w?.({...te,phase:"initResult",source:"host"}),i({...te,initializationId:g.initializationId})},m)}catch(k){if(S!=="preparingInit")return;i({message:"Failed to prepare custom block initialization",error:k}),B({initializationId:g.initializationId,error:Ee(),phase:"init",source:"host"})}}}function J(g){if(S!=="stopped"&&S==="waitingForConnect"){if(!tt(g.bridgeProtocolVersion)){let k=Ye({currentBridgeProtocolVersion:g.bridgeProtocolVersion});B({initializationId:g.initializationId,error:k,phase:"connect",source:"host"});return}if(g.bridgeProtocolVersion<l){let k=Ze({currentBridgeProtocolVersion:g.bridgeProtocolVersion,minBridgeProtocolVersion:l});B({initializationId:g.initializationId,error:k,phase:"connect",source:"host"});return}if(g.status==="error"){B({initializationId:g.initializationId,error:g.error,phase:"connect",source:"sandbox"});return}ee=!0,F(g)}}function ne(g){if(S==="stopped"||S!=="waitingForConnect")return"handled";let{initializationId:k,bridgeProtocolVersion:$}=g;if(k===void 0)return"nack";let te=g.error;return $!==void 0&&(tt($)?$<l&&(te=Ze({currentBridgeProtocolVersion:$,minBridgeProtocolVersion:l})):te=Ye({currentBridgeProtocolVersion:$})),B({initializationId:k,error:te,phase:"connect",source:"host"}),"handled"}function R(g){let{initializationId:k,error:$}=g;S!=="waitingForInitResult"||k===void 0||k!==j||(W(),V(),S="error",i($),w?.({...$,phase:"initResult",source:"host"}))}function K(){if(S!=="stopped"){if(Y){_({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}Y=!0,W(),S==="waitingForConnect"&&(L=window.setTimeout(()=>{if(S!=="waitingForConnect")return;S="error";let g=or();i(g),w?.({...g,phase:"connect",source:"host"})},f))}}function pe(g){if(S!=="waitingForInitResult"||g.initializationId!==j){i({message:"Ignored stale or unexpected initResult",payload:g});return}V(),S=g.status==="success"?"initialized":"error",g.status==="success"?c():w?.({...g.error,phase:"initResult",source:"sandbox"}),x?.(g)}function Re(){S="stopped",W(),se(),V()}return{get status(){return S},get hasConnectedSandbox(){return ee},handleConnect:J,handleInitResult:pe,handleInvalidConnect:ne,handleInvalidInitResult:R,onIframeLoad:K,stop:Re}}function rt({url:e,hostOrigin:n}){return typeof n=="string"&&n!==""&&e.origin!==n&&(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function mr(e){let n=new AbortController,o=()=>n.abort();e.signal.addEventListener("abort",o,{once:!0});let i=new Promise((l,f)=>{n.signal.addEventListener("abort",()=>f(n.signal.reason),{once:!0})});e.signal.aborted&&n.abort();let c=e.manifestSource==="local"?window.setTimeout(()=>{n.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let l=await Promise.race([e.manifestSource==="local"?Jn(e.sandboxOrigin,n.signal):e.getPersistedManifest({signal:n.signal}),i]);if(n.signal.aborted)throw new Error("Manifest loading was cancelled.");return{status:"success",manifest:oe(me,l)}}catch(l){return e.signal.aborted||e.onError(l),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(c),e.signal.removeEventListener("abort",o)}}async function Jn(e,n){let o=new URL(e);if(!rt({url:o,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let i=await fetch(new URL("/manifest",o),{credentials:"omit",redirect:"error",cache:"no-store",signal:n});if(!i.ok)throw new Error(`Manifest request failed: HTTP ${i.status}.`);return i.json()}function yr(e,n){return n>=5||!(e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged")?e:{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([i,c])=>[i,{...c,collectionSchema:{...c.collectionSchema,propertiesById:{...c.collectionSchema?.propertiesById,...kt}}}]))}}}var vr=r({theme:ge,contrastMode:u(ve),blockId:ae,parent:ue,page:de,manifest:me,dataSources:r({bindings:fe}),currentUser:ce});function dr(e){if(e.length>2048||!URL.canParse(e))return;let n=new URL(e);if(!(n.protocol!=="http:"&&n.protocol!=="https:"||n.username!==""||n.password!==""||n.href.length>2048))return n.href}function hr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var gr=r({code:t(),message:t(),isRetryable:d()});var br={type:s("connect"),initializationId:t(),bridgeProtocolVersion:C(),sdkVersion:t()},kr=h("status",[r({status:s("success"),manifest:u(me),...br}),r({status:s("error"),error:gr,...br})]);var Kn=h("type",[r({type:s("start")}),r({type:s("end")}),r({type:s("before"),blockId:ae}),r({type:s("after"),blockId:ae})]),Yn=h("type",[r({type:s("page_id"),page_id:A}),r({type:s("data_source_id"),data_source_id:re})]),Sr=r({type:s("createPage"),requestId:t(),parent:Yn,properties:Ce,position:u(Kn)});var Zn=t(),eo=r({code:Zn,message:t(),isRetryable:d()}),Ir=h("status",[r({type:s("initResult"),initializationId:t(),status:s("success"),initialHeight:u(z(C(),ke(),Ie(0)))}),r({type:s("initResult"),initializationId:t(),status:s("error"),error:eo})]);var xr=r({type:s("invalidHostMessage"),reason:t()});var _r=D(["ascending","descending"]);var Cr=z(A,He(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Le(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),nt=I([p({contains:Cr}),p({does_not_contain:Cr})]),Be=I([p({is_empty:s(!0)}),p({is_not_empty:s(!0)})]),je=I([t(),O(t())]),Er=p({object:D(["user","group"]),id:z(t(),Se(1))}),to=I([p({contains:Er}),p({does_not_contain:Er}),Be]),Or=p({object:s("user"),id:z(t(),Se(1),De(2e3))}),ro=I([p({contains:Or}),p({does_not_contain:Or}),p({is_empty:s(!0)}),p({is_not_empty:s(!0)})]),Oe=I([p({equals:t()}),p({does_not_equal:t()}),p({contains:t()}),p({does_not_contain:t()}),p({starts_with:t()}),p({ends_with:t()}),Be]),no=I([p({equals:C()}),p({does_not_equal:C()}),p({greater_than:C()}),p({less_than:C()}),p({greater_than_or_equal_to:C()}),p({less_than_or_equal_to:C()}),Be]),oo=I([p({equals:d()}),p({does_not_equal:d()})]),Rr=I([p({equals:je}),p({does_not_equal:je}),Be]),Pr=D(["To-do","In progress","Complete","Current","Future"]),jr=I([Pr,z(O(Pr),Se(1),De(5))]),so=I([p({group_equals:jr}),p({group_does_not_equal:jr})]),io=I([Rr,so]),ao=I([p({contains:je}),p({contains_all:je}),p({does_not_contain:je}),Be]),X=D(["start_date","end_date"]),uo=D(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Pe=I([uo,t()]),co=I([p({target:u(X),equals:Pe}),p({target:u(X),before:Pe}),p({target:u(X),after:Pe}),p({target:u(X),on_or_before:Pe}),p({target:u(X),on_or_after:Pe}),p({target:u(X),this_week:p({})}),p({target:u(X),past_week:p({})}),p({target:u(X),past_month:p({})}),p({target:u(X),past_year:p({})}),p({target:u(X),next_week:p({})}),p({target:u(X),next_month:p({})}),p({target:u(X),next_year:p({})}),p({target:u(X),is_empty:s(!0)}),p({target:u(X),is_not_empty:s(!0)})]),Br=I([p({propertyId:t(),relation:nt}),p({propertyId:t(),created_by:ro}),p({propertyId:t(),title:Oe}),p({propertyId:t(),rich_text:Oe}),p({propertyId:t(),url:Oe}),p({propertyId:t(),email:Oe}),p({propertyId:t(),phone_number:Oe}),p({propertyId:t(),number:no}),p({propertyId:t(),checkbox:oo}),p({propertyId:t(),select:Rr}),p({propertyId:t(),multi_select:ao}),p({propertyId:t(),status:io}),p({propertyId:t(),date:co}),p({propertyId:t(),people:to})]),lo=I([Br,p({and:O(Br)})]),ot=10,po=p({propertyId:t(),direction:_r}),Mr=r({type:s("queryDataSource"),subscriptionId:t(),dataSourceId:re,limit:C(),filter:u(lo),sorts:u(O(po))});var Dr=r({type:s("resize"),height:z(C(),ke(),Ie(0))});var wr=r({type:s("unsubscribeDataSourceQuery"),subscriptionId:t()});var qr=r({type:s("updatePage"),requestId:t(),pageId:A,properties:u(Ce),icon:u(Xe),cover:u(We),archived:u(d())});var Ar=h("type",[kr,Ir,Mr,wr,Sr,Dt,qt,Nt,Ht,Ft,qr,Dr,xr]);function Tr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Nr(e){let n=Tr(e);return n==="invalidHostMessage"||n==="invalidSandboxMessage"?{incomingType:n}:{incomingType:n,nack:{type:"invalidSandboxMessage",reason:fo(n)}}}function fo(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var Ur=r({initializationId:t()}),mo=r({bridgeProtocolVersion:I([C(),Ge()])});function Fr(e){let{iframe:n,sandboxOrigin:o,getInitStatus:i,emit:c,sendNack:l,onInvalidConnect:f,onInvalidInitResult:y,onConnect:m,onInitResult:_,onQueryDataSource:x,onUnsubscribeDataSourceQuery:w,onCreatePage:S,onGetPage:L,onOpenPage:G,onOpenExternalUrl:U,onGetUser:j,onListUsers:Y,onUpdatePage:ee,onResize:W}=e;function se(V,B){c("warn",{message:"Ignored unsupported sandbox message",payload:st(V),issues:B});let F=Nr(V);if(F.incomingType==="connect"){let J=_e(Ur,V),ne=_e(mo,V);if(f({initializationId:J.success?J.output.initializationId:void 0,error:sr(),bridgeProtocolVersion:ne.success?ne.output.bridgeProtocolVersion:void 0})==="handled")return}if(F.incomingType==="initResult"){let J=_e(Ur,V);y({initializationId:J.success?J.output.initializationId:void 0,error:pr()})}F.nack!==void 0&&i()!=="stopped"&&l(F.nack)}return function(B){let F=B.source===n.contentWindow,J=B.origin===o;if(!F||!J)return;let ne=_e(Ar,B.data);if(!ne.success){se(B.data,ne.issues);return}let R=ne.output;if(!hr(R)&&i()!=="initialized"){c("warn",{message:`Ignored ${R.type} before initialization completed`,payload:st(R)});return}switch(c("in",st(R)),R.type){case"connect":m(R);return;case"initResult":_(R);return;case"queryDataSource":x(R);return;case"unsubscribeDataSourceQuery":w(R);return;case"createPage":S(R);return;case"openPage":G(R);return;case"openExternalUrl":U(R);return;case"getPage":L(R);return;case"getUser":j(R);return;case"listUsers":Y(R);return;case"updatePage":ee(R);return;case"resize":W(R);return;case"invalidHostMessage":return;default:le(R)}}}function st(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var Te=class{constructor(n){this.onUnsubscribe=n}onUnsubscribe;bySubscriptionId=new Map;subscribe(n){this.unsubscribe(n.subscriptionId);let o={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(n.subscriptionId,{message:n,token:o,isRefreshing:!0,shouldRefreshAgain:!1}),o}isCurrent(n,o){return this.bySubscriptionId.get(n)?.token===o}unsubscribe(n){this.bySubscriptionId.delete(n)&&this.onUnsubscribe(n)}refresh(n){let o=[],i=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===n){if(i=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,o.push({message:c.message,token:c.token})}return i?o:void 0}finish(n,o){let i=this.bySubscriptionId.get(n);if(i?.token===o&&(i.isRefreshing=!1,!!i.shouldRefreshAgain))return i.shouldRefreshAgain=!1,i.isRefreshing=!0,{message:i.message,token:i.token}}unsubscribeAll(){for(let n of this.bySubscriptionId.keys())this.unsubscribe(n)}};function zr(e,n){if(e===void 0)return;let o="and"in e?e.and:[e];for(let i of o){let c=yo(i,n);if(c!==void 0)return c}}function yo(e,n){if(!Object.hasOwn(n.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let o=n.propertiesById[e.propertyId],i=Object.keys(e).find(y=>y!=="propertyId");if(i!==o.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${i}" does not match property type "${o.type}".`,isRetryable:!1};if("status"in e&&o.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,x=(Array.isArray(m)?m:[m]).find(w=>!o.groups.some(S=>S.name===w));return x===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${x}".`,isRetryable:!1}}}if("relation"in e&&!yt(nt,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=vo(e);if(c===void 0||o.type!==c.propertyType)return;let l=new Set(o.options.map(y=>y.name)),f=ho(c.operator).find(y=>!l.has(y));if(f!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${f}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function vo(e){if("select"in e)return{propertyType:"select",operator:e.select};if("multi_select"in e)return{propertyType:"multi_select",operator:e.multi_select};if("status"in e){let n=e.status;return"group_equals"in n||"group_does_not_equal"in n?void 0:{propertyType:"status",operator:n}}}function ho(e){let n;if("equals"in e)n=e.equals;else if("does_not_equal"in e)n=e.does_not_equal;else if("contains"in e)n=e.contains;else if("contains_all"in e)n=e.contains_all;else if("does_not_contain"in e)n=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:le(e);return Array.isArray(n)?n:[n]}var go=new Set(bt);function Hr(e,n){if(e===void 0)return;if(e.length>ot)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${ot} entries.`,isRetryable:!1};let o=new Set;for(let i of e){if(o.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(o.add(i.propertyId),!Object.hasOwn(n.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=n.propertiesById[i.propertyId];if(!go.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 Gr=5;function bo(e){let{iframe:n,prepareInitialState:o,handlers:i,onInitialized:c,onConnectionFailure:l,onLog:f,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:_,noConnectTimeoutMs:x,initialStateTimeoutMs:w,noInitResultTimeoutMs:S}=e,L=Math.max(_??3,3),G=new AbortController,U,j={},Y=!1,ee=new AbortController,W,se,V=6,B=new Te(a=>{y?.(a)});function F(a,b){f?.(a,b)}function J(a){let b=q.status;switch(b){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return le(b)}let E=yr(a,V);F("out",E),n.contentWindow?.postMessage(E,m)}function ne(a){J(oe(Ae,a))}function R(a){J(a)}function K(a){let b=q.status;switch(b){case"initialized":J(oe(nr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:le(b)}}async function pe(a,b){if(b===void 0)return;let E=await b(a);K({type:`${a.type}Result`,requestId:a.requestId,...E})}function Re(a){let b=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};K(b)}async function g(a,b=B.subscribe(a)){try{let E=ko(se,a.dataSourceId),ye=So(a,E);if(ye!==void 0){B.isCurrent(a.subscriptionId,b)&&(B.unsubscribe(a.subscriptionId),Re({subscriptionId:a.subscriptionId,response:{status:"error",error:ye}}));return}let Ne=await i.queryDataSource(a);if(!B.isCurrent(a.subscriptionId,b))return;Ne.status==="error"&&!Ne.error.isRetryable&&B.unsubscribe(a.subscriptionId),Re({subscriptionId:a.subscriptionId,response:Ne})}finally{let E=B.finish(a.subscriptionId,b);E!==void 0&&g(E.message,E.token)}}function k(a){q.status==="stopped"||q.status==="error"||(Object.assign(j,a),te())}async function $(a){if(i.openExternalUrl===void 0||G.signal.aborted||U===a.requestId)return;if(U!==void 0){let E={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};K(E);return}let b=dr(a.url);if(b===void 0){let E={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};K(E);return}U=a.requestId;try{let E=await i.openExternalUrl({...a,url:b},{signal:G.signal});if(G.signal.aborted)return;let ye={type:"openExternalUrlResult",requestId:a.requestId,...E};K(ye)}catch(E){if(!G.signal.aborted)throw E}finally{U===a.requestId&&(U=void 0)}}function te(){if(q.status!=="initialized")return;let a=j;j={},a.theme!==void 0&&K({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&K({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&K({type:"parentChanged",parent:a.parent}),a.page!==void 0&&K({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&K({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&K({type:"currentUserChanged",currentUser:a.currentUser})}let q=fr({async prepareInit(a){V=a.bridgeProtocolVersion;let b=await Qr;return q.status!=="preparingInit"?b:$r(b)},sendInitMessage:ne,warn:a=>F("warn",a),flushPendingHostStateChanges:te,minBridgeProtocolVersion:L,noConnectTimeoutMs:x,initialStateTimeoutMs:w,noInitResultTimeoutMs:S,stopHostWithFailure:ut,onInitResult(a){a.status==="success"&&W!==void 0&&c?.({manifest:W,initialHeight:a.initialHeight})},onConnectionFailure:a=>{ee.abort(),l?.(a)}});function $r(a){if(a.status==="error")return a;let b=oe(vr,{...a.initialState,...j});if(W=b.manifest,j={},V<Gr&&b.page.type==="unavailable")return{status:"error",error:et()};let E=Vr(b.manifest,b.dataSources);return E!==void 0?{status:"error",error:E}:(se=b.dataSources,Y=!0,{status:"success",initialState:b})}let Qr=Xr().catch(a=>(ee.signal.aborted||F("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Ee()}));async function Xr(){let a=await mr({...e,sandboxOrigin:m,signal:ee.signal,onError:E=>{F("warn",{message:"Failed to load custom block manifest",error:E})}});if(a.status==="error")return a;if(ee.signal.aborted)return{status:"error",error:Ee()};let b=await o({manifest:a.manifest,signal:ee.signal});return b.status==="error"?b:{status:"success",initialState:{...b.initialState,manifest:a.manifest}}}let it=Fr({iframe:n,sandboxOrigin:m,getInitStatus:()=>q.status,emit:F,sendNack:R,onInvalidConnect:q.handleInvalidConnect,onInvalidInitResult:q.handleInvalidInitResult,onConnect:q.handleConnect,onInitResult:q.handleInitResult,onQueryDataSource:g,onUnsubscribeDataSourceQuery:a=>B.unsubscribe(a.subscriptionId),onOpenExternalUrl:$,onCreatePage:a=>pe(a,i.createPage),onGetPage:a=>pe(a,i.getPage),onOpenPage:a=>pe(a,i.openPage),onGetUser:a=>pe(a,i.getUser),onListUsers:a=>pe(a,i.listUsers),onUpdatePage:a=>pe(a,i.updatePage),onResize:a=>i.resize?.(a)});window.addEventListener("message",it),n.addEventListener("load",q.onIframeLoad);function at(){G.abort(),ee.abort(),window.removeEventListener("message",it),n.removeEventListener("load",q.onIframeLoad),q.stop(),B.unsubscribeAll()}function ut(a){at(),F("warn",a),l?.(a)}return{stop:at,setTheme(a){k({theme:a})},setContrastMode(a){k({contrastMode:a})},setParent(a){k({parent:a})},setPage(a){if(a.type==="unavailable"&&V<Gr&&(q.status==="preparingInit"&&Y||q.status==="waitingForInitResult"||q.status==="initialized")){ut({...et(),phase:"runtime",source:"host"});return}k({page:a})},setCurrentUser(a){k({currentUser:a})},setDataSources(a){let b={bindings:oe(fe,a.bindings)};if(q.hasConnectedSandbox&&W!==void 0&&Vr(W,b)!==void 0){F("warn",{message:"Ignored invalid data source bindings update",payload:b});return}se=b,k({dataSources:b})},refreshQuery({dataSourceId:a}){if(q.status!=="initialized")return;let b=oe(re,a),E=B.refresh(b);if(E===void 0){F("warn",`No active query exists for data source "${a}"`);return}for(let ye of E)g(ye.message,ye.token)}}}function ko(e,n){return Object.values(e?.bindings??{}).find(o=>o.collectionPointer?.id===n)?.collectionSchema}function Vr(e,n){for(let[o,i]of Object.entries(e.dataSources)){let c=n.bindings[o];if(c?.collectionPointer===void 0||c.collectionSchema===void 0)return ar();for(let[l,f]of Object.entries(i.properties??{})){let y=c.propertyIdsByKey?.[l];if(y===void 0)return ur();if(c.collectionSchema.propertiesById[y]?.type!==f.type)return cr()}}}function So(e,n){return n===void 0?e.filter===void 0&&(e.sorts?.length??0)===0?void 0:{code:"data_source_schema_unavailable",message:"You cannot query this data source with filters or sorts because its schema is unavailable.",isRetryable:!1}:zr(e.filter,n)??Hr(e.sorts,n)}function Io(e){return oe(A,e)}export{Ue as LATEST_BRIDGE_PROTOCOL_VERSION,Wr as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,bo as createCustomBlockHost,Jr as getAutoBoundPropertyIdsByKey,rt as isLocalCustomBlockUrl,Io as toNotionPageId};
|
|
1
|
+
var He=6,Ve=6;function ln(e){let{manifestProperties:t,propertySchemasById:o}=e,i=[];for(let[l,c]of Object.entries(t)){let p=pn({propertyKey:l,manifestProperty:c,propertySchemasById:o});p!==void 0&&i.push([l,p])}return Object.fromEntries(i)}function pn(e){let{propertyKey:t,manifestProperty:o,propertySchemasById:i}=e,l=ft(o.name),c=Object.entries(i).filter(([p,y])=>y.type===o.type&&(p===t||ft(y.name)===l));return c.length===1?c[0][0]:void 0}function ft(e){return e.trim().toLowerCase()}var De,fn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Ge(e){return!e&&!De?fn:{lang:e?.lang??De?.lang,message:e?.message,abortEarly:e?.abortEarly??De?.abortEarly,abortPipeEarly:e?.abortPipeEarly??De?.abortPipeEarly}}var mn;function yn(e){return mn?.get(e)}var vn;function dn(e){return vn?.get(e)}var hn;function gn(e,t){return hn?.get(e)?.get(t)}function Se(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function D(e,t,o,i,l){let c=l&&"input"in l?l.input:o.value,p=l?.expected??e.expects??null,y=l?.received??Se(c),m={kind:e.kind,type:e.type,input:c,expected:p,received:y,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${y}`,requirement:e.requirement,path:l?.path,issues:l?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},_=e.kind==="schema",x=l?.message??e.message??gn(e.reference,m.lang)??(_?dn(m.lang):null)??i.message??yn(m.lang);x!==void 0&&(m.message=typeof x=="function"?x(m):x),_&&(o.typed=!1),o.issues?o.issues.push(m):o.issues=[m]}var mt=new WeakMap;function V(e){let t=mt.get(e);return t||(t={version:1,vendor:"valibot",validate(o){return e["~run"]({value:o},Ge())}},mt.set(e,t)),t}function bn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function $e(e,t){let o=[...new Set(e)];return o.length>1?`(${o.join(` ${t} `)})`:o[0]??"never"}var Sn=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 ke(e){return{kind:"validation",type:"finite",reference:ke,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,o){return t.typed&&!this.requirement(t.value)&&D(this,"finite",t,o),t}}}function we(e,t){return{kind:"validation",type:"max_length",reference:we,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(o,i){return o.typed&&o.value.length>this.requirement&&D(this,"length",o,i,{received:`${o.value.length}`}),o}}}function Ie(e,t){return{kind:"validation",type:"min_length",reference:Ie,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(o,i){return o.typed&&o.value.length<this.requirement&&D(this,"length",o,i,{received:`${o.value.length}`}),o}}}function _e(e,t){return{kind:"validation",type:"min_value",reference:_e,async:!1,expects:`>=${e instanceof Date?e.toJSON():Se(e)}`,requirement:e,message:t,"~run"(o,i){return o.typed&&!(o.value>=this.requirement)&&D(this,"value",o,i,{received:o.value instanceof Date?o.value.toJSON():Se(o.value)}),o}}}function Qe(e,t){return{kind:"validation",type:"regex",reference:Qe,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(o,i){return o.typed&&!this.requirement.test(o.value)&&D(this,"format",o,i),o}}}function Xe(e){return{kind:"transformation",type:"transform",reference:Xe,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var vt={abortEarly:!0};function dt(e,t,o){return typeof e.fallback=="function"?e.fallback(t,o):e.fallback}function qe(e,t,o){return typeof e.default=="function"?e.default(t,o):e.default}function ht(e,t){return!e["~run"]({value:t},vt).issues}function E(e,t){return{kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){let l=o.value;if(Array.isArray(l)){o.typed=!0,o.value=[];for(let c=0;c<l.length;c++){let p=l[c],y=this.item["~run"]({value:p},i);if(y.issues){let m={type:"array",origin:"value",input:l,key:c,value:p};for(let _ of y.issues)_.path?_.path.unshift(m):_.path=[m],o.issues?.push(_);if(o.issues||(o.issues=y.issues),i.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value.push(y.value)}}else D(this,"type",o,i);return o}}}function h(e){return{kind:"schema",type:"boolean",reference:h,expects:"boolean",async:!1,message:e,get"~standard"(){return V(this)},"~run"(t,o){return typeof t.value=="boolean"?t.typed=!0:D(this,"type",t,o),t}}}function s(e,t){return{kind:"schema",type:"literal",reference:s,expects:Se(e),async:!1,literal:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){return o.value===this.literal?o.typed=!0:D(this,"type",o,i),o}}}function We(e){return{kind:"schema",type:"nan",reference:We,expects:"NaN",async:!1,message:e,get"~standard"(){return V(this)},"~run"(t,o){return Number.isNaN(t.value)?t.typed=!0:D(this,"type",t,o),t}}}function A(e,t){return{kind:"schema",type:"nullable",reference:A,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return V(this)},"~run"(o,i){return o.value===null&&(this.default!==void 0&&(o.value=qe(this,o,i)),o.value===null)?(o.typed=!0,o):this.wrapped["~run"](o,i)}}}function C(e){return{kind:"schema",type:"number",reference:C,expects:"number",async:!1,message:e,get"~standard"(){return V(this)},"~run"(t,o){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:D(this,"type",t,o),t}}}function n(e,t){return{kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){let l=o.value;if(l&&typeof l=="object"){o.typed=!0,o.value={};for(let c in this.entries){let p=this.entries[c];if(c in l||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=c in l?l[c]:qe(p),m=p["~run"]({value:y},i);if(m.issues){let _={type:"object",origin:"value",input:l,key:c,value:y};for(let x of m.issues)x.path?x.path.unshift(_):x.path=[_],o.issues?.push(x);if(o.issues||(o.issues=m.issues),i.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[c]=m.value}else if(p.fallback!==void 0)o.value[c]=dt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(D(this,"key",o,i,{input:void 0,expected:`"${c}"`,path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]}),i.abortEarly))break}}else D(this,"type",o,i);return o}}}function u(e,t){return{kind:"schema",type:"optional",reference:u,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return V(this)},"~run"(o,i){return o.value===void 0&&(this.default!==void 0&&(o.value=qe(this,o,i)),o.value===void 0)?(o.typed=!0,o):this.wrapped["~run"](o,i)}}}function w(e,t){return{kind:"schema",type:"picklist",reference:w,expects:$e(e.map(Se),"|"),async:!1,options:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){return this.options.includes(o.value)?o.typed=!0:D(this,"type",o,i),o}}}function U(e,t,o){return{kind:"schema",type:"record",reference:U,expects:"Object",async:!1,key:e,value:t,message:o,get"~standard"(){return V(this)},"~run"(i,l){let c=i.value;if(c&&typeof c=="object"){i.typed=!0,i.value={};for(let p in c)if(bn(c,p)){let y=c[p],m=this.key["~run"]({value:p},l);if(m.issues){let x={type:"object",origin:"key",input:c,key:p,value:y};for(let P of m.issues)P.path=[x],i.issues?.push(P);if(i.issues||(i.issues=m.issues),l.abortEarly){i.typed=!1;break}}let _=this.value["~run"]({value:y},l);if(_.issues){let x={type:"object",origin:"value",input:c,key:p,value:y};for(let P of _.issues)P.path?P.path.unshift(x):P.path=[x],i.issues?.push(P);if(i.issues||(i.issues=_.issues),l.abortEarly){i.typed=!1;break}}(!m.typed||!_.typed)&&(i.typed=!1),m.typed&&(i.value[m.value]=_.value)}}else D(this,"type",i,l);return i}}}function f(e,t){return{kind:"schema",type:"strict_object",reference:f,expects:"Object",async:!1,entries:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){let l=o.value;if(l&&typeof l=="object"){o.typed=!0,o.value={};for(let c in this.entries){let p=this.entries[c];if(c in l||(p.type==="exact_optional"||p.type==="optional"||p.type==="nullish")&&p.default!==void 0){let y=c in l?l[c]:qe(p),m=p["~run"]({value:y},i);if(m.issues){let _={type:"object",origin:"value",input:l,key:c,value:y};for(let x of m.issues)x.path?x.path.unshift(_):x.path=[_],o.issues?.push(x);if(o.issues||(o.issues=m.issues),i.abortEarly){o.typed=!1;break}}m.typed||(o.typed=!1),o.value[c]=m.value}else if(p.fallback!==void 0)o.value[c]=dt(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(D(this,"key",o,i,{input:void 0,expected:`"${c}"`,path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]}),i.abortEarly))break}if(!o.issues||!i.abortEarly){for(let c in l)if(!(c in this.entries)){D(this,"key",o,i,{input:c,expected:"never",path:[{type:"object",origin:"key",input:l,key:c,value:l[c]}]});break}}}else D(this,"type",o,i);return o}}}function r(e){return{kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,get"~standard"(){return V(this)},"~run"(t,o){return typeof t.value=="string"?t.typed=!0:D(this,"type",t,o),t}}}function yt(e){let t;if(e)for(let o of e)if(t)for(let i of o.issues)t.push(i);else t=o.issues;return t}function k(e,t){return{kind:"schema",type:"union",reference:k,expects:$e(e.map(o=>o.expects),"|"),async:!1,options:e,message:t,get"~standard"(){return V(this)},"~run"(o,i){let l,c,p;for(let y of this.options){let m=y["~run"]({value:o.value},i);if(m.typed)if(m.issues)c?c.push(m):c=[m];else{l=m;break}else p?p.push(m):p=[m]}if(l)return l;if(c){if(c.length===1)return c[0];D(this,"type",o,i,{issues:yt(c)}),o.typed=!0}else{if(p?.length===1)return p[0];D(this,"type",o,i,{issues:yt(p)})}return o}}}function xe(){return{kind:"schema",type:"unknown",reference:xe,expects:"unknown",async:!1,get"~standard"(){return V(this)},"~run"(e){return e.typed=!0,e}}}function v(e,t,o){return{kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:o,get"~standard"(){return V(this)},"~run"(i,l){let c=i.value;if(c&&typeof c=="object"){let p,y=0,m=this.key,_=[],x=(P,S)=>{for(let F of P.options){if(F.type==="variant")x(F,new Set(S).add(F.key));else{let G=!0,z=0;for(let R of S){let te=F.entries[R];if(R in c?te["~run"]({typed:!1,value:c[R]},vt).issues:te.type!=="exact_optional"&&te.type!=="optional"&&te.type!=="nullish"){G=!1,m!==R&&(y<z||y===z&&R in c&&!(m in c))&&(y=z,m=R,_=[]),m===R&&_.push(F.entries[R].expects);break}z++}if(G){let R=F["~run"]({value:c},l);(!p||!p.typed&&R.typed)&&(p=R)}}if(p&&!p.issues)break}};if(x(this,new Set([this.key])),p)return p;D(this,"type",i,l,{input:c[m],expected:$e(_,"|"),path:[{type:"object",origin:"value",input:c,key:m,value:c[m]}]})}else D(this,"type",i,l);return i}}}function ie(e,t,o){let i=e["~run"]({value:t},Ge(o));if(i.issues)throw new Sn(i.issues);return i.value}function H(...e){return{...e[0],pipe:e,get"~standard"(){return V(this)},"~run"(t,o){for(let i of e)if(i.kind!=="metadata"){if(t.issues&&(i.kind==="schema"||i.kind==="transformation")){t.typed=!1;break}(!t.issues||!o.abortEarly&&!o.abortPipeEarly)&&(t=i["~run"](t,o))}return t}}}function Ce(e,t,o){let i=e["~run"]({value:t},Ge(o));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}var le=H(r(),ce("NotionBlockId")),X=H(r(),ce("NotionDataSourceId")),T=H(r(),ce("NotionPageId")),gt=H(r(),ce("NotionAgentId")),bt=H(r(),ce("NotionSpaceId"));var St=w(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),Je=n({id:r(),name:r(),color:u(St),description:u(r())}),kn=n({id:r(),name:r(),color:u(St),option_ids:E(r())}),In=n({synced_property_id:r(),synced_property_name:r()}),j=n({name:r(),description:u(r())}),_n=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],kt=w(_n),It=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Ke=v("type",[n({...j.entries,type:s("title")}),n({...j.entries,type:s("rich_text")}),n({...j.entries,type:s("number")}),n({...j.entries,type:s("checkbox")}),n({...j.entries,type:s("url")}),n({...j.entries,type:s("email")}),n({...j.entries,type:s("phone_number")}),n({...j.entries,type:s("select"),options:E(Je)}),n({...j.entries,type:s("multi_select"),options:E(Je)}),n({...j.entries,type:s("status"),options:E(Je),groups:E(kn)}),n({...j.entries,type:s("date")}),n({...j.entries,type:s("people")}),n({...j.entries,type:s("files")}),n({...j.entries,type:s("unique_id")}),n({...j.entries,type:s("relation"),data_source_id:u(r()),dual_property:u(In)}),n({...j.entries,type:s("place")}),n({...j.entries,type:s("formula")}),n({...j.entries,type:s("rollup")}),n({...j.entries,type:s("button")}),n({...j.entries,type:s("verification")}),n({...j.entries,type:s("last_visited_time")}),n({...j.entries,type:s("location")}),n({...j.entries,type:s("created_time")}),n({...j.entries,type:s("last_edited_time")}),n({...j.entries,type:s("created_by")}),n({...j.entries,type:s("last_edited_by")})]);var _t=n({id:X,table:r(),spaceId:u(bt)}),xt=n({id:u(X),propertiesById:U(r(),Ke)}),Lo=n({key:r(),collectionPointer:u(_t),collectionSchema:u(xt),propertyIdsByKey:U(r(),u(r())),propertySchemasById:U(r(),Ke)}),xn=n({collectionPointer:u(_t),collectionSchema:u(xt),propertyIdsByKey:u(U(r(),u(r())))}),me=U(r(),xn);var de=w(["standard","high"]),Ct="standard";var Pt=n({type:s("contrastModeChanged"),contrastMode:de});var Te=n({id:r(),table:r()});var ae=v("type",[n({type:s("page_id"),page_id:T}),n({type:s("data_source_id"),data_source_id:X}),n({type:s("workspace"),workspace:s(!0)}),n({type:s("block_id"),block_id:le}),n({type:s("agent_id"),agent_id:gt}),n({type:s("unavailable")})]);var he=v("type",[n({type:s("unavailable")}),n({type:s("page"),id:T,parent:ae})]),Cn=n({type:s("emoji"),emoji:r()}),Pn=n({type:s("custom_emoji"),custom_emoji:n({id:r(),name:u(r()),url:u(r())})}),Ot=n({type:s("external"),external:n({url:r()})}),jt=n({type:s("file"),file:n({url:r(),expiry_time:u(r())})}),Ne=v("type",[Cn,Pn,Ot,jt]),Ue=v("type",[Ot,jt]),W=A(r()),Et=U(r(),xe()),Ye=k([n({id:r(),name:u(r()),color:u(r()),description:u(W)}),n({name:r(),id:u(r()),color:u(r()),description:u(W)})]),En=n({start:r(),end:u(W),time_zone:u(W)}),On=k([n({object:u(s("user")),id:r()}),n({object:s("group"),id:r(),name:u(W)})]),jn=n({id:r()}),Rn=k([n({type:s("external"),name:r(),external:n({url:r()})}),n({type:s("file"),name:r(),file:n({url:r(),expiry_time:u(r())})})]),Mn=n({lat:C(),lon:C(),name:u(W),address:u(W),aws_place_id:u(W),google_place_id:u(W)}),N={id:r()},Ae=A(n({...Te.entries,table:w(["notion_user","bot","organization_bot"]),spaceId:u(r())})),Rt=v("type",[n({...N,type:s("title"),title:E(Et)}),n({...N,type:s("rich_text"),rich_text:E(Et)}),n({...N,type:s("number"),number:A(C())}),n({...N,type:s("url"),url:W}),n({...N,type:s("email"),email:W}),n({...N,type:s("phone_number"),phone_number:W}),n({...N,type:s("checkbox"),checkbox:h()}),n({...N,type:s("select"),select:A(Ye)}),n({...N,type:s("status"),status:A(Ye)}),n({...N,type:s("multi_select"),multi_select:E(Ye)}),n({...N,type:s("date"),date:A(En)}),n({...N,type:s("people"),people:E(On)}),n({...N,type:s("relation"),has_more:u(h()),relation:E(jn)}),n({...N,type:s("files"),files:E(Rn)}),n({...N,type:s("place"),place:A(Mn)}),n({...N,type:s("created_time"),created_time:W}),n({...N,type:s("last_edited_time"),last_edited_time:W}),n({...N,type:s("created_by"),created_by:Ae}),n({...N,type:s("last_edited_by"),last_edited_by:Ae}),n({...N,type:s("last_visited_time"),last_visited_time:W})]),Pe=U(r(),Rt),Bn=U(r(),A(Rt)),re=n({object:s("page"),id:T,parent:ae,properties:Bn,created_by:u(Ae,null),last_edited_by:u(Ae,null),last_visited_time:u(A(r()),null),created_time:u(A(r()),null),last_edited_time:u(A(r()),null),icon:u(A(Ne),null),cover:u(A(Ue),null),url:u(A(r()),null),public_url:u(A(r()),null),is_archived:h(),in_trash:h()}),ge=n({object:s("page"),id:T,parent:ae,properties:Pe,created_time:u(r()),last_edited_time:u(r()),icon:u(Ne),cover:u(Ue),url:u(r()),public_url:u(r()),is_archived:h(),in_trash:h()});var Dn=r(),Mt=n({code:Dn,message:r(),isRetryable:h()}),Bt=v("status",[n({type:s("createPageResult"),requestId:r(),status:s("success"),page:re}),n({type:s("createPageResult"),requestId:r(),status:s("error"),error:Mt})]),Dt=v("status",[n({type:s("createPageResult"),requestId:r(),status:s("success"),page:k([re,ge])}),n({type:s("createPageResult"),requestId:r(),status:s("error"),error:Mt})]);var Ze=H(r(),ce("NotionUserId")),pe=n({object:s("user"),id:Ze,name:u(r()),avatar_url:A(r()),type:s("person"),person:n({email:r()})}),wt=n({object:s("list"),results:E(pe),next_cursor:A(r()),has_more:h(),type:s("user"),user:U(r(),xe())});var qt=n({type:s("currentUserChanged"),currentUser:pe});var Tt=n({type:s("dataSourcesChanged"),dataSources:n({bindings:me})});var wn=r(),At=n({code:wn,message:r(),isRetryable:h()}),Nt=n({type:s("getPage"),requestId:r(),pageId:T,dataSourceId:u(X)}),Ut=v("status",[n({type:s("getPageResult"),requestId:r(),status:s("success"),page:re}),n({type:s("getPageResult"),requestId:r(),status:s("error"),error:At})]),Ft=v("status",[n({type:s("getPageResult"),requestId:r(),status:s("success"),page:k([re,ge])}),n({type:s("getPageResult"),requestId:r(),status:s("error"),error:At})]);var qn=r(),Tn=n({code:qn,message:r(),isRetryable:h()}),zt=n({type:s("getUser"),requestId:r(),userId:Ze}),Lt=v("status",[n({type:s("getUserResult"),requestId:r(),status:s("success"),user:pe}),n({type:s("getUserResult"),requestId:r(),status:s("error"),error:Tn})]);var An=v("type",[n({type:s("emoji"),emoji:r()}),n({type:s("external"),url:r()})]),Nn=n({name:r(),description:u(r()),type:kt}),Un=n({name:r(),description:u(r()),icon:u(An),properties:u(U(r(),Nn),{})}),ye=n({version:s(1),name:u(r()),description:u(r()),slashCommand:u(r()),icon:u(n({type:s("emoji"),emoji:r()})),dataSources:u(U(r(),Un),{})});var be=w(["light","dark"]);var Fn=r(),zn=n({code:Fn,message:r(),isRetryable:h()});var Fe=v("status",[n({type:s("init"),initializationId:r(),status:s("success"),theme:be,contrastMode:de,blockId:le,parent:ae,page:he,manifest:ye,dataSources:n({bindings:me}),currentUser:pe}),n({type:s("init"),initializationId:r(),status:s("error"),error:zn})]);var Ht=n({type:s("invalidSandboxMessage"),reason:r()});var Ln=r(),Hn=n({code:Ln,message:r(),isRetryable:h()}),Vt=n({type:s("listUsers"),requestId:r(),startCursor:u(r()),pageSize:u(C())}),Gt=v("status",[n({type:s("listUsersResult"),requestId:r(),status:s("success"),list:wt}),n({type:s("listUsersResult"),requestId:r(),status:s("error"),error:Hn})]);var Vn=r(),Gn=n({code:Vn,message:r(),isRetryable:h()}),$t=n({type:s("openExternalUrl"),requestId:r(),url:r()}),Qt=v("status",[n({type:s("openExternalUrlResult"),requestId:r(),status:s("success")}),n({type:s("openExternalUrlResult"),requestId:r(),status:s("error"),error:Gn})]);var $n=w(["side_peek","center_peek"]),Qn=r(),Xn=n({code:Qn,message:r(),isRetryable:h()}),Xt=n({type:s("openPage"),requestId:r(),pageId:T,mode:$n}),Wt=v("status",[n({type:s("openPageResult"),requestId:r(),status:s("success"),pageId:T}),n({type:s("openPageResult"),requestId:r(),status:s("error"),error:Xn})]);var Jt=n({type:s("pageChanged"),page:he});var Kt=n({type:s("parentChanged"),parent:ae});var Yt=n({unit:w(["year","month","week","day"]),value:C(),time:r(),defaultTimeZone:u(r())}),Wn=n({unit:w(["hour","minute"]),value:C()}),Zt=n({unit:s("none")}),Jn=k([Yt,Wn]),er=u(k([Yt,Zt])),tr=u(k([Jn,Zt])),Kn=n({type:s("date"),start_date:r(),reminder:er}),Yn=n({type:s("daterange"),start_date:r(),end_date:r(),reminder:er}),Zn=n({type:s("datetime"),start_date:r(),start_time:r(),time_zone:u(r()),reminder:tr}),eo=n({type:s("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:u(r()),reminder:tr}),rr=v("type",[Kn,Yn,Zn,eo]);var nr=k([r(),C(),h(),rr,E(r()),E(Te)]);var or=n({id:T,is_archived:h(),in_trash:h(),propertiesById:U(r(),u(nr))});var to=r(),sr=n({code:to,message:r(),isRetryable:h()}),ir=v("status",[n({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("success"),items:E(re),hasMore:h()}),n({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("error"),error:sr})]),ar=v("status",[n({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("success"),items:E(k([re,or])),hasMore:h()}),n({type:s("queryDataSourceResult"),subscriptionId:r(),status:s("error"),error:sr})]);var ur=n({type:s("themeChanged"),theme:be});var ro=r(),cr=n({code:ro,message:r(),isRetryable:h()}),lr=v("status",[n({type:s("updatePageResult"),requestId:r(),status:s("success"),page:re}),n({type:s("updatePageResult"),requestId:r(),status:s("error"),error:cr})]),pr=v("status",[n({type:s("updatePageResult"),requestId:r(),status:s("success"),page:k([re,ge])}),n({type:s("updatePageResult"),requestId:r(),status:s("error"),error:cr})]);var fr=v("type",[Fe,ur,Pt,Kt,Jt,qt,Tt,Lt,Gt,Wt,Qt,Ht]),mr=v("type",[...fr.options,ir,Ut,Bt,lr]),li=v("type",[...fr.options,ar,Ft,Dt,pr]);function yr(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function vr(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function et(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function tt(e){let{currentBridgeProtocolVersion:t,minBridgeProtocolVersion:o}=e;return{code:"unsupported_protocol_version",message:`Sandbox bridge protocol version ${t} is not supported. Minimum supported version is ${o}.`,isRetryable:!1}}function rt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function dr(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function hr(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function gr(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function br(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function Sr(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function kr(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Ee(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function ee(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function nt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var no=5e3,oo=5e3,so=5e3;function Ir(e){let{prepareInit:t,sendInitMessage:o,warn:i,flushPendingHostStateChanges:l,minBridgeProtocolVersion:c,noConnectTimeoutMs:p=no,initialStateTimeoutMs:y=oo,noInitResultTimeoutMs:m=so,stopHostWithFailure:_,onInitResult:x,onConnectionFailure:P}=e,S="waitingForConnect",F,G,z,R,te=!1,ne=!1;function K(){F!==void 0&&(window.clearTimeout(F),F=void 0)}function ue(){G!==void 0&&(window.clearTimeout(G),G=void 0)}function $(){z!==void 0&&(window.clearTimeout(z),z=void 0)}function M(g){let{initializationId:I,error:Q,phase:oe,source:q}=g;switch(S){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"error":case"stopped":return;default:return ee(S)}S="error",R=I,K(),ue(),o({type:"init",initializationId:I,status:"error",error:Q}),P?.({...Q,phase:oe,source:q})}async function L(g){if(S==="waitingForConnect"){S="preparingInit",R=g.initializationId,K(),G=window.setTimeout(()=>{if(S!=="preparingInit")return;let I=dr();i({...I,initializationId:g.initializationId}),M({initializationId:g.initializationId,error:I,phase:"init",source:"host"})},y);try{let I=await t(g);if(S!=="preparingInit")return;if(ue(),I.status==="error"){M({initializationId:g.initializationId,error:I.error,phase:"init",source:"host"});return}S="waitingForInitResult";let Q={type:"init",initializationId:g.initializationId,status:"success",theme:I.initialState.theme,contrastMode:I.initialState.contrastMode??Ct,blockId:I.initialState.blockId,parent:I.initialState.parent,page:I.initialState.page,currentUser:I.initialState.currentUser,manifest:I.initialState.manifest,dataSources:I.initialState.dataSources};o(Q),z=window.setTimeout(()=>{if(S!=="waitingForInitResult")return;S="error";let oe=Sr();P?.({...oe,phase:"initResult",source:"host"}),i({...oe,initializationId:g.initializationId})},m)}catch(I){if(S!=="preparingInit")return;i({message:"Failed to prepare custom block initialization",error:I}),M({initializationId:g.initializationId,error:Ee(),phase:"init",source:"host"})}}}function Y(g){if(S!=="stopped"&&S==="waitingForConnect"){if(!nt(g.bridgeProtocolVersion)){let I=et({currentBridgeProtocolVersion:g.bridgeProtocolVersion});M({initializationId:g.initializationId,error:I,phase:"connect",source:"host"});return}if(g.bridgeProtocolVersion<c){let I=tt({currentBridgeProtocolVersion:g.bridgeProtocolVersion,minBridgeProtocolVersion:c});M({initializationId:g.initializationId,error:I,phase:"connect",source:"host"});return}if(g.status==="error"){M({initializationId:g.initializationId,error:g.error,phase:"connect",source:"sandbox"});return}ne=!0,L(g)}}function se(g){if(S==="stopped"||S!=="waitingForConnect")return"handled";let{initializationId:I,bridgeProtocolVersion:Q}=g;if(I===void 0)return"nack";let oe=g.error;return Q!==void 0&&(nt(Q)?Q<c&&(oe=tt({currentBridgeProtocolVersion:Q,minBridgeProtocolVersion:c})):oe=et({currentBridgeProtocolVersion:Q})),M({initializationId:I,error:oe,phase:"connect",source:"host"}),"handled"}function B(g){let{initializationId:I,error:Q}=g;S!=="waitingForInitResult"||I===void 0||I!==R||(K(),$(),S="error",i(Q),P?.({...Q,phase:"initResult",source:"host"}))}function Z(){if(S!=="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,K(),S==="waitingForConnect"&&(F=window.setTimeout(()=>{if(S!=="waitingForConnect")return;S="error";let g=yr();i(g),P?.({...g,phase:"connect",source:"host"})},p))}}function fe(g){if(S!=="waitingForInitResult"||g.initializationId!==R){i({message:"Ignored stale or unexpected initResult",payload:g});return}$(),S=g.status==="success"?"initialized":"error",g.status==="success"?l():P?.({...g.error,phase:"initResult",source:"sandbox"}),x?.(g)}function Be(){S="stopped",K(),ue(),$()}return{get status(){return S},get hasConnectedSandbox(){return ne},handleConnect:Y,handleInitResult:fe,handleInvalidConnect:se,handleInvalidInitResult:B,onIframeLoad:Z,stop:Be}}function ot({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}async function _r(e){let t=new AbortController,o=()=>t.abort();e.signal.addEventListener("abort",o,{once:!0});let i=new Promise((c,p)=>{t.signal.addEventListener("abort",()=>p(t.signal.reason),{once:!0})});e.signal.aborted&&t.abort();let l=e.manifestSource==="local"?window.setTimeout(()=>{t.abort(new Error("Manifest loading timed out after 5000 ms."))},5e3):void 0;try{let c=await Promise.race([e.manifestSource==="local"?io(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,c)}}catch(c){return e.signal.aborted||e.onError(c),{status:"error",error:{code:"manifest_unavailable",message:"The custom block manifest is unavailable.",isRetryable:!0}}}finally{window.clearTimeout(l),e.signal.removeEventListener("abort",o)}}async function io(e,t){let o=new URL(e);if(!ot({url:o,hostOrigin:window.location.origin}))throw new Error("Preview requires a separate loopback origin.");let i=await fetch(new URL("/manifest",o),{credentials:"omit",redirect:"error",cache:"no-store",signal:t});if(!i.ok)throw new Error(`Manifest request failed: HTTP ${i.status}.`);return i.json()}function Cr(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 Pr(e){let t={};for(let o of Object.values(e.properties))o&&(t[o.id]=uo(o));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:t}}function xr(e){return e.map(t=>{if(typeof t.plain_text=="string")return t.plain_text;let o=t.text;return o&&typeof o=="object"&&"content"in o&&typeof o.content=="string"?o.content:""}).join("")}function st(e){if(e==null||e==="")return;let t=new Date(e);if(Number.isFinite(t.getTime()))return{type:"datetime",start_date:t.toISOString().slice(0,10),start_time:t.toISOString().slice(11,16),time_zone:"UTC"}}function ao(e){let t=e.start.includes("T")||e.time_zone!=null,o=e.start.match(/([+-])(\d{2}):(\d{2})$/),i=o?(Number(o[2])*60+Number(o[3]))*(o[1]==="-"?-1:1):0,l=m=>{if(!m.includes("T"))return{date:m,time:"00:00"};let _=m.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(_)return{date:_[1],time:_[2]};if(!e.time_zone){let S=new Date(new Date(m).getTime()+i*6e4).toISOString();return{date:S.slice(0,10),time:S.slice(11,16)}}let x=new Intl.DateTimeFormat("en-CA",{timeZone:e.time_zone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(m)),P=S=>x.find(F=>F.type===S)?.value;return{date:`${P("year")}-${P("month")}-${P("day")}`,time:`${P("hour")}:${P("minute")}`}},c=l(e.start),p=e.end?l(e.end):void 0;if(!t)return p?{type:"daterange",start_date:c.date,end_date:p.date}:{type:"date",start_date:c.date};let y=e.time_zone??(i===0?"UTC":`UTC${i<0?"-":"+"}${Math.floor(Math.abs(i)/60)}${Math.abs(i)%60===0?"":`:${String(Math.abs(i)%60).padStart(2,"0")}`}`);return p?{type:"datetimerange",start_date:c.date,start_time:c.time,end_date:p.date,end_time:p.time,time_zone:y}:{type:"datetime",start_date:c.date,start_time:c.time,time_zone:y}}function uo(e){switch(e.type){case"title":return xr(e.title);case"rich_text":return xr(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?ao(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"place":return"";case"created_time":return st(e.created_time);case"last_edited_time":return st(e.last_edited_time);case"last_visited_time":return st(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return ee(e)}}function Er(e,t){if(t>=6||e.status==="error")return e;switch(e.type){case"queryDataSourceResult":return{...e,items:e.items.map(Pr)};case"getPageResult":case"createPageResult":case"updatePageResult":return{...e,page:Cr(e.page)};default:return ee(e)}}function Or(e,t){return e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"?e:Er(e,t)}var jr=n({theme:be,contrastMode:u(de),blockId:le,parent:ae,page:he,manifest:ye,dataSources:n({bindings:me}),currentUser:pe});function Rr(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 Mr(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Br=n({code:r(),message:r(),isRetryable:h()});var Dr={type:s("connect"),initializationId:r(),bridgeProtocolVersion:C(),sdkVersion:r()},wr=v("status",[n({status:s("success"),manifest:u(ye),...Dr}),n({status:s("error"),error:Br,...Dr})]);var co=v("type",[n({type:s("start")}),n({type:s("end")}),n({type:s("before"),blockId:le}),n({type:s("after"),blockId:le})]),lo=v("type",[n({type:s("page_id"),page_id:T}),n({type:s("data_source_id"),data_source_id:X})]),qr=n({type:s("createPage"),requestId:r(),parent:lo,properties:Pe,position:u(co)});var po=r(),fo=n({code:po,message:r(),isRetryable:h()}),Tr=v("status",[n({type:s("initResult"),initializationId:r(),status:s("success"),initialHeight:u(H(C(),ke(),_e(0)))}),n({type:s("initResult"),initializationId:r(),status:s("error"),error:fo})]);var Ar=n({type:s("invalidHostMessage"),reason:r()});var Nr=w(["ascending","descending"]);var Ur=H(T,Qe(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),Xe(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),it=k([f({contains:Ur}),f({does_not_contain:Ur})]),Me=k([f({is_empty:s(!0)}),f({is_not_empty:s(!0)})]),Re=k([r(),E(r())]),Fr=f({object:w(["user","group"]),id:H(r(),Ie(1))}),mo=k([f({contains:Fr}),f({does_not_contain:Fr}),Me]),zr=f({object:s("user"),id:H(r(),Ie(1),we(2e3))}),yo=k([f({contains:zr}),f({does_not_contain:zr}),f({is_empty:s(!0)}),f({is_not_empty:s(!0)})]),Oe=k([f({equals:r()}),f({does_not_equal:r()}),f({contains:r()}),f({does_not_contain:r()}),f({starts_with:r()}),f({ends_with:r()}),Me]),vo=k([f({equals:C()}),f({does_not_equal:C()}),f({greater_than:C()}),f({less_than:C()}),f({greater_than_or_equal_to:C()}),f({less_than_or_equal_to:C()}),Me]),ho=k([f({equals:h()}),f({does_not_equal:h()})]),Gr=k([f({equals:Re}),f({does_not_equal:Re}),Me]),Lr=w(["To-do","In progress","Complete","Current","Future"]),Hr=k([Lr,H(E(Lr),Ie(1),we(5))]),go=k([f({group_equals:Hr}),f({group_does_not_equal:Hr})]),bo=k([Gr,go]),So=k([f({contains:Re}),f({contains_all:Re}),f({does_not_contain:Re}),Me]),J=w(["start_date","end_date"]),ko=w(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),je=k([ko,r()]),Io=k([f({target:u(J),equals:je}),f({target:u(J),before:je}),f({target:u(J),after:je}),f({target:u(J),on_or_before:je}),f({target:u(J),on_or_after:je}),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:s(!0)}),f({target:u(J),is_not_empty:s(!0)})]),Vr=k([f({propertyId:r(),relation:it}),f({propertyId:r(),created_by:yo}),f({propertyId:r(),title:Oe}),f({propertyId:r(),rich_text:Oe}),f({propertyId:r(),url:Oe}),f({propertyId:r(),email:Oe}),f({propertyId:r(),phone_number:Oe}),f({propertyId:r(),number:vo}),f({propertyId:r(),checkbox:ho}),f({propertyId:r(),select:Gr}),f({propertyId:r(),multi_select:So}),f({propertyId:r(),status:bo}),f({propertyId:r(),date:Io}),f({propertyId:r(),people:mo})]),_o=k([Vr,f({and:E(Vr)})]),at=10,xo=f({propertyId:r(),direction:Nr}),$r=n({type:s("queryDataSource"),subscriptionId:r(),dataSourceId:X,limit:C(),filter:u(_o),sorts:u(E(xo))});var Qr=n({type:s("resize"),height:H(C(),ke(),_e(0))});var Xr=n({type:s("unsubscribeDataSourceQuery"),subscriptionId:r()});var Wr=n({type:s("updatePage"),requestId:r(),pageId:T,dataSourceId:u(X),properties:u(Pe),icon:u(Ne),cover:u(Ue),archived:u(h())});var Jr=v("type",[wr,Tr,$r,Xr,qr,Nt,zt,Vt,Xt,$t,Wr,Qr,Ar]);function Kr(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}function Yr(e){let t=Kr(e);return t==="invalidHostMessage"||t==="invalidSandboxMessage"?{incomingType:t}:{incomingType:t,nack:{type:"invalidSandboxMessage",reason:Co(t)}}}function Co(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var Zr=n({initializationId:r()}),Po=n({bridgeProtocolVersion:k([C(),We()])});function en(e){let{iframe:t,sandboxOrigin:o,getInitStatus:i,emit:l,sendNack:c,onInvalidConnect:p,onInvalidInitResult:y,onConnect:m,onInitResult:_,onQueryDataSource:x,onUnsubscribeDataSourceQuery:P,onCreatePage:S,onGetPage:F,onOpenPage:G,onOpenExternalUrl:z,onGetUser:R,onListUsers:te,onUpdatePage:ne,onResize:K}=e;function ue($,M){l("warn",{message:"Ignored unsupported sandbox message",payload:ut($),issues:M});let L=Yr($);if(L.incomingType==="connect"){let Y=Ce(Zr,$),se=Ce(Po,$);if(p({initializationId:Y.success?Y.output.initializationId:void 0,error:vr(),bridgeProtocolVersion:se.success?se.output.bridgeProtocolVersion:void 0})==="handled")return}if(L.incomingType==="initResult"){let Y=Ce(Zr,$);y({initializationId:Y.success?Y.output.initializationId:void 0,error:kr()})}L.nack!==void 0&&i()!=="stopped"&&c(L.nack)}return function(M){let L=M.source===t.contentWindow,Y=M.origin===o;if(!L||!Y)return;let se=Ce(Jr,M.data);if(!se.success){ue(M.data,se.issues);return}let B=se.output;if(!Mr(B)&&i()!=="initialized"){l("warn",{message:`Ignored ${B.type} before initialization completed`,payload:ut(B)});return}switch(l("in",ut(B)),B.type){case"connect":m(B);return;case"initResult":_(B);return;case"queryDataSource":x(B);return;case"unsubscribeDataSourceQuery":P(B);return;case"createPage":S(B);return;case"openPage":G(B);return;case"openExternalUrl":z(B);return;case"getPage":F(B);return;case"getUser":R(B);return;case"listUsers":te(B);return;case"updatePage":ne(B);return;case"resize":K(B);return;case"invalidHostMessage":return;default:ee(B)}}}function ut(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}var ze=class{constructor(t){this.onUnsubscribe=t}onUnsubscribe;bySubscriptionId=new Map;subscribe(t){this.unsubscribe(t.subscriptionId);let o={_tag:"QuerySubscriptionToken"};return this.bySubscriptionId.set(t.subscriptionId,{message:t,token:o,isRefreshing:!0,shouldRefreshAgain:!1}),o}isCurrent(t,o){return this.bySubscriptionId.get(t)?.token===o}unsubscribe(t){this.bySubscriptionId.delete(t)&&this.onUnsubscribe(t)}refresh(t){let o=[],i=!1;for(let l of this.bySubscriptionId.values())if(l.message.dataSourceId===t){if(i=!0,l.isRefreshing){l.shouldRefreshAgain=!0;continue}l.isRefreshing=!0,o.push({message:l.message,token:l.token})}return i?o:void 0}finish(t,o){let i=this.bySubscriptionId.get(t);if(i?.token===o&&(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 tn(e,t){if(e===void 0)return;let o="and"in e?e.and:[e];for(let i of o){let l=Eo(i,t);if(l!==void 0)return l}}function Eo(e,t){if(!Object.hasOwn(t.propertiesById,e.propertyId))return{code:"invalid_data_source_query_filter",message:`Data source query filter property ID "${e.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let o=t.propertiesById[e.propertyId],i=Object.keys(e).find(y=>y!=="propertyId");if(i!==o.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${i}" does not match property type "${o.type}".`,isRetryable:!1};if("status"in e&&o.type==="status"){let y=e.status;if("group_equals"in y||"group_does_not_equal"in y){let m="group_equals"in y?y.group_equals:y.group_does_not_equal,x=(Array.isArray(m)?m:[m]).find(P=>!o.groups.some(S=>S.name===P));return x===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${x}".`,isRetryable:!1}}}if("relation"in e&&!ht(it,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let l=Oo(e);if(l===void 0||o.type!==l.propertyType)return;let c=new Set(o.options.map(y=>y.name)),p=jo(l.operator).find(y=>!c.has(y));if(p!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${p}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function Oo(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 jo(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 Ro=new Set(It);function rn(e,t){if(e===void 0)return;if(e.length>at)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${at} entries.`,isRetryable:!1};let o=new Set;for(let i of e){if(o.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(o.add(i.propertyId),!Object.hasOwn(t.propertiesById,i.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${i.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let l=t.propertiesById[i.propertyId];if(!Ro.has(l.type))return{code:"invalid_data_source_query_sort",message:`Data source query sorts do not yet support property type "${l.type}".`,isRetryable:!1}}}var on=5;function Mo(e){let{iframe:t,prepareInitialState:o,handlers:i,onInitialized:l,onConnectionFailure:c,onLog:p,onQueryUnsubscribed:y,sandboxOrigin:m,minBridgeProtocolVersion:_,noConnectTimeoutMs:x,initialStateTimeoutMs:P,noInitResultTimeoutMs:S}=e,F=Math.max(_??3,3),G=new AbortController,z,R={},te=!1,ne=new AbortController,K,ue,$=6,M=new ze(a=>{y?.(a)});function L(a,b){p?.(a,b)}function Y(a){let b=q.status;switch(b){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"error":break;case"stopped":return;default:return ee(b)}let O=Or(a,$);L("out",O),t.contentWindow?.postMessage(O,m)}function se(a){Y(ie(Fe,a))}function B(a){Y(a)}function Z(a){let b=q.status;switch(b){case"initialized":Y(ie(mr,a));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"error":case"stopped":return;default:ee(b)}}async function fe(a,b){if(b===void 0)return;let O=await b(a);Z({type:`${a.type}Result`,requestId:a.requestId,...O})}function Be(a){let b=a.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"error",error:a.response.error}:{type:"queryDataSourceResult",subscriptionId:a.subscriptionId,status:"success",items:a.response.items,hasMore:a.response.hasMore};Z(b)}async function g(a,b=M.subscribe(a)){try{let O=Bo(ue,a.dataSourceId),ve=Do(a,O);if(ve!==void 0){M.isCurrent(a.subscriptionId,b)&&(M.unsubscribe(a.subscriptionId),Be({subscriptionId:a.subscriptionId,response:{status:"error",error:ve}}));return}let Le=await i.queryDataSource(a);if(!M.isCurrent(a.subscriptionId,b))return;Le.status==="error"&&!Le.error.isRetryable&&M.unsubscribe(a.subscriptionId),Be({subscriptionId:a.subscriptionId,response:Le})}finally{let O=M.finish(a.subscriptionId,b);O!==void 0&&g(O.message,O.token)}}function I(a){q.status==="stopped"||q.status==="error"||(Object.assign(R,a),oe())}async function Q(a){if(i.openExternalUrl===void 0||G.signal.aborted||z===a.requestId)return;if(z!==void 0){let O={type:"openExternalUrlResult",requestId:a.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};Z(O);return}let b=Rr(a.url);if(b===void 0){let O={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}};Z(O);return}z=a.requestId;try{let O=await i.openExternalUrl({...a,url:b},{signal:G.signal});if(G.signal.aborted)return;let ve={type:"openExternalUrlResult",requestId:a.requestId,...O};Z(ve)}catch(O){if(!G.signal.aborted)throw O}finally{z===a.requestId&&(z=void 0)}}function oe(){if(q.status!=="initialized")return;let a=R;R={},a.theme!==void 0&&Z({type:"themeChanged",theme:a.theme}),a.contrastMode!==void 0&&Z({type:"contrastModeChanged",contrastMode:a.contrastMode}),a.parent!==void 0&&Z({type:"parentChanged",parent:a.parent}),a.page!==void 0&&Z({type:"pageChanged",page:a.page}),a.dataSources!==void 0&&Z({type:"dataSourcesChanged",dataSources:a.dataSources}),a.currentUser!==void 0&&Z({type:"currentUserChanged",currentUser:a.currentUser})}let q=Ir({async prepareInit(a){$=a.bridgeProtocolVersion;let b=await un;return q.status!=="preparingInit"?b:an(b)},sendInitMessage:se,warn:a=>L("warn",a),flushPendingHostStateChanges:oe,minBridgeProtocolVersion:F,noConnectTimeoutMs:x,initialStateTimeoutMs:P,noInitResultTimeoutMs:S,stopHostWithFailure:pt,onInitResult(a){a.status==="success"&&K!==void 0&&l?.({manifest:K,initialHeight:a.initialHeight})},onConnectionFailure:a=>{ne.abort(),c?.(a)}});function an(a){if(a.status==="error")return a;let b=ie(jr,{...a.initialState,...R});if(K=b.manifest,R={},$<on&&b.page.type==="unavailable")return{status:"error",error:rt()};let O=sn(b.manifest,b.dataSources);return O!==void 0?{status:"error",error:O}:(ue=b.dataSources,te=!0,{status:"success",initialState:b})}let un=cn().catch(a=>(ne.signal.aborted||L("warn",{message:"Failed to prepare custom block initialization",error:a}),{status:"error",error:Ee()}));async function cn(){let a=await _r({...e,sandboxOrigin:m,signal:ne.signal,onError:O=>{L("warn",{message:"Failed to load custom block manifest",error:O})}});if(a.status==="error")return a;if(ne.signal.aborted)return{status:"error",error:Ee()};let b=await o({manifest:a.manifest,signal:ne.signal});return b.status==="error"?b:{status:"success",initialState:{...b.initialState,manifest:a.manifest}}}let ct=en({iframe:t,sandboxOrigin:m,getInitStatus:()=>q.status,emit:L,sendNack:B,onInvalidConnect:q.handleInvalidConnect,onInvalidInitResult:q.handleInvalidInitResult,onConnect:q.handleConnect,onInitResult:q.handleInitResult,onQueryDataSource:g,onUnsubscribeDataSourceQuery:a=>M.unsubscribe(a.subscriptionId),onOpenExternalUrl:Q,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",ct),t.addEventListener("load",q.onIframeLoad);function lt(){G.abort(),ne.abort(),window.removeEventListener("message",ct),t.removeEventListener("load",q.onIframeLoad),q.stop(),M.unsubscribeAll()}function pt(a){lt(),L("warn",a),c?.(a)}return{stop:lt,setTheme(a){I({theme:a})},setContrastMode(a){I({contrastMode:a})},setParent(a){I({parent:a})},setPage(a){if(a.type==="unavailable"&&$<on&&(q.status==="preparingInit"&&te||q.status==="waitingForInitResult"||q.status==="initialized")){pt({...rt(),phase:"runtime",source:"host"});return}I({page:a})},setCurrentUser(a){I({currentUser:a})},setDataSources(a){let b={bindings:ie(me,a.bindings)};if(q.hasConnectedSandbox&&K!==void 0&&sn(K,b)!==void 0){L("warn",{message:"Ignored invalid data source bindings update",payload:b});return}ue=b,I({dataSources:b})},refreshQuery({dataSourceId:a}){if(q.status!=="initialized")return;let b=ie(X,a),O=M.refresh(b);if(O===void 0){L("warn",`No active query exists for data source "${a}"`);return}for(let ve of O)g(ve.message,ve.token)}}}function Bo(e,t){return Object.values(e?.bindings??{}).find(o=>o.collectionPointer?.id===t)?.collectionSchema}function sn(e,t){for(let[o,i]of Object.entries(e.dataSources)){let l=t.bindings[o];if(l?.collectionPointer===void 0||l.collectionSchema===void 0)return hr();for(let[c,p]of Object.entries(i.properties??{})){let y=l.propertyIdsByKey?.[c];if(y===void 0)return gr();if(l.collectionSchema.propertiesById[y]?.type!==p.type)return br()}}}function Do(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}:tn(e.filter,t)??rn(e.sorts,t)}function wo(e){return ie(T,e)}export{He as LATEST_BRIDGE_PROTOCOL_VERSION,Ve as LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION,Mo as createCustomBlockHost,ln as getAutoBoundPropertyIdsByKey,ot as isLocalCustomBlockUrl,wo as toNotionPageId};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { LegacyNotionDataSourcePageBridge
|
|
1
|
+
export type { LegacyNotionDataSourcePageBridge } from "./protocol/dataSources/dataSourcePage.js";
|
|
2
2
|
export type { NotionPropertySchemasById } from "./protocol/dataSources/propertySchema.js";
|
|
3
3
|
export type { CustomBlockErrorInfo } from "./protocol/errors.js";
|
|
4
4
|
export type { NotionPageId } from "./protocol/ids.js";
|
|
@@ -12,7 +12,7 @@ export type { OpenPageMessage } from "./protocol/messages/openPage.js";
|
|
|
12
12
|
export type { CustomBlockCheckboxFilterOperator, CustomBlockContainsFilterOperator, CustomBlockCreatedByFilterOperator, CustomBlockDateFilterOperator, CustomBlockNumberFilterOperator, CustomBlockOptionFilterOperator, CustomBlockPeopleFilterOperator, CustomBlockPersonFilterValue, CustomBlockRelationFilterOperator, CustomBlockStatusFilterOperator, CustomBlockStatusGroupFilterOperator, CustomBlockStatusGroupName, CustomBlockTextFilterOperator, QueryDataSourceMessage, ResolvedCustomBlockDataSourceFilter, ResolvedCustomBlockDataSourcePropertyFilter, ResolvedCustomBlockDataSourceSort, } from "./protocol/messages/queryDataSource.js";
|
|
13
13
|
export type { ResizeMessage } from "./protocol/messages/resize.js";
|
|
14
14
|
export type { UpdatePageMessage } from "./protocol/messages/updatePage.js";
|
|
15
|
-
export type { NotionDateInput, NotionFileInput, NotionPageCover, NotionPageIcon, NotionPagePropertyReadMap, NotionPagePropertyValue, NotionPagePropertyWriteMap, NotionRichTextItem, NotionSelectOptionInput, } from "./protocol/pages/page.js";
|
|
15
|
+
export type { NotionDateInput, NotionFileInput, NotionPageCover, NotionPageData, NotionPageIcon, NotionPagePropertyReadMap, NotionPagePropertyValue, NotionPagePropertyWriteMap, NotionRichTextItem, NotionSelectOptionInput, } from "./protocol/pages/page.js";
|
|
16
16
|
export { LATEST_BRIDGE_PROTOCOL_VERSION, LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION, } from "./protocol/protocolVersion.js";
|
|
17
17
|
export { type AutoBindableProperty, getAutoBoundPropertyIdsByKey, } from "./autoBindProperties.js";
|
|
18
18
|
export { type CustomBlockHostHandle, type CustomBlockHostOptions, createCustomBlockHost, } from "./createCustomBlockHost.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gCAAgC,EAAE,MAAM,gEAAgE,CAAA;AACtH,YAAY,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAA;AAC/G,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAA;AAC1F,YAAY,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAA;AAC9F,YAAY,EAAE,sBAAsB,EAAE,MAAM,8DAA8D,CAAA;AAC1G,YAAY,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,YAAY,EACX,iCAAiC,EACjC,iCAAiC,EACjC,kCAAkC,EAClC,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,EAC5B,iCAAiC,EACjC,+BAA+B,EAC/B,oCAAoC,EACpC,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,mCAAmC,EACnC,2CAA2C,EAC3C,iCAAiC,GACjC,MAAM,8DAA8D,CAAA;AACrE,YAAY,EAAE,aAAa,EAAE,MAAM,qDAAqD,CAAA;AACxF,YAAY,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAA;AAChG,YAAY,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,gDAAgD,CAAA;AACvD,OAAO,EACN,8BAA8B,EAC9B,sCAAsC,GACtC,MAAM,qDAAqD,CAAA;AAC5D,OAAO,EACN,KAAK,oBAAoB,EACzB,4BAA4B,GAC5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,qBAAqB,GACrB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,YAAY,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAA;AACpF,YAAY,EACX,qBAAqB,EACrB,iCAAiC,EACjC,2BAA2B,EAC3B,iCAAiC,EACjC,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EACX,sBAAsB,EACtB,+BAA+B,EAC/B,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,8BAA8B,EAC9B,2BAA2B,EAC3B,gCAAgC,EAChC,oCAAoC,EACpC,6BAA6B,EAC7B,+BAA+B,EAC/B,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,EAC3B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { LegacyNotionPage, notionPageDataSchema } from "../protocol/pages/page.js";
|
|
2
|
+
import type { InferOutput } from "valibot";
|
|
3
|
+
export declare function toLegacyPage(page: InferOutput<typeof notionPageDataSchema>): LegacyNotionPage;
|
|
4
|
+
export declare function toLegacyQueryPage(page: InferOutput<typeof notionPageDataSchema>): {
|
|
5
|
+
id: string & import("valibot").Brand<"NotionPageId">;
|
|
6
|
+
is_archived: boolean;
|
|
7
|
+
in_trash: boolean;
|
|
8
|
+
propertiesById: Record<string, string | number | boolean | string[] | {
|
|
9
|
+
id: string;
|
|
10
|
+
table: string;
|
|
11
|
+
}[] | {
|
|
12
|
+
type: "date";
|
|
13
|
+
start_date: string;
|
|
14
|
+
reminder?: {
|
|
15
|
+
unit: "day" | "month" | "week" | "year";
|
|
16
|
+
value: number;
|
|
17
|
+
time: string;
|
|
18
|
+
defaultTimeZone?: string | undefined;
|
|
19
|
+
} | {
|
|
20
|
+
unit: "none";
|
|
21
|
+
} | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
type: "daterange";
|
|
24
|
+
start_date: string;
|
|
25
|
+
end_date: string;
|
|
26
|
+
reminder?: {
|
|
27
|
+
unit: "day" | "month" | "week" | "year";
|
|
28
|
+
value: number;
|
|
29
|
+
time: string;
|
|
30
|
+
defaultTimeZone?: string | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
unit: "none";
|
|
33
|
+
} | undefined;
|
|
34
|
+
} | {
|
|
35
|
+
type: "datetime";
|
|
36
|
+
start_date: string;
|
|
37
|
+
start_time: string;
|
|
38
|
+
time_zone?: string | undefined;
|
|
39
|
+
reminder?: {
|
|
40
|
+
unit: "day" | "month" | "week" | "year";
|
|
41
|
+
value: number;
|
|
42
|
+
time: string;
|
|
43
|
+
defaultTimeZone?: string | undefined;
|
|
44
|
+
} | {
|
|
45
|
+
unit: "hour" | "minute";
|
|
46
|
+
value: number;
|
|
47
|
+
} | {
|
|
48
|
+
unit: "none";
|
|
49
|
+
} | undefined;
|
|
50
|
+
} | {
|
|
51
|
+
type: "datetimerange";
|
|
52
|
+
start_date: string;
|
|
53
|
+
start_time: string;
|
|
54
|
+
end_date: string;
|
|
55
|
+
end_time: string;
|
|
56
|
+
time_zone?: string | undefined;
|
|
57
|
+
reminder?: {
|
|
58
|
+
unit: "day" | "month" | "week" | "year";
|
|
59
|
+
value: number;
|
|
60
|
+
time: string;
|
|
61
|
+
defaultTimeZone?: string | undefined;
|
|
62
|
+
} | {
|
|
63
|
+
unit: "hour" | "minute";
|
|
64
|
+
value: number;
|
|
65
|
+
} | {
|
|
66
|
+
unit: "none";
|
|
67
|
+
} | undefined;
|
|
68
|
+
} | undefined>;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=legacyPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacyPage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/legacyPage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAEhB,oBAAoB,EACpB,MAAM,gDAAgD,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C,wBAAgB,YAAY,CAC3B,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,GAC5C,gBAAgB,CAelB;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAc9C"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { unreachable } from "../utils.js";
|
|
2
|
+
export function toLegacyPage(page) {
|
|
3
|
+
return {
|
|
4
|
+
...page,
|
|
5
|
+
properties: Object.fromEntries(Object.values(page.properties).flatMap(property => property ? [[property.id, property]] : [])),
|
|
6
|
+
icon: page.icon ?? undefined,
|
|
7
|
+
cover: page.cover ?? undefined,
|
|
8
|
+
created_time: page.created_time ?? undefined,
|
|
9
|
+
last_edited_time: page.last_edited_time ?? undefined,
|
|
10
|
+
url: page.url ?? undefined,
|
|
11
|
+
public_url: page.public_url ?? undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function toLegacyQueryPage(page) {
|
|
15
|
+
const propertiesById = {};
|
|
16
|
+
for (const property of Object.values(page.properties)) {
|
|
17
|
+
if (property) {
|
|
18
|
+
propertiesById[property.id] = toLegacyProperty(property);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
id: page.id,
|
|
23
|
+
is_archived: page.is_archived,
|
|
24
|
+
in_trash: page.in_trash,
|
|
25
|
+
propertiesById,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function plainText(items) {
|
|
29
|
+
return items
|
|
30
|
+
.map(item => {
|
|
31
|
+
if (typeof item.plain_text === "string") {
|
|
32
|
+
return item.plain_text;
|
|
33
|
+
}
|
|
34
|
+
const text = item.text;
|
|
35
|
+
return text &&
|
|
36
|
+
typeof text === "object" &&
|
|
37
|
+
"content" in text &&
|
|
38
|
+
typeof text.content === "string"
|
|
39
|
+
? text.content
|
|
40
|
+
: "";
|
|
41
|
+
})
|
|
42
|
+
.join("");
|
|
43
|
+
}
|
|
44
|
+
function timestamp(value) {
|
|
45
|
+
if (value === undefined || value === null || value === "") {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const date = new Date(value);
|
|
49
|
+
if (!Number.isFinite(date.getTime())) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
type: "datetime",
|
|
54
|
+
start_date: date.toISOString().slice(0, 10),
|
|
55
|
+
start_time: date.toISOString().slice(11, 16),
|
|
56
|
+
time_zone: "UTC",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function legacyDate(value) {
|
|
60
|
+
const timed = value.start.includes("T") || value.time_zone != null;
|
|
61
|
+
const offset = value.start.match(/([+-])(\d{2}):(\d{2})$/);
|
|
62
|
+
const offsetMinutes = offset
|
|
63
|
+
? (Number(offset[2]) * 60 + Number(offset[3])) *
|
|
64
|
+
(offset[1] === "-" ? -1 : 1)
|
|
65
|
+
: 0;
|
|
66
|
+
const parts = (input) => {
|
|
67
|
+
if (!input.includes("T")) {
|
|
68
|
+
return { date: input, time: "00:00" };
|
|
69
|
+
}
|
|
70
|
+
const wallClock = input.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);
|
|
71
|
+
if (wallClock) {
|
|
72
|
+
return { date: wallClock[1], time: wallClock[2] };
|
|
73
|
+
}
|
|
74
|
+
if (!value.time_zone) {
|
|
75
|
+
const local = new Date(new Date(input).getTime() + offsetMinutes * 60_000).toISOString();
|
|
76
|
+
return { date: local.slice(0, 10), time: local.slice(11, 16) };
|
|
77
|
+
}
|
|
78
|
+
const entries = new Intl.DateTimeFormat("en-CA", {
|
|
79
|
+
timeZone: value.time_zone,
|
|
80
|
+
year: "numeric",
|
|
81
|
+
month: "2-digit",
|
|
82
|
+
day: "2-digit",
|
|
83
|
+
hour: "2-digit",
|
|
84
|
+
minute: "2-digit",
|
|
85
|
+
hourCycle: "h23",
|
|
86
|
+
}).formatToParts(new Date(input));
|
|
87
|
+
const get = (type) => entries.find(part => part.type === type)?.value;
|
|
88
|
+
return {
|
|
89
|
+
date: `${get("year")}-${get("month")}-${get("day")}`,
|
|
90
|
+
time: `${get("hour")}:${get("minute")}`,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const start = parts(value.start);
|
|
94
|
+
const end = value.end ? parts(value.end) : undefined;
|
|
95
|
+
if (!timed) {
|
|
96
|
+
return end
|
|
97
|
+
? { type: "daterange", start_date: start.date, end_date: end.date }
|
|
98
|
+
: { type: "date", start_date: start.date };
|
|
99
|
+
}
|
|
100
|
+
const zone = value.time_zone ??
|
|
101
|
+
(offsetMinutes === 0
|
|
102
|
+
? "UTC"
|
|
103
|
+
: `UTC${offsetMinutes < 0 ? "-" : "+"}${Math.floor(Math.abs(offsetMinutes) / 60)}${Math.abs(offsetMinutes) % 60 === 0 ? "" : `:${String(Math.abs(offsetMinutes) % 60).padStart(2, "0")}`}`);
|
|
104
|
+
return end
|
|
105
|
+
? {
|
|
106
|
+
type: "datetimerange",
|
|
107
|
+
start_date: start.date,
|
|
108
|
+
start_time: start.time,
|
|
109
|
+
end_date: end.date,
|
|
110
|
+
end_time: end.time,
|
|
111
|
+
time_zone: zone,
|
|
112
|
+
}
|
|
113
|
+
: {
|
|
114
|
+
type: "datetime",
|
|
115
|
+
start_date: start.date,
|
|
116
|
+
start_time: start.time,
|
|
117
|
+
time_zone: zone,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function toLegacyProperty(property) {
|
|
121
|
+
switch (property.type) {
|
|
122
|
+
case "title":
|
|
123
|
+
return plainText(property.title);
|
|
124
|
+
case "rich_text":
|
|
125
|
+
return plainText(property.rich_text);
|
|
126
|
+
case "number":
|
|
127
|
+
return property.number ?? undefined;
|
|
128
|
+
case "checkbox":
|
|
129
|
+
return property.checkbox;
|
|
130
|
+
case "url":
|
|
131
|
+
return property.url ?? "";
|
|
132
|
+
case "email":
|
|
133
|
+
return property.email ?? "";
|
|
134
|
+
case "phone_number":
|
|
135
|
+
return property.phone_number ?? "";
|
|
136
|
+
case "select":
|
|
137
|
+
return property.select?.name;
|
|
138
|
+
case "status":
|
|
139
|
+
return property.status?.name;
|
|
140
|
+
case "multi_select":
|
|
141
|
+
return property.multi_select.flatMap(option => option.name ?? []);
|
|
142
|
+
case "date":
|
|
143
|
+
return property.date ? legacyDate(property.date) : undefined;
|
|
144
|
+
case "people":
|
|
145
|
+
return property.people.map(person => person.object === "group"
|
|
146
|
+
? {
|
|
147
|
+
id: person.id,
|
|
148
|
+
table: "space_permission_group",
|
|
149
|
+
spaceId: person.id.split("|")[1],
|
|
150
|
+
}
|
|
151
|
+
: { id: person.id, table: "notion_user" });
|
|
152
|
+
case "relation":
|
|
153
|
+
return property.relation.map(page => ({ id: page.id, table: "block" }));
|
|
154
|
+
case "files":
|
|
155
|
+
return property.files.map(file => file.name).join(",");
|
|
156
|
+
case "place":
|
|
157
|
+
return "";
|
|
158
|
+
case "created_time":
|
|
159
|
+
return timestamp(property.created_time);
|
|
160
|
+
case "last_edited_time":
|
|
161
|
+
return timestamp(property.last_edited_time);
|
|
162
|
+
case "last_visited_time":
|
|
163
|
+
return timestamp(property.last_visited_time);
|
|
164
|
+
case "created_by":
|
|
165
|
+
return property.created_by ? [property.created_by] : undefined;
|
|
166
|
+
case "last_edited_by":
|
|
167
|
+
return property.last_edited_by ? [property.last_edited_by] : undefined;
|
|
168
|
+
default:
|
|
169
|
+
return unreachable(property);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HostToSandboxMessage } from "../protocol/messages/hostToSandbox.js";
|
|
1
|
+
import type { HostToSandboxMessage, HostToSandboxMessageLegacy } from "../protocol/messages/hostToSandbox.js";
|
|
2
2
|
/**
|
|
3
3
|
* Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
|
|
4
4
|
*/
|
|
5
|
-
export declare function normalizeHostToSandboxMessage(message: HostToSandboxMessage, bridgeProtocolVersion: number):
|
|
5
|
+
export declare function normalizeHostToSandboxMessage(message: HostToSandboxMessage, bridgeProtocolVersion: number): HostToSandboxMessageLegacy;
|
|
6
6
|
//# sourceMappingURL=normalizeHostToSandboxMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,MAAM,4DAA4D,CAAA;AAGnE;;GAEG;AAGH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CAc5B"}
|
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeToLegacyPage } from "./normalizePage.js";
|
|
2
2
|
/**
|
|
3
3
|
* Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
|
|
4
4
|
*/
|
|
5
5
|
// TODO(custom-blocks): Remove this function when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION
|
|
6
|
-
// reaches
|
|
6
|
+
// reaches 6.
|
|
7
7
|
export function normalizeHostToSandboxMessage(message, bridgeProtocolVersion) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if (message.type !== "queryDataSourceResult" &&
|
|
9
|
+
message.type !== "getPageResult" &&
|
|
10
|
+
message.type !== "createPageResult" &&
|
|
11
|
+
message.type !== "updatePageResult") {
|
|
10
12
|
return message;
|
|
11
13
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (!containsDataSources) {
|
|
15
|
-
return message;
|
|
16
|
-
}
|
|
17
|
-
// Protocol 5 excludes synthetic IDs such as created_time from collectionSchema.propertiesById.
|
|
18
|
-
// Older SDKs derive read schemas from that map. Restore those entries in outgoing copies so
|
|
19
|
-
// host query validation still uses the actual database schema.
|
|
20
|
-
return {
|
|
21
|
-
...message,
|
|
22
|
-
dataSources: {
|
|
23
|
-
bindings: Object.fromEntries(Object.entries(message.dataSources.bindings).map(([key, binding]) => [
|
|
24
|
-
key,
|
|
25
|
-
{
|
|
26
|
-
...binding,
|
|
27
|
-
collectionSchema: {
|
|
28
|
-
...binding.collectionSchema,
|
|
29
|
-
propertiesById: {
|
|
30
|
-
...binding.collectionSchema?.propertiesById,
|
|
31
|
-
...NOTION_BUILTIN_PROPERTY_SCHEMAS,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
])),
|
|
36
|
-
},
|
|
37
|
-
};
|
|
14
|
+
const normalizedMessage = normalizeToLegacyPage(message, bridgeProtocolVersion);
|
|
15
|
+
return normalizedMessage;
|
|
38
16
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CreatePageResultMessage } from "../protocol/messages/createPageResult.js";
|
|
2
|
+
import type { GetPageResultMessage } from "../protocol/messages/getPage.js";
|
|
3
|
+
import type { HostToSandboxMessageLegacy } from "../protocol/messages/hostToSandbox.js";
|
|
4
|
+
import type { QueryDataSourceResultMessage } from "../protocol/messages/queryDataSourceResult.js";
|
|
5
|
+
import type { UpdatePageResultMessage } from "../protocol/messages/updatePageResult.js";
|
|
6
|
+
export declare function normalizeToLegacyPage(message: CreatePageResultMessage | GetPageResultMessage | UpdatePageResultMessage | QueryDataSourceResultMessage, bridgeProtocolVersion: number): HostToSandboxMessageLegacy;
|
|
7
|
+
//# sourceMappingURL=normalizePage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizePage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAA;AAC5G,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oEAAoE,CAAA;AACtH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAK5G,wBAAgB,qBAAqB,CACpC,OAAO,EACJ,uBAAuB,GACvB,oBAAoB,GACpB,uBAAuB,GACvB,4BAA4B,EAC/B,qBAAqB,EAAE,MAAM,GAC3B,0BAA0B,CAkB5B"}
|