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