@notionhq/custom-blocks-host 0.3.5 → 0.3.7

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