@notionhq/custom-blocks-host 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +9 -0
  2. package/dist/browser.js +1 -1
  3. package/dist/compatibility/normalizeHostToSandboxMessage.d.ts.map +1 -1
  4. package/dist/compatibility/normalizeHostToSandboxMessage.js +5 -1
  5. package/dist/compatibility/normalizeSandboxToHostMessage.d.ts +87 -1
  6. package/dist/compatibility/normalizeSandboxToHostMessage.d.ts.map +1 -1
  7. package/dist/compatibility/pages/toIconForProtocol3To8.d.ts +4 -0
  8. package/dist/compatibility/pages/toIconForProtocol3To8.d.ts.map +1 -0
  9. package/dist/compatibility/pages/toIconForProtocol3To8.js +13 -0
  10. package/dist/compatibility/protocol3To5/toPageForProtocol3To5.d.ts.map +1 -1
  11. package/dist/compatibility/protocol3To5/toPageForProtocol3To5.js +2 -1
  12. package/dist/compatibility/protocol3To5/toQueryPageForProtocol3To5.d.ts +8 -8
  13. package/dist/compatibility/protocol6/normalizePageResultsForProtocol6.d.ts.map +1 -1
  14. package/dist/compatibility/protocol6/normalizePageResultsForProtocol6.js +9 -2
  15. package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.d.ts +4 -0
  16. package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.d.ts.map +1 -0
  17. package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.js +16 -0
  18. package/dist/createCustomBlockHost.d.ts.map +1 -1
  19. package/dist/createCustomBlockHost.js +1 -0
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/messages/createSandboxMessageRouter.d.ts +3 -2
  23. package/dist/messages/createSandboxMessageRouter.d.ts.map +1 -1
  24. package/dist/messages/createSandboxMessageRouter.js +7 -1
  25. package/dist/messages/invalidNativeIconColor.d.ts +5 -0
  26. package/dist/messages/invalidNativeIconColor.d.ts.map +1 -0
  27. package/dist/messages/invalidNativeIconColor.js +34 -0
  28. package/dist/pages/types.d.ts +2 -0
  29. package/dist/pages/types.d.ts.map +1 -1
  30. package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +7 -1
  31. package/dist/protocol/dataSources/messages/queryDataSource.d.ts +14 -2
  32. package/dist/protocol/icons.d.ts +17 -0
  33. package/dist/protocol/icons.js +27 -0
  34. package/dist/protocol/index.d.ts +3 -2
  35. package/dist/protocol/index.js +3 -2
  36. package/dist/protocol/messages/hostToSandbox.d.ts +77 -11
  37. package/dist/protocol/messages/sandboxToHost.d.ts +87 -1
  38. package/dist/protocol/pages/bridgePage.d.ts +7 -1
  39. package/dist/protocol/pages/messages/createPage.d.ts +102 -4
  40. package/dist/protocol/pages/messages/createPage.js +3 -1
  41. package/dist/protocol/pages/messages/getPage.d.ts +21 -3
  42. package/dist/protocol/pages/messages/updatePage.d.ts +29 -5
  43. package/dist/protocol/pages/pageAppearance.d.ts +36 -1
  44. package/dist/protocol/pages/pageAppearance.js +9 -0
  45. package/dist/protocol/utils/protocolVersion.d.ts +2 -1
  46. package/dist/protocol/utils/protocolVersion.js +3 -1
  47. package/docs/bridge/changelog.md +12 -0
  48. package/docs/bridge/protocol.md +11 -0
  49. package/docs/bridge/versioning.md +1 -0
  50. package/docs/compatibility.md +15 -7
  51. package/package.json +1 -1
  52. package/src/compatibility/normalizeHostToSandboxMessage.ts +5 -0
  53. package/src/compatibility/pages/toIconForProtocol3To8.ts +17 -0
  54. package/src/compatibility/protocol3To5/toPageForProtocol3To5.ts +2 -1
  55. package/src/compatibility/protocol6/normalizePageResultsForProtocol6.ts +11 -2
  56. package/src/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.ts +22 -0
  57. package/src/createCustomBlockHost.ts +1 -0
  58. package/src/index.ts +1 -0
  59. package/src/messages/createSandboxMessageRouter.ts +18 -2
  60. package/src/messages/invalidNativeIconColor.ts +43 -0
  61. package/src/pages/types.ts +3 -0
package/README.md CHANGED
@@ -182,3 +182,12 @@ These schemas validate wire payloads. Your application still enforces permission
182
182
 
183
183
  `dist/browser.js` is one ES module with all dependencies. Use it when the browser must not fetch
184
184
  additional modules, such as under an exact-URL Content Security Policy.
185
+
186
+ ### Native page icons
187
+
188
+ `CustomBlockHostPageIcon` accepts canonical native icon names from adapters. Adapters validate names
189
+ and colors before writing. The runtime validates response payloads.
190
+
191
+ Adapters must check URL-backed icon and cover writes against the block's network permissions before
192
+ mutating records. Notion permits the submitted HTTPS destination only when its origin is
193
+ allowlisted; that origin is trusted to redirect.
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- var Le,Yo={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function st(e){return!e&&!Le?Yo:{lang:e?.lang??Le?.lang,message:e?.message,abortEarly:e?.abortEarly??Le?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Le?.abortPipeEarly}}var en;function tn(e){return en?.get(e)}var rn;function on(e){return rn?.get(e)}var nn;function sn(e,t){return nn?.get(e)?.get(t)}function _e(e){let t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function w(e,t,n,s,c){let p=c&&"input"in c?c.input:n.value,f=c?.expected??e.expects??null,h=c?.received??_e(p),y={kind:e.kind,type:e.type,input:p,expected:f,received:h,message:`Invalid ${t}: ${f?`Expected ${f} but r`:"R"}eceived ${h}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},x=e.kind==="schema",I=c?.message??e.message??sn(e.reference,y.lang)??(x?on(y.lang):null)??s.message??tn(y.lang);I!==void 0&&(y.message=typeof I=="function"?I(y):I),x&&(n.typed=!1),n.issues?n.issues.push(y):n.issues=[y]}function an(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function un(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function at(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}function W(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},st())},e}var cn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function pe(e){return{kind:"transformation",type:"brand",reference:pe,async:!1,name:e,"~run"(t){return t}}}function De(e){return{kind:"validation",type:"finite",reference:De,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,n){return t.typed&&!this.requirement(t.value)&&w(this,"finite",t,n),t}}}function ut(e,t){let n=_e(e);return{kind:"validation",type:"includes",reference:ut,async:!1,expects:n,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&w(this,"content",s,c,{received:`!${n}`}),s}}}function we(e,t){return{kind:"validation",type:"max_length",reference:we,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(n,s){return n.typed&&n.value.length>this.requirement&&w(this,"length",n,s,{received:`${n.value.length}`}),n}}}function ge(e,t){return{kind:"validation",type:"min_length",reference:ge,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(n,s){return n.typed&&n.value.length<this.requirement&&w(this,"length",n,s,{received:`${n.value.length}`}),n}}}function Te(e,t){return{kind:"validation",type:"min_value",reference:Te,async:!1,expects:`>=${e instanceof Date?e.toJSON():_e(e)}`,requirement:e,message:t,"~run"(n,s){return n.typed&&!(n.value>=this.requirement)&&w(this,"value",n,s,{received:n.value instanceof Date?n.value.toJSON():_e(n.value)}),n}}}function ct(e,t){return{kind:"validation",type:"regex",reference:ct,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(n,s){return n.typed&&!this.requirement.test(n.value)&&w(this,"format",n,s),n}}}function lt(e){return{kind:"transformation",type:"transform",reference:lt,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var Dt={abortEarly:!0};function wt(e,t,n){return typeof e.fallback=="function"?e.fallback(t,n):e.fallback}function Ve(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function Tt(e,t){return!e["~run"]({value:t},Dt).issues}function E(e,t){return W({kind:"schema",type:"array",reference:E,expects:"Array",async:!1,item:e,message:t,"~run"(n,s){let c=n.value;if(Array.isArray(c)){n.typed=!0,n.value=[];for(let p=0;p<c.length;p++){let f=c[p],h=this.item["~run"]({value:f},s);if(h.issues){let y={type:"array",origin:"value",input:c,key:p,value:f};for(let x of h.issues)x.path?x.path.unshift(y):x.path=[y],n.issues?.push(x);if(n.issues||(n.issues=h.issues),s.abortEarly){n.typed=!1;break}}h.typed||(n.typed=!1),n.value.push(h.value)}}else w(this,"type",n,s);return n}})}function g(e){return W({kind:"schema",type:"boolean",reference:g,expects:"boolean",async:!1,message:e,"~run"(t,n){return typeof t.value=="boolean"?t.typed=!0:w(this,"type",t,n),t}})}function i(e,t){return W({kind:"schema",type:"literal",reference:i,expects:_e(e),async:!1,literal:e,message:t,"~run"(n,s){return an(n.value,this.literal)?n.typed=!0:w(this,"type",n,s),n}})}function pt(e){return W({kind:"schema",type:"nan",reference:pt,expects:"NaN",async:!1,message:e,"~run"(t,n){return Number.isNaN(t.value)?t.typed=!0:w(this,"type",t,n),t}})}function mt(e){return W({kind:"schema",type:"never",reference:mt,expects:"never",async:!1,message:e,"~run"(t,n){return w(this,"type",t,n),t}})}function D(e,t){return W({kind:"schema",type:"nullable",reference:D,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(n,s){return n.value===null&&(this.default!==void 0&&(n.value=Ve(this,n,s)),n.value===null)?(n.typed=!0,n):this.wrapped["~run"](n,s)}})}function O(e){return W({kind:"schema",type:"number",reference:O,expects:"number",async:!1,message:e,"~run"(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:w(this,"type",t,n),t}})}function o(e,t){return W({kind:"schema",type:"object",reference:o,expects:"Object",async:!1,entries:e,message:t,"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.value={};for(let p in this.entries){let f=this.entries[p];if(p in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let h=p in c?c[p]:Ve(f),y=f["~run"]({value:h},s);if(y.issues){let x={type:"object",origin:"value",input:c,key:p,value:h};for(let I of y.issues)I.path?I.path.unshift(x):I.path=[x],n.issues?.push(I);if(n.issues||(n.issues=y.issues),s.abortEarly){n.typed=!1;break}}y.typed||(n.typed=!1),n.value[p]=y.value}else if(f.fallback!==void 0)n.value[p]=wt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(w(this,"key",n,s,{input:void 0,expected:`"${p}"`,path:[{type:"object",origin:"key",input:c,key:p,value:c[p]}]}),s.abortEarly))break}}else w(this,"type",n,s);return n}})}function a(e,t){return W({kind:"schema",type:"optional",reference:a,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(n,s){return n.value===void 0&&(this.default!==void 0&&(n.value=Ve(this,n,s)),n.value===void 0)?(n.typed=!0,n):this.wrapped["~run"](n,s)}})}function T(e,t){return W({kind:"schema",type:"picklist",reference:T,expects:at(e.map(_e),"|"),async:!1,options:e,message:t,"~run"(n,s){return this.options.includes(n.value)?n.typed=!0:w(this,"type",n,s),n}})}function Q(e,t,n){return W({kind:"schema",type:"record",reference:Q,expects:"Object",async:!1,key:e,value:t,message:n,"~run"(s,c){let p=s.value;if(p&&typeof p=="object"){s.typed=!0,s.value={};for(let f in p)if(un(p,f)){let h=p[f],y=this.key["~run"]({value:f},c);if(y.issues){let I={type:"object",origin:"key",input:p,key:f,value:h};for(let M of y.issues)M.path=[I],s.issues?.push(M);if(s.issues||(s.issues=y.issues),c.abortEarly){s.typed=!1;break}}let x=this.value["~run"]({value:h},c);if(x.issues){let I={type:"object",origin:"value",input:p,key:f,value:h};for(let M of x.issues)M.path?M.path.unshift(I):M.path=[I],s.issues?.push(M);if(s.issues||(s.issues=x.issues),c.abortEarly){s.typed=!1;break}}(!y.typed||!x.typed)&&(s.typed=!1),y.typed&&(s.value[y.value]=x.value)}}else w(this,"type",s,c);return s}})}function l(e,t){return W({kind:"schema",type:"strict_object",reference:l,expects:"Object",async:!1,entries:e,message:t,"~run"(n,s){let c=n.value;if(c&&typeof c=="object"){n.typed=!0,n.value={};for(let p in this.entries){let f=this.entries[p];if(p in c||(f.type==="exact_optional"||f.type==="optional"||f.type==="nullish")&&f.default!==void 0){let h=p in c?c[p]:Ve(f),y=f["~run"]({value:h},s);if(y.issues){let x={type:"object",origin:"value",input:c,key:p,value:h};for(let I of y.issues)I.path?I.path.unshift(x):I.path=[x],n.issues?.push(I);if(n.issues||(n.issues=y.issues),s.abortEarly){n.typed=!1;break}}y.typed||(n.typed=!1),n.value[p]=y.value}else if(f.fallback!==void 0)n.value[p]=wt(f);else if(f.type!=="exact_optional"&&f.type!=="optional"&&f.type!=="nullish"&&(w(this,"key",n,s,{input:void 0,expected:`"${p}"`,path:[{type:"object",origin:"key",input:c,key:p,value:c[p]}]}),s.abortEarly))break}if(!n.issues||!s.abortEarly){for(let p in c)if(!Object.prototype.hasOwnProperty.call(this.entries,p)){w(this,"key",n,s,{input:p,expected:"never",path:[{type:"object",origin:"key",input:c,key:p,value:c[p]}]});break}}}else w(this,"type",n,s);return n}})}function r(e){return W({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,n){return typeof t.value=="string"?t.typed=!0:w(this,"type",t,n),t}})}function Mt(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function d(e,t){return W({kind:"schema",type:"union",reference:d,expects:at(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,"~run"(n,s){let c,p,f;for(let h of this.options){let y=h["~run"]({value:n.value},s);if(y.typed)if(y.issues)p?p.push(y):p=[y];else{c=y;break}else f?f.push(y):f=[y]}if(c)return c;if(p){if(p.length===1)return p[0];w(this,"type",n,s,{issues:Mt(p)}),n.typed=!0}else{if(f?.length===1)return f[0];w(this,"type",n,s,{issues:Mt(f)})}return n}})}function qe(){return W({kind:"schema",type:"unknown",reference:qe,expects:"unknown",async:!1,"~run"(e){return e.typed=!0,e}})}function v(e,t,n){return W({kind:"schema",type:"variant",reference:v,expects:"Object",async:!1,key:e,options:t,message:n,"~run"(s,c){let p=s.value;if(p&&typeof p=="object"){let f,h=0,y=this.key,x=[],I=(M,X)=>{for(let V of M.options){if(V.type==="variant")I(V,new Set(X).add(V.key));else{let b=!0,N=0;for(let B of X){let z=V.entries[B];if(B in p?z["~run"]({typed:!1,value:p[B]},Dt).issues:z.type!=="exact_optional"&&z.type!=="optional"&&z.type!=="nullish"){b=!1,y!==B&&(h<N||h===N&&B in p&&!(y in p))&&(h=N,y=B,x=[]),y===B&&x.push(V.entries[B].expects);break}N++}if(b){let B=V["~run"]({value:p},c);(!f||!f.typed&&B.typed)&&(f=B)}}if(f&&!f.issues)break}};if(I(this,new Set([this.key])),f)return f;w(this,"type",s,c,{input:p[y],expected:at(x,"|"),path:[{type:"object",origin:"value",input:p,key:y,value:p[y]}]})}else w(this,"type",s,c);return s}})}function qt(e,t){let n={...e.entries};for(let s of t)delete n[s];return W({...e,entries:n})}function ae(e,t,n){let s=e["~run"]({value:t},st(n));if(s.issues)throw new cn(s.issues);return s.value}function A(...e){return W({...e[0],pipe:e,"~run"(t,n){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=s["~run"](t,n))}return t}})}function de(e,t,n){let s=e["~run"]({value:t},st(n));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var me=A(r(),pe("NotionBlockId")),Z=A(r(),pe("NotionDataSourceId")),F=A(r(),pe("NotionPageId")),At=A(r(),pe("NotionAgentId")),Nt=A(r(),pe("NotionSpaceId"));var Ut=o({id:Z,table:r(),spaceId:a(Nt)});var Ft=T(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),ft=o({id:r(),name:r(),color:a(Ft),description:a(r())}),ln=o({id:r(),name:r(),color:a(Ft),option_ids:E(r())}),pn=o({synced_property_id:r(),synced_property_name:r()}),R=o({name:r(),description:a(r())}),mn=["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"],zt=T(mn),Ht=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Lt=v("type",[o({...R.entries,type:i("title")}),o({...R.entries,type:i("rich_text")}),o({...R.entries,type:i("number")}),o({...R.entries,type:i("checkbox")}),o({...R.entries,type:i("url")}),o({...R.entries,type:i("email")}),o({...R.entries,type:i("phone_number")}),o({...R.entries,type:i("select"),options:E(ft)}),o({...R.entries,type:i("multi_select"),options:E(ft)}),o({...R.entries,type:i("status"),options:E(ft),groups:E(ln)}),o({...R.entries,type:i("date")}),o({...R.entries,type:i("people")}),o({...R.entries,type:i("files")}),o({...R.entries,type:i("unique_id")}),o({...R.entries,type:i("relation"),data_source_id:a(r()),dual_property:a(pn)}),o({...R.entries,type:i("place")}),o({...R.entries,type:i("formula")}),o({...R.entries,type:i("rollup")}),o({...R.entries,type:i("button")}),o({...R.entries,type:i("verification")}),o({...R.entries,type:i("last_visited_time")}),o({...R.entries,type:i("location")}),o({...R.entries,type:i("created_time")}),o({...R.entries,type:i("last_edited_time")}),o({...R.entries,type:i("created_by")}),o({...R.entries,type:i("last_edited_by")})]);var Vt={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var Gt=o({id:a(Z),propertiesById:Q(r(),Lt)});var $t=o({collectionPointer:a(Ut),collectionSchema:a(Gt),propertyIdsByKey:a(Q(r(),a(r()))),inaccessible:a(i(!0))});var ve=Q(r(),$t);function Qt(e){let t=Object.entries(e.manifestDataSource.properties??{}).map(([n,s])=>{let c=e.propertyIdsByKey?.[n],p=c===void 0?void 0:e.collectionSchema?.propertiesById[c];return fn(n,c,p?.type,s.type)});return e.collectionSchema===void 0?{status:"missing_schema",properties:t}:t.every(n=>n.status==="mapped")?{status:"complete",properties:t}:{status:"incomplete",properties:t}}function fn(e,t,n,s){return t===void 0?{status:"missing",propertyKey:e,propertyId:t}:n===void 0?{status:"invalid",propertyKey:e,propertyId:t}:{status:n===s?"mapped":"incompatible",propertyKey:e,propertyId:t}}var Ge=o({type:i("page_id"),page_id:F}),$e=o({type:i("data_source_id"),data_source_id:Z}),yn=o({type:i("workspace"),workspace:i(!0)}),dn=o({type:i("block_id"),block_id:me}),vn=o({type:i("agent_id"),agent_id:At}),hn=o({type:i("unavailable")}),re=v("type",[Ge,$e,yn,dn,vn,hn]);var Ie=v("type",[o({type:i("unavailable")}),o({type:i("page"),id:F,parent:re})]);var xe=T(["standard","high"]),Wt="standard";var Ce=T(["light","dark"]);var Xt=o({capability:r(),resource:r()});var gn=v("type",[o({type:i("emoji"),emoji:r()}),o({type:i("external"),url:r()})]),bn=o({name:r(),description:a(r()),type:zt}),Sn=o({name:r(),description:a(r()),icon:a(gn),properties:a(Q(r(),bn),{})}),he=o({version:i(1),name:a(r()),description:a(r()),slashCommand:a(r()),icon:a(o({type:i("emoji"),emoji:r()})),dataSources:a(Q(r(),Sn),{}),capabilities:a(E(Xt))});var Qe=A(r(),pe("NotionUserId"));var ue=o({object:i("user"),id:Qe,name:a(r()),avatar_url:D(r()),type:i("person"),person:o({email:r()})});var kn=r(),Ne=o({code:kn,message:r(),isRetryable:g()}),Ae=class extends Error{constructor(t){super(t.message),this.name="CustomBlockInitializationError",this.code=t.code,this.isRetryable=t.isRetryable}code;isRetryable},We=v("status",[o({type:i("init"),initializationId:r(),status:i("success"),theme:Ce,contrastMode:xe,blockId:me,parent:re,page:Ie,manifest:he,dataSources:o({bindings:ve}),currentUser:ue}),o({type:i("init"),initializationId:r(),status:i("error"),error:Ne})]);var Kt=o({type:i("contrastModeChanged"),contrastMode:xe});var Zt=o({type:i("pageChanged"),page:Ie});var Jt=o({type:i("parentChanged"),parent:re});var Yt=o({type:i("themeChanged"),theme:Ce});var er=o({type:i("dataSourcesChanged"),dataSources:o({bindings:ve})});var Xe=o({unit:T(["year","month","week","day"]),value:O(),time:r(),defaultTimeZone:a(r())}),_n=o({unit:T(["hour","minute"]),value:O()}),Ue=o({unit:i("none")}),yt=d([Xe,_n]),tr=a(d([Xe,Ue])),rr=a(d([yt,Ue])),In=o({type:i("date"),start_date:r(),reminder:tr}),xn=o({type:i("daterange"),start_date:r(),end_date:r(),reminder:tr}),Cn=o({type:i("datetime"),start_date:r(),start_time:r(),time_zone:a(r()),reminder:rr}),Pn=o({type:i("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:a(r()),reminder:rr}),or=v("type",[In,xn,Cn,Pn]);var Ke=o({id:r(),table:r()});var nr=d([r(),O(),g(),or,E(r()),E(Ke)]);var ir=o({id:F,is_archived:g(),in_trash:g(),propertiesById:Q(r(),a(nr))});var En=o({type:i("emoji"),emoji:r()}),On=o({type:i("custom_emoji"),custom_emoji:o({id:r(),name:a(r()),url:a(r())})}),sr=o({type:i("external"),external:o({url:r()})}),ar=o({type:i("file"),file:o({url:r(),expiry_time:a(r())})}),Pe=v("type",[En,On,sr,ar]),Ee=v("type",[sr,ar]);var L=D(r());var dt={start:r(),end:a(L),time_zone:a(L),reminder:a(d([yt,Ue]))},ur=d([o({...dt,start:A(r(),ut("T"))}),o({...dt,time_zone:r()}),o({...dt,reminder:a(d([Xe,Ue]))})]);var cr=d([o({type:i("external"),name:r(),external:o({url:r()})}),o({type:i("file"),name:r(),file:o({url:r(),expiry_time:a(r())})})]);var Oe=D(o({...Ke.entries,table:T(["notion_user","bot","organization_bot"]),spaceId:a(r())}));var lr=o({lat:O(),lon:O(),name:a(L),address:a(L),aws_place_id:a(L),google_place_id:a(L)});var pr=o({id:r()});var vt=Q(r(),qe());var Ze=d([o({id:r(),name:a(r()),color:a(r()),description:a(L)}),o({name:r(),id:a(r()),color:a(r()),description:a(L)})]);var mr=d([o({object:a(i("user")),id:r()}),o({object:i("group"),id:r(),name:a(L)})]);var j={id:r()},ht=v("type",[o({...j,type:i("title"),title:E(vt)}),o({...j,type:i("rich_text"),rich_text:E(vt)}),o({...j,type:i("number"),number:D(O())}),o({...j,type:i("url"),url:L}),o({...j,type:i("email"),email:L}),o({...j,type:i("phone_number"),phone_number:L}),o({...j,type:i("checkbox"),checkbox:g()}),o({...j,type:i("select"),select:D(Ze)}),o({...j,type:i("status"),status:D(Ze)}),o({...j,type:i("multi_select"),multi_select:E(Ze)}),o({...j,type:i("date"),date:D(ur)}),o({...j,type:i("people"),people:E(mr)}),o({...j,type:i("relation"),has_more:a(g()),relation:E(pr)}),o({...j,type:i("files"),files:E(cr)}),o({...j,type:i("place"),place:D(lr)}),o({...j,type:i("created_time"),created_time:L}),o({...j,type:i("last_edited_time"),last_edited_time:L}),o({...j,type:i("created_by"),created_by:Oe}),o({...j,type:i("last_edited_by"),last_edited_by:Oe}),o({...j,type:i("last_visited_time"),last_visited_time:L}),o({...j,type:i("unique_id"),unique_id:r()}),o({...j,type:i("button"),button:r()}),o({...j,type:i("formula"),formula:r()}),o({...j,type:i("location"),location:r()}),o({...j,type:i("rollup"),rollup:r()}),o({...j,type:i("verification"),verification:r()})]);var Be=Q(r(),ht),fr=Q(r(),D(ht));var oe=o({object:i("page"),id:F,parent:re,properties:fr,created_by:a(Oe,null),last_edited_by:a(Oe,null),last_visited_time:a(D(r()),null),created_time:a(D(r()),null),last_edited_time:a(D(r()),null),icon:a(D(Pe),null),cover:a(D(Ee),null),url:a(D(r()),null),public_url:a(D(r()),null),is_archived:g(),in_trash:g()});var yr=d([l({equals:g()}),l({does_not_equal:g()})]);var ce=d([l({is_empty:i(!0)}),l({is_not_empty:i(!0)})]);var be=d([r(),E(r())]);var dr=d([l({contains:be}),l({contains_all:be}),l({does_not_contain:be}),ce]);var vr=l({object:i("user"),id:A(r(),ge(1),we(2e3))}),hr=d([l({contains:vr}),l({does_not_contain:vr}),l({is_empty:i(!0)}),l({is_not_empty:i(!0)})]);var J=T(["start_date","end_date"]),Bn=T(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),Fe=d([Bn,r()]),gr=d([l({target:a(J),equals:Fe}),l({target:a(J),before:Fe}),l({target:a(J),after:Fe}),l({target:a(J),on_or_before:Fe}),l({target:a(J),on_or_after:Fe}),l({target:a(J),this_week:l({})}),l({target:a(J),past_week:l({})}),l({target:a(J),past_month:l({})}),l({target:a(J),past_year:l({})}),l({target:a(J),next_week:l({})}),l({target:a(J),next_month:l({})}),l({target:a(J),next_year:l({})}),l({target:a(J),is_empty:i(!0)}),l({target:a(J),is_not_empty:i(!0)})]);var br=d([l({equals:O()}),l({does_not_equal:O()}),l({greater_than:O()}),l({less_than:O()}),l({greater_than_or_equal_to:O()}),l({less_than_or_equal_to:O()}),ce]);var Je=d([l({equals:be}),l({does_not_equal:be}),ce]);var Sr=l({object:T(["user","group"]),id:A(r(),ge(1))}),kr=d([l({contains:Sr}),l({does_not_contain:Sr}),ce]);var _r=A(F,ct(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),lt(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),Ye=d([l({contains:_r}),l({does_not_contain:_r}),l({is_empty:i(!0)}),l({is_not_empty:i(!0)})]);var Ir=T(["To-do","In progress","Complete","Current","Future"]),xr=d([Ir,A(E(Ir),ge(1),we(5))]),Cr=d([l({group_equals:xr}),l({group_does_not_equal:xr})]);var Pr=d([Je,Cr]);var Re=d([l({equals:r()}),l({does_not_equal:r()}),l({contains:r()}),l({does_not_contain:r()}),l({starts_with:r()}),l({ends_with:r()}),ce]);var gt=d([l({propertyId:r(),relation:Ye}),l({propertyId:r(),created_by:hr}),l({propertyId:r(),title:Re}),l({propertyId:r(),rich_text:Re}),l({propertyId:r(),url:Re}),l({propertyId:r(),email:Re}),l({propertyId:r(),phone_number:Re}),l({propertyId:r(),number:br}),l({propertyId:r(),checkbox:yr}),l({propertyId:r(),select:Je}),l({propertyId:r(),multi_select:dr}),l({propertyId:r(),status:Pr}),l({propertyId:r(),date:gr}),l({propertyId:r(),people:kr})]);var Er=d([gt,l({and:E(gt)})]);var Or=T(["ascending","descending"]);var bt=10,Br=l({propertyId:r(),direction:Or});var Rr=o({type:i("queryDataSource"),subscriptionId:r(),dataSourceId:Z,limit:O(),filter:a(Er),sorts:a(E(Br))}),Rn=r(),jr=o({code:Rn,message:r(),isRetryable:g()}),Mr=v("status",[o({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:E(oe),hasMore:g()}),o({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:jr})]),Dr=v("status",[o({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:E(d([oe,ir])),hasMore:g()}),o({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:jr})]);var jn=r(),Mn=o({code:jn,message:r(),isRetryable:g()}),wr=o({type:i("openExternalUrl"),requestId:r(),url:r()}),Tr=v("status",[o({type:i("openExternalUrlResult"),requestId:r(),status:i("success")}),o({type:i("openExternalUrlResult"),requestId:r(),status:i("error"),error:Mn})]);var je=o({object:i("page"),id:F,parent:re,properties:Be,created_time:a(r()),last_edited_time:a(r()),icon:a(Pe),cover:a(Ee),url:a(r()),public_url:a(r()),is_archived:g(),in_trash:g()});var Dn=r(),Ar=o({code:Dn,message:r(),isRetryable:g()}),Nr=v("status",[o({type:i("createPageResult"),requestId:r(),status:i("success"),page:oe}),o({type:i("createPageResult"),requestId:r(),status:i("error"),error:Ar})]),Ur=v("status",[o({type:i("createPageResult"),requestId:r(),status:i("success"),page:d([oe,je])}),o({type:i("createPageResult"),requestId:r(),status:i("error"),error:Ar})]),wn=v("type",[o({type:i("start")}),o({type:i("end")}),o({type:i("before"),blockId:me}),o({type:i("after"),blockId:me})]),Za=v("type",[Ge,$e]),qr={type:i("createPage"),requestId:r(),properties:Be},Fr=v("type",[o({...qr,parent:Ge,position:a(wn)}),o({...qr,parent:$e,position:a(mt())})]);var Tn=r(),zr=o({code:Tn,message:r(),isRetryable:g()}),Hr=o({type:i("getPage"),requestId:r(),pageId:F,dataSourceId:a(Z)}),Lr=v("status",[o({type:i("getPageResult"),requestId:r(),status:i("success"),page:oe}),o({type:i("getPageResult"),requestId:r(),status:i("error"),error:zr})]),Vr=v("status",[o({type:i("getPageResult"),requestId:r(),status:i("success"),page:d([oe,je])}),o({type:i("getPageResult"),requestId:r(),status:i("error"),error:zr})]);var qn=T(["side_peek","center_peek"]),An=r(),Nn=o({code:An,message:r(),isRetryable:g()}),Gr=o({type:i("openPage"),requestId:r(),pageId:F,mode:qn}),$r=v("status",[o({type:i("openPageResult"),requestId:r(),status:i("success"),pageId:F}),o({type:i("openPageResult"),requestId:r(),status:i("error"),error:Nn})]);var Un=r(),Qr=o({code:Un,message:r(),isRetryable:g()}),Wr=v("status",[o({type:i("updatePageResult"),requestId:r(),status:i("success"),page:oe}),o({type:i("updatePageResult"),requestId:r(),status:i("error"),error:Qr})]),Xr=v("status",[o({type:i("updatePageResult"),requestId:r(),status:i("success"),page:d([oe,je])}),o({type:i("updatePageResult"),requestId:r(),status:i("error"),error:Qr})]),Kr=o({type:i("updatePage"),requestId:r(),pageId:F,dataSourceId:a(Z),properties:a(Be),icon:a(Pe),cover:a(Ee),archived:a(g())});var Zr=o({type:i("currentUserChanged"),currentUser:ue});var Fn=r(),zn=o({code:Fn,message:r(),isRetryable:g()}),Jr=o({type:i("getUser"),requestId:r(),userId:Qe}),Yr=v("status",[o({type:i("getUserResult"),requestId:r(),status:i("success"),user:ue}),o({type:i("getUserResult"),requestId:r(),status:i("error"),error:zn})]);var eo=o({object:i("list"),results:E(ue),next_cursor:D(r()),has_more:g(),type:i("user"),user:Q(r(),qe())});var Hn=r(),Ln=o({code:Hn,message:r(),isRetryable:g()}),to=o({type:i("listUsers"),requestId:r(),startCursor:a(r()),pageSize:a(O())}),ro=v("status",[o({type:i("listUsersResult"),requestId:r(),status:i("success"),list:eo}),o({type:i("listUsersResult"),requestId:r(),status:i("error"),error:Ln})]);var oo=o({type:i("invalidSandboxMessage"),requestId:a(r()),reason:r()});var no=v("type",[We,Yt,Kt,Jt,Zt,Zr,er,Yr,ro,$r,Tr,oo]),io=v("type",[...no.options,Mr,Lr,Nr,Wr]),Au=v("type",[...no.options,Dr,Vr,Ur,Xr]);function so(e){return{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([t,n])=>[t,{...n,collectionSchema:{...n.collectionSchema,propertiesById:{...n.collectionSchema?.propertiesById,...Vt}}}]))}}}function ee(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function ze(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,n])=>{switch(n?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];case"title":case"rich_text":case"number":case"url":case"email":case"phone_number":case"checkbox":case"select":case"status":case"multi_select":case"date":case"people":case"relation":case"files":case"place":case"created_time":case"last_edited_time":case"created_by":case"last_edited_by":case"last_visited_time":case void 0:return[t,n];default:return ee(n)}}))}}function ao(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 Se(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"}}var ke=class extends Error{};function St(e){try{return Vn(e)}catch(t){throw t instanceof RangeError?new ke(t.message):t}}function Vn(e){let{start:t,end:n,time_zone:s,reminder:c}=e;if(!t.split("T")[0])throw new ke("Date values must include a date.");let p=t.includes("T")||s!=null,f=t.match(/([+-])(\d{2}):(\d{2})$/),h=f?(Number(f[2])*60+Number(f[3]))*(f[1]==="-"?-1:1):0,y=s?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=y?(Number(y[2]??0)*60+Number(y[3]??0))*(y[1]==="-"?-1:1):h,I=b=>{if(!b.split("T")[0])throw new ke("Date values must include a date.");if(!b.includes("T"))return{date:b,time:"00:00"};let N=b.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(N)return{date:N[1],time:N[2]};if(!s||y){let U=new Date(new Date(b).getTime()+x*6e4).toISOString();return{date:U.slice(0,10),time:U.slice(11,16)}}let B=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(b)),z=U=>B.find(te=>te.type===U)?.value;return{date:`${z("year")}-${z("month")}-${z("day")}`,time:`${z("hour")}:${z("minute")}`}},M=I(t),X=n?I(n):void 0;if(!p){if(c&&!("time"in c)&&c.unit!=="none")throw new ke("Hour and minute reminders require a date with a time.");return X?{type:"daterange",start_date:M.date,end_date:X.date,reminder:c}:{type:"date",start_date:M.date,reminder:c}}let V=s??(h===0?"UTC":`UTC${h<0?"-":"+"}${Math.floor(Math.abs(h)/60)}${Math.abs(h)%60===0?"":`:${String(Math.abs(h)%60).padStart(2,"0")}`}`);return X?{type:"datetimerange",start_date:M.date,start_time:M.time,end_date:X.date,end_time:X.time,time_zone:V,reminder:c}:{type:"datetime",start_date:M.date,start_time:M.time,time_zone:V,reminder:c}}function co(e){switch(e.type){case"title":return uo(e.title);case"rich_text":return uo(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?St(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return Se(e.created_time);case"last_edited_time":return Se(e.last_edited_time);case"last_visited_time":return Se(e.last_visited_time);case"created_by":return e.created_by?[e.created_by]:void 0;case"last_edited_by":return e.last_edited_by?[e.last_edited_by]:void 0;default:return ee(e)}}function uo(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 lo(e){let t={};for(let n of Object.values(e.properties))n&&(t[n.id]=co(n));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:{...t,created_time:Se(e.created_time),last_edited_time:Se(e.last_edited_time),created_by:e.created_by?[e.created_by]:void 0,last_edited_by:e.last_edited_by?[e.last_edited_by]:void 0}}}function po(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(lo)}:{...e,page:ao(ze(e.page))}}function mo(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(ze)}:{...e,page:ze(e.page)}}function fo(e,t){return e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged"?t<5?so(e):e:e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"||e.status==="error"?e:t<6?po(e):t<7?mo(e):e}var kt=o({theme:Ce,contrastMode:a(xe),blockId:me,parent:re,page:Ie,manifest:he,dataSources:o({bindings:ve}),currentUser:ue}),yo=v("status",[o({status:i("success"),initialState:qt(kt,["manifest"])}),o({status:i("error"),error:Ne})]);var et=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=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,n.push({message:c.message,token:c.token})}return s?n:void 0}finish(t,n){let s=this.bySubscriptionId.get(t);if(s?.token===n&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function vo(e,t){if(e===void 0)return;let n="and"in e?e.and:[e];for(let s of n){let c=Qn(s,t);if(c!==void 0)return c}}function Qn(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],s=Object.keys(e).find(h=>h!=="propertyId");if(s!==n.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${n.type}".`,isRetryable:!1};if("status"in e&&n.type==="status"){let h=e.status;if("group_equals"in h||"group_does_not_equal"in h){let y="group_equals"in h?h.group_equals:h.group_does_not_equal,I=(Array.isArray(y)?y:[y]).find(M=>!n.groups.some(X=>X.name===M));return I===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${I}".`,isRetryable:!1}}}if("relation"in e&&!Tt(Ye,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=Wn(e);if(c===void 0||n.type!==c.propertyType)return;let p=new Set(n.options.map(h=>h.name)),f=Xn(c.operator).find(h=>!p.has(h));if(f!==void 0)return{code:"invalid_data_source_query_filter",message:`Data source query filter option "${f}" is not defined for property "${e.propertyId}".`,isRetryable:!1}}function Wn(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 Xn(e){let t;if("equals"in e)t=e.equals;else if("does_not_equal"in e)t=e.does_not_equal;else if("contains"in e)t=e.contains;else if("contains_all"in e)t=e.contains_all;else if("does_not_contain"in e)t=e.does_not_contain;else return"is_empty"in e||"is_not_empty"in e?[]:ee(e);return Array.isArray(t)?t:[t]}var Kn=new Set(Ht);function ho(e,t){if(e===void 0)return;if(e.length>bt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${bt} entries.`,isRetryable:!1};let n=new Set;for(let s of e){if(n.has(s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${s.propertyId}".`,isRetryable:!1};if(n.add(s.propertyId),!Object.hasOwn(t.propertiesById,s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${s.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[s.propertyId];if(!Kn.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}}}function go(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function _t(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function bo(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function So(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function tt(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function It(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 xt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var Zn=5e3,Jn=5e3,Yn=5e3;function ko(e){let{manifestSource:t,prepareInit:n,sendInitMessage:s,warn:c,flushPendingHostStateChanges:p,minBridgeProtocolVersion:f,noConnectTimeoutMs:h=Zn,initialStateTimeoutMs:y=Jn,noInitResultTimeoutMs:x=Yn,stopHostWithFailure:I,onInitResult:M,onInitSent:X,onConnectionFailure:V}=e,b="waitingForConnect",N,B,z,U,te=!1,fe=!1;function K(){N!==void 0&&(window.clearTimeout(N),N=void 0)}function H(){B!==void 0&&(window.clearTimeout(B),B=void 0)}function G(){z!==void 0&&(window.clearTimeout(z),z=void 0)}function $(k){let{initializationId:C,error:_,phase:se,source:ot}=k;switch(b){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"failed":case"stopped":return;default:return ee(b)}b="failed",U=C,K(),H(),s({type:"init",initializationId:C,status:"error",error:_}),V({..._,phase:se,source:ot})}async function ne(k){if(b==="waitingForConnect"){b="preparingInit",U=k.initializationId,K(),B=window.setTimeout(()=>{if(b!=="preparingInit")return;let C=go();c({...C,initializationId:k.initializationId}),$({initializationId:k.initializationId,error:C,phase:"init",source:"host"})},y);try{let C=await n(k);if(b!=="preparingInit")return;if(H(),C.status==="error"){$({initializationId:k.initializationId,error:C.error,phase:"init",source:"host"});return}b="waitingForInitResult";let _={type:"init",initializationId:k.initializationId,status:"success",theme:C.initialState.theme,contrastMode:C.initialState.contrastMode??Wt,blockId:C.initialState.blockId,parent:C.initialState.parent,page:C.initialState.page,currentUser:C.initialState.currentUser,manifest:C.initialState.manifest,dataSources:C.initialState.dataSources};if(s(_),b!=="waitingForInitResult"||(X(),b!=="waitingForInitResult"))return;z=window.setTimeout(()=>{if(b!=="waitingForInitResult")return;b="failed";let se=So();V({...se,phase:"initResult",source:"host"}),c({...se,initializationId:k.initializationId})},x)}catch(C){if(b!=="preparingInit")return;c({message:"Failed to prepare custom block initialization",error:C}),$({initializationId:k.initializationId,error:tt(),phase:"init",source:"host"})}}}function q(k){if(b!=="stopped"&&b==="waitingForConnect"){if(!xt(k.bridgeProtocolVersion)){let C=_t({currentBridgeProtocolVersion:k.bridgeProtocolVersion});$({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.bridgeProtocolVersion<f){let C=It({currentBridgeProtocolVersion:k.bridgeProtocolVersion,minBridgeProtocolVersion:f});$({initializationId:k.initializationId,error:C,phase:"connect",source:"host"});return}if(k.status==="error"&&(t==="sandbox"||k.error.code!=="manifest_invalid")){$({initializationId:k.initializationId,error:k.error,phase:"connect",source:"sandbox"});return}fe=!0,ne(k)}}function Y(k){if(b==="stopped"||b!=="waitingForConnect")return"handled";let{initializationId:C,bridgeProtocolVersion:_}=k;if(C===void 0)return"nack";let se=k.error;return _!==void 0&&(xt(_)?_<f&&(se=It({currentBridgeProtocolVersion:_,minBridgeProtocolVersion:f})):se=_t({currentBridgeProtocolVersion:_})),$({initializationId:C,error:se,phase:"connect",source:"host"}),"handled"}function ie(k){let{initializationId:C,error:_}=k;b!=="waitingForInitResult"||C===void 0||C!==U||(K(),G(),b="failed",c(_),V({..._,phase:"initResult",source:"host"}))}function He(){if(b!=="stopped"){if(te){I({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}te=!0,K(),b==="waitingForConnect"&&(N=window.setTimeout(()=>{if(b!=="waitingForConnect")return;b="failed";let k=bo();c(k),V({...k,phase:"connect",source:"host"})},h))}}function Me(k){if(b!=="waitingForInitResult"||k.initializationId!==U){c({message:"Ignored stale or unexpected initResult",payload:k});return}G(),b=k.status==="success"?"initialized":"failed",k.status==="success"?p():V({...k.error,phase:"initResult",source:"sandbox"}),M(k)}function ye(){b="stopped",K(),H(),G()}return{get status(){return b},get hasConnectedSandbox(){return fe},handleConnect:q,handleInitResult:Me,handleInvalidConnect:Y,handleInvalidInitResult:ie,onIframeLoad:He,stop:ye}}function Ct(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Pt(){return{code:"invalid_local_preview_url",message:"Local custom blocks require an HTTP(S) URL on localhost, a .localhost subdomain, or 127.0.0.1, without credentials and on a different origin from the host.",isRetryable:!1}}function _o(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function Io(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function xo(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function Co(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}function rt({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&Co(e)}async function Po(e){return e.manifestSource==="host"?e.hostManifest:e.connectManifest!==void 0?{status:"success",manifest:e.connectManifest}:{status:"error",error:{code:"manifest_unavailable",message:"The sandbox did not provide a manifest in connect.",isRetryable:!1}}}var Eo=v("status",[o({status:i("success"),manifest:he}),o({status:i("error"),error:Ne})]);function Oo(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Bo=o({type:i("resize"),height:A(O(),De(),Te(0))});var Ro=o({type:i("unsubscribeDataSourceQuery"),subscriptionId:r()});var jo=o({code:r(),message:r(),isRetryable:g()});var Mo={type:i("connect"),initializationId:r(),bridgeProtocolVersion:O(),sdkVersion:r()},Do=v("status",[o({status:i("success"),manifest:a(he),...Mo}),o({status:i("error"),error:jo,...Mo})]);var ei=r(),ti=o({code:ei,message:r(),isRetryable:g()}),wo=v("status",[o({type:i("initResult"),initializationId:r(),status:i("success"),initialHeight:a(A(O(),De(),Te(0)))}),o({type:i("initResult"),initializationId:r(),status:i("error"),error:ti})]);var To=o({type:i("invalidHostMessage"),requestId:a(r()),reason:r()});var qo=v("type",[Do,wo,Rr,Ro,Fr,Hr,Jr,to,Gr,wr,Kr,Bo,To]);function Ao(e){return de(qo,e)}function No(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function Uo(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Fo(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}var ri=o({requestId:r()});function zo(e){let t=de(ri,e);return t.success?t.output.requestId:void 0}function Ho(e){let t=Fo(e);if(t==="invalidHostMessage"||t==="invalidSandboxMessage")return{incomingType:t};let n=zo(e);return{incomingType:t,nack:{type:"invalidSandboxMessage",...n!==void 0?{requestId:n}:{},reason:oi(t)}}}function oi(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var Lo=o({initializationId:r()}),ni=o({bridgeProtocolVersion:d([O(),pt()])});function Vo(e){let{iframe:t,sandboxOrigin:n,getInitStatus:s,emit:c,sendNack:p,onInvalidConnect:f,onInvalidInitResult:h,onConnect:y,onInitResult:x,onQueryDataSource:I,onUnsubscribeDataSourceQuery:M,onCreatePage:X,onGetPage:V,onOpenPage:b,onOpenExternalUrl:N,onGetUser:B,onListUsers:z,onUpdatePage:U,onResize:te}=e;function fe(K,H){c("warn",{message:"Ignored unsupported sandbox message",payload:Et(K),issues:H});let G=Ho(K);if(G.incomingType==="connect"){let $=de(Lo,K),ne=de(ni,K);if(f({initializationId:$.success?$.output.initializationId:void 0,error:No(),bridgeProtocolVersion:ne.success?ne.output.bridgeProtocolVersion:void 0})==="handled")return}if(G.incomingType==="initResult"){let $=de(Lo,K);h({initializationId:$.success?$.output.initializationId:void 0,error:Uo()})}G.nack!==void 0&&s()!=="stopped"&&p(G.nack)}return function(H){let G=H.source===t.contentWindow,$=H.origin===n;if(!G||!$)return;let ne=Ao(H.data);if(!ne.success){fe(H.data,ne.issues);return}let q=ne.output;if(!Oo(q)&&s()!=="initialized"){c("warn",{message:`Ignored ${q.type} before initialization completed`,payload:Et(q)});return}switch(c("in",Et(q)),q.type){case"connect":y(q);return;case"initResult":x(q);return;case"queryDataSource":I(q);return;case"unsubscribeDataSourceQuery":M(q);return;case"createPage":X(q);return;case"openPage":b(q);return;case"openExternalUrl":N(q);return;case"getPage":V(q);return;case"getUser":B(q);return;case"listUsers":z(q);return;case"updatePage":U(q);return;case"resize":te(q);return;case"invalidHostMessage":return;default:ee(q)}}}function Et(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}function Go(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}var Qo=5;function si(e){let{iframe:t,prepareInitialState:n,handlers:s,onStatusChange:c,onLog:p,onQueryUnsubscribed:f,minBridgeProtocolVersion:h,noConnectTimeoutMs:y,initialStateTimeoutMs:x,noInitResultTimeoutMs:I}=e,M=ai(e.sandboxUrl,e.manifestSource),X=M.origin,V=Math.max(h??3,3),b=new AbortController,N,B={},z=!1,U=new AbortController,te,fe,K=8,H=new et(u=>{f?.(u)});function G(u,S){p?.(u,S)}function $(u){let S=_.status;switch(S){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"failed":break;case"stopped":return;default:return ee(S)}let P=fo(u,K);G("out",P),t.contentWindow?.postMessage(P,X)}function ne(u){$(ae(We,u))}function q(u){$(u)}function Y(u){let S=_.status;switch(S){case"initialized":$(ae(io,u));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"failed":case"stopped":return;default:ee(S)}}async function ie(u,S){try{let P=S===void 0?ci(u.type):await S(u);Y({...P,type:`${u.type}Result`,requestId:u.requestId})}catch(P){if(_.status!=="initialized")return;G("warn",P),Y({type:`${u.type}Result`,requestId:u.requestId,status:"error",error:{code:"unknown_error",message:`The host could not complete ${u.type}.`,isRetryable:!1}})}}function He(u){let S=u.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:u.subscriptionId,status:"error",error:u.response.error}:{type:"queryDataSourceResult",subscriptionId:u.subscriptionId,status:"success",items:u.response.items,hasMore:u.response.hasMore};Y(S)}async function Me(u,S=H.subscribe(u)){try{let P=ui(fe,u.dataSourceId),le=li(u,P);if(le!==void 0){H.isCurrent(u.subscriptionId,S)&&(H.unsubscribe(u.subscriptionId),He({subscriptionId:u.subscriptionId,response:{status:"error",error:le}}));return}let it=await s.queryDataSource(u);if(!H.isCurrent(u.subscriptionId,S))return;it.status==="error"&&!it.error.isRetryable&&H.unsubscribe(u.subscriptionId),He({subscriptionId:u.subscriptionId,response:it})}finally{let P=H.finish(u.subscriptionId,S);P!==void 0&&Me(P.message,P.token)}}function ye(u){_.status==="stopped"||_.status==="failed"||(Object.assign(B,u),C())}async function k(u){if(b.signal.aborted)return;let S=s.openExternalUrl;if(S===void 0){await ie(u,void 0);return}if(N===u.requestId)return;if(N!==void 0){let le={type:"openExternalUrlResult",requestId:u.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};Y(le);return}let P=Go(u.url);if(P===void 0){let le={type:"openExternalUrlResult",requestId:u.requestId,status:"error",error:{code:"invalid_url",message:"Only valid HTTP or HTTPS URLs without credentials, up to 2,048 characters, can be opened.",isRetryable:!1}};Y(le);return}N=u.requestId;try{await ie(u,()=>S({...u,url:P},{signal:b.signal}))}finally{N===u.requestId&&(N=void 0)}}function C(){if(_.status!=="initialized")return;let u=B;B={},u.theme!==void 0&&Y({type:"themeChanged",theme:u.theme}),u.contrastMode!==void 0&&Y({type:"contrastModeChanged",contrastMode:u.contrastMode}),u.parent!==void 0&&Y({type:"parentChanged",parent:u.parent}),u.page!==void 0&&Y({type:"pageChanged",page:u.page}),u.dataSources!==void 0&&Y({type:"dataSourcesChanged",dataSources:u.dataSources}),u.currentUser!==void 0&&Y({type:"currentUserChanged",currentUser:u.currentUser})}let _=ko({manifestSource:e.manifestSource,async prepareInit(u){let S=u.status==="success"?u.manifest:void 0;K=u.bridgeProtocolVersion,c({status:"preparingInit",localManifest:rt({url:M,hostOrigin:window.location.origin})?S:void 0,bridgeProtocolVersion:u.bridgeProtocolVersion,sdkVersion:u.sdkVersion});let P=await(Ko??Bt(S));return _.status!=="preparingInit"?P:se(P)},sendInitMessage:ne,onInitSent:()=>c({status:"waitingForInitResult"}),warn:u=>G("warn",u),flushPendingHostStateChanges:C,minBridgeProtocolVersion:V,noConnectTimeoutMs:y,initialStateTimeoutMs:x,noInitResultTimeoutMs:I,stopHostWithFailure:jt,onInitResult(u){u.status==="success"&&te!==void 0&&c({status:"initialized",resolvedManifest:te,initialHeight:u.initialHeight})},onConnectionFailure:u=>{U.abort(),c({status:"failed",error:u})}});function se(u){if(u.status==="error")return u;let S=ae(kt,{...u.initialState,...B});if(te=S.manifest,B={},K<Qo&&S.page.type==="unavailable")return{status:"error",error:Ct()};let P=Wo(S.manifest,S.dataSources);return P!==void 0?{status:"error",error:P}:(fe=S.dataSources,z=!0,{status:"success",initialState:S})}let ot=Zo().catch(Ot),Ko=e.manifestSource==="host"?Bt(void 0).catch(Ot):void 0;async function Zo(){U.signal.throwIfAborted();let u=await e.getPersistedManifest({signal:U.signal});return U.signal.throwIfAborted(),ae(Eo,u)}function Ot(u){return U.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:u}),{status:"error",error:tt()}}async function Bt(u){U.signal.throwIfAborted();let S=await Po({manifestSource:e.manifestSource,hostManifest:ot,connectManifest:u});if(U.signal.throwIfAborted(),S.status==="error")return S;let P=ae(yo,await n({manifest:S.manifest,signal:U.signal}));return P.status==="error"?P:{status:"success",initialState:{...P.initialState,manifest:S.manifest}}}let Rt=Vo({iframe:t,sandboxOrigin:X,getInitStatus:()=>_.status,emit:G,sendNack:q,onInvalidConnect:_.handleInvalidConnect,onInvalidInitResult:_.handleInvalidInitResult,onConnect:_.handleConnect,onInitResult:_.handleInitResult,onQueryDataSource:Me,onUnsubscribeDataSourceQuery:u=>H.unsubscribe(u.subscriptionId),onOpenExternalUrl:k,onCreatePage:u=>ie(u,s.createPage),onGetPage:u=>ie(u,s.getPage),onOpenPage:u=>ie(u,s.openPage),onGetUser:u=>ie(u,s.getUser),onListUsers:u=>ie(u,s.listUsers),onUpdatePage:u=>ie(u,s.updatePage),onResize:u=>s.resize?.(u)});window.addEventListener("message",Rt),t.addEventListener("load",_.onIframeLoad);function nt(){b.abort(),U.abort(),window.removeEventListener("message",Rt),t.removeEventListener("load",_.onIframeLoad),_.stop(),H.unsubscribeAll()}function Jo(){let u=_.status;nt(),u!=="stopped"&&u!=="failed"&&c({status:"stopped"})}function jt(u){if(_.status!=="stopped"){if(_.status==="failed"){nt();return}nt(),G("warn",u),c({status:"failed",error:u})}}return c({status:"waitingForConnect"}),{stop:Jo,setTheme(u){ye({theme:u})},setContrastMode(u){ye({contrastMode:u})},setParent(u){ye({parent:u})},setPage(u){if(u.type==="unavailable"&&K<Qo&&(_.status==="preparingInit"&&z||_.status==="waitingForInitResult"||_.status==="initialized")){jt({...Ct(),phase:"runtime",source:"host"});return}ye({page:u})},setCurrentUser(u){ye({currentUser:u})},setDataSources(u){let S={bindings:ae(ve,u.bindings)},P=_.hasConnectedSandbox&&te!==void 0?Wo(te,S):void 0;return P!==void 0?(G("warn",{message:"Ignored invalid data source bindings update",payload:S}),{status:"error",error:P}):(fe=S,ye({dataSources:S}),{status:"success"})},refreshQuery({dataSourceId:u}){if(_.status!=="initialized")return;let S=ae(Z,u),P=H.refresh(S);if(P===void 0){G("warn",`No active query exists for data source "${u}"`);return}for(let le of P)Me(le.message,le.token)}}}function ai(e,t){let n;try{n=new URL(e)}catch(s){throw t==="host"?s:new Ae(Pt())}if(t==="sandbox"&&!rt({url:n,hostOrigin:window.location.origin}))throw new Ae(Pt());return n}function ui(e,t){return Object.values(e?.bindings??{}).find(n=>n.collectionPointer?.id===t)?.collectionSchema}function Wo(e,t){for(let[n,s]of Object.entries(e.dataSources)){let c=t.bindings[n];if(c?.inaccessible===!0)continue;let p=Qt({manifestDataSource:s,collectionSchema:c?.collectionSchema,propertyIdsByKey:c?.propertyIdsByKey});if(c?.collectionPointer===void 0||p.status==="missing_schema")return Io();for(let f of p.properties){if(f.status==="missing")return xo();if(f.status!=="mapped")return _o()}}}function ci(e){return{status:"error",error:{code:"unsupported_operation",message:`The host does not support ${e}.`,isRetryable:!1}}}function li(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}:vo(e.filter,t)??ho(e.sorts,t)}function pi(e){let{manifestProperties:t,propertySchemasById:n}=e,s=[];for(let[c,p]of Object.entries(t)){let f=mi({propertyKey:c,manifestProperty:p,propertySchemasById:n});f!==void 0&&s.push([c,f])}return Object.fromEntries(s)}function mi(e){let{propertyKey:t,manifestProperty:n,propertySchemasById:s}=e,c=Xo(n.name),p=Object.entries(s).filter(([f,h])=>h.type===n.type&&(f===t||Xo(h.name)===c));return p.length===1?p[0][0]:void 0}function Xo(e){return e.trim().toLowerCase()}function fi(e){return ae(F,e)}export{ke as InvalidNotionDateError,si as createCustomBlockHost,pi as getAutoBoundPropertyIdsByKey,rt as isAllowedLocalPreviewUrl,St as toNotionDateValue,fi as toNotionPageId};
1
+ var Ve,mn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function ut(e){return!e&&!Ve?mn:{lang:e?.lang??Ve?.lang,message:e?.message,abortEarly:e?.abortEarly??Ve?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Ve?.abortPipeEarly}}var fn;function yn(e){return fn?.get(e)}var dn;function vn(e){return dn?.get(e)}var hn;function gn(e,t){return hn?.get(e)?.get(t)}function xe(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 M(e,t,o,s,c){let l=c&&"input"in c?c.input:o.value,p=c?.expected??e.expects??null,h=c?.received??xe(l),y={kind:e.kind,type:e.type,input:l,expected:p,received:h,message:`Invalid ${t}: ${p?`Expected ${p} but r`:"R"}eceived ${h}`,requirement:e.requirement,path:c?.path,issues:c?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},x=e.kind==="schema",k=c?.message??e.message??gn(e.reference,y.lang)??(x?vn(y.lang):null)??s.message??yn(y.lang);k!==void 0&&(y.message=typeof k=="function"?k(y):k),x&&(o.typed=!1),o.issues?o.issues.push(y):o.issues=[y]}function bn(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Ft(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function ct(e,t){let o=[...new Set(e)];return o.length>1?`(${o.join(` ${t} `)})`:o[0]??"never"}function $(e){return e["~standard"]={version:1,vendor:"valibot",validate:t=>e["~run"]({value:t},ut())},e}var Sn=class extends Error{constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function me(e){return{kind:"transformation",type:"brand",reference:me,async:!1,name:e,"~run"(t){return t}}}function Te(e){return{kind:"validation",type:"finite",reference:Te,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(t,o){return t.typed&&!this.requirement(t.value)&&M(this,"finite",t,o),t}}}function lt(e,t){let o=xe(e);return{kind:"validation",type:"includes",reference:lt,async:!1,expects:o,requirement:e,message:t,"~run"(s,c){return s.typed&&!s.value.includes(this.requirement)&&M(this,"content",s,c,{received:`!${o}`}),s}}}function qe(e,t){return{kind:"validation",type:"max_length",reference:qe,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&o.value.length>this.requirement&&M(this,"length",o,s,{received:`${o.value.length}`}),o}}}function be(e,t){return{kind:"validation",type:"min_length",reference:be,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&o.value.length<this.requirement&&M(this,"length",o,s,{received:`${o.value.length}`}),o}}}function Ae(e,t){return{kind:"validation",type:"min_value",reference:Ae,async:!1,expects:`>=${e instanceof Date?e.toJSON():xe(e)}`,requirement:e,message:t,"~run"(o,s){return o.typed&&!(o.value>=this.requirement)&&M(this,"value",o,s,{received:o.value instanceof Date?o.value.toJSON():xe(o.value)}),o}}}function pt(e,t){return{kind:"validation",type:"regex",reference:pt,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(o,s){return o.typed&&!this.requirement.test(o.value)&&M(this,"format",o,s),o}}}function mt(e){return{kind:"transformation",type:"transform",reference:mt,async:!1,operation:e,"~run"(t){return t.value=this.operation(t.value),t}}}var zt={abortEarly:!0};function ft(e,t,o){return typeof e.fallback=="function"?e.fallback(t,o):e.fallback}function Ne(e,t,o){return typeof e.default=="function"?e.default(t,o):e.default}function Ht(e,t){return!e["~run"]({value:t},zt).issues}function O(e,t){return $({kind:"schema",type:"array",reference:O,expects:"Array",async:!1,item:e,message:t,"~run"(o,s){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],h=this.item["~run"]({value:p},s);if(h.issues){let y={type:"array",origin:"value",input:c,key:l,value:p};for(let x of h.issues)x.path?x.path.unshift(y):x.path=[y],o.issues?.push(x);if(o.issues||(o.issues=h.issues),s.abortEarly){o.typed=!1;break}}h.typed||(o.typed=!1),o.value.push(h.value)}}else M(this,"type",o,s);return o}})}function g(e){return $({kind:"schema",type:"boolean",reference:g,expects:"boolean",async:!1,message:e,"~run"(t,o){return typeof t.value=="boolean"?t.typed=!0:M(this,"type",t,o),t}})}function i(e,t){return $({kind:"schema",type:"literal",reference:i,expects:xe(e),async:!1,literal:e,message:t,"~run"(o,s){return bn(o.value,this.literal)?o.typed=!0:M(this,"type",o,s),o}})}function Ge(e,t){return $({kind:"schema",type:"loose_object",reference:Ge,expects:"Object",async:!1,entries:e,message:t,"~run"(o,s){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 h=l in c?c[l]:Ne(p),y=p["~run"]({value:h},s);if(y.issues){let x={type:"object",origin:"value",input:c,key:l,value:h};for(let k of y.issues)k.path?k.path.unshift(x):k.path=[x],o.issues?.push(k);if(o.issues||(o.issues=y.issues),s.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value[l]=y.value}else if(p.fallback!==void 0)o.value[l]=ft(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(M(this,"key",o,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!o.issues||!s.abortEarly)for(let l in c)Ft(c,l)&&!Object.prototype.hasOwnProperty.call(this.entries,l)&&(o.value[l]=c[l])}else M(this,"type",o,s);return o}})}function yt(e){return $({kind:"schema",type:"nan",reference:yt,expects:"NaN",async:!1,message:e,"~run"(t,o){return Number.isNaN(t.value)?t.typed=!0:M(this,"type",t,o),t}})}function dt(e){return $({kind:"schema",type:"never",reference:dt,expects:"never",async:!1,message:e,"~run"(t,o){return M(this,"type",t,o),t}})}function q(e,t){return $({kind:"schema",type:"nullable",reference:q,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,"~run"(o,s){return o.value===null&&(this.default!==void 0&&(o.value=Ne(this,o,s)),o.value===null)?(o.typed=!0,o):this.wrapped["~run"](o,s)}})}function R(e){return $({kind:"schema",type:"number",reference:R,expects:"number",async:!1,message:e,"~run"(t,o){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:M(this,"type",t,o),t}})}function n(e,t){return $({kind:"schema",type:"object",reference:n,expects:"Object",async:!1,entries:e,message:t,"~run"(o,s){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 h=l in c?c[l]:Ne(p),y=p["~run"]({value:h},s);if(y.issues){let x={type:"object",origin:"value",input:c,key:l,value:h};for(let k of y.issues)k.path?k.path.unshift(x):k.path=[x],o.issues?.push(k);if(o.issues||(o.issues=y.issues),s.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value[l]=y.value}else if(p.fallback!==void 0)o.value[l]=ft(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(M(this,"key",o,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}}else M(this,"type",o,s);return o}})}function a(e,t){return $({kind:"schema",type:"optional",reference:a,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,"~run"(o,s){return o.value===void 0&&(this.default!==void 0&&(o.value=Ne(this,o,s)),o.value===void 0)?(o.typed=!0,o):this.wrapped["~run"](o,s)}})}function B(e,t){return $({kind:"schema",type:"picklist",reference:B,expects:ct(e.map(xe),"|"),async:!1,options:e,message:t,"~run"(o,s){return this.options.includes(o.value)?o.typed=!0:M(this,"type",o,s),o}})}function Q(e,t,o){return $({kind:"schema",type:"record",reference:Q,expects:"Object",async:!1,key:e,value:t,message:o,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){s.typed=!0,s.value={};for(let p in l)if(Ft(l,p)){let h=l[p],y=this.key["~run"]({value:p},c);if(y.issues){let k={type:"object",origin:"key",input:l,key:p,value:h};for(let T of y.issues)T.path=[k],s.issues?.push(T);if(s.issues||(s.issues=y.issues),c.abortEarly){s.typed=!1;break}}let x=this.value["~run"]({value:h},c);if(x.issues){let k={type:"object",origin:"value",input:l,key:p,value:h};for(let T of x.issues)T.path?T.path.unshift(k):T.path=[k],s.issues?.push(T);if(s.issues||(s.issues=x.issues),c.abortEarly){s.typed=!1;break}}(!y.typed||!x.typed)&&(s.typed=!1),y.typed&&(s.value[y.value]=x.value)}}else M(this,"type",s,c);return s}})}function m(e,t){return $({kind:"schema",type:"strict_object",reference:m,expects:"Object",async:!1,entries:e,message:t,"~run"(o,s){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 h=l in c?c[l]:Ne(p),y=p["~run"]({value:h},s);if(y.issues){let x={type:"object",origin:"value",input:c,key:l,value:h};for(let k of y.issues)k.path?k.path.unshift(x):k.path=[x],o.issues?.push(k);if(o.issues||(o.issues=y.issues),s.abortEarly){o.typed=!1;break}}y.typed||(o.typed=!1),o.value[l]=y.value}else if(p.fallback!==void 0)o.value[l]=ft(p);else if(p.type!=="exact_optional"&&p.type!=="optional"&&p.type!=="nullish"&&(M(this,"key",o,s,{input:void 0,expected:`"${l}"`,path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]}),s.abortEarly))break}if(!o.issues||!s.abortEarly){for(let l in c)if(!Object.prototype.hasOwnProperty.call(this.entries,l)){M(this,"key",o,s,{input:l,expected:"never",path:[{type:"object",origin:"key",input:c,key:l,value:c[l]}]});break}}}else M(this,"type",o,s);return o}})}function r(e){return $({kind:"schema",type:"string",reference:r,expects:"string",async:!1,message:e,"~run"(t,o){return typeof t.value=="string"?t.typed=!0:M(this,"type",t,o),t}})}function Ut(e){let t;if(e)for(let o of e)if(t)for(let s of o.issues)t.push(s);else t=o.issues;return t}function d(e,t){return $({kind:"schema",type:"union",reference:d,expects:ct(e.map(o=>o.expects),"|"),async:!1,options:e,message:t,"~run"(o,s){let c,l,p;for(let h of this.options){let y=h["~run"]({value:o.value},s);if(y.typed)if(y.issues)l?l.push(y):l=[y];else{c=y;break}else p?p.push(y):p=[y]}if(c)return c;if(l){if(l.length===1)return l[0];M(this,"type",o,s,{issues:Ut(l)}),o.typed=!0}else{if(p?.length===1)return p[0];M(this,"type",o,s,{issues:Ut(p)})}return o}})}function Se(){return $({kind:"schema",type:"unknown",reference:Se,expects:"unknown",async:!1,"~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,"~run"(s,c){let l=s.value;if(l&&typeof l=="object"){let p,h=0,y=this.key,x=[],k=(T,W)=>{for(let V of T.options){if(V.type==="variant")k(V,new Set(W).add(V.key));else{let b=!0,N=0;for(let j of W){let H=V.entries[j];if(j in l?H["~run"]({typed:!1,value:l[j]},zt).issues:H.type!=="exact_optional"&&H.type!=="optional"&&H.type!=="nullish"){b=!1,y!==j&&(h<N||h===N&&j in l&&!(y in l))&&(h=N,y=j,x=[]),y===j&&x.push(V.entries[j].expects);break}N++}if(b){let j=V["~run"]({value:l},c);(!p||!p.typed&&j.typed)&&(p=j)}}if(p&&!p.issues)break}};if(k(this,new Set([this.key])),p)return p;M(this,"type",s,c,{input:l[y],expected:ct(x,"|"),path:[{type:"object",origin:"value",input:l,key:y,value:l[y]}]})}else M(this,"type",s,c);return s}})}function Lt(e,t){let o={...e.entries};for(let s of t)delete o[s];return $({...e,entries:o})}function ue(e,t,o){let s=e["~run"]({value:t},ut(o));if(s.issues)throw new Sn(s.issues);return s.value}function A(...e){return $({...e[0],pipe:e,"~run"(t,o){for(let s of e)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!o.abortEarly&&!o.abortPipeEarly)&&(t=s["~run"](t,o))}return t}})}function ie(e,t,o){let s=e["~run"]({value:t},ut(o));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}var fe=A(r(),me("NotionBlockId")),K=A(r(),me("NotionDataSourceId")),z=A(r(),me("NotionPageId")),Vt=A(r(),me("NotionAgentId")),Gt=A(r(),me("NotionSpaceId"));var $t=n({id:K,table:r(),spaceId:a(Gt)});var Qt=B(["default","gray","brown","orange","yellow","green","blue","purple","pink","red","gray_background","brown_background","orange_background","yellow_background","green_background","blue_background","purple_background","pink_background","red_background","default_background"]),vt=n({id:r(),name:r(),color:a(Qt),description:a(r())}),kn=n({id:r(),name:r(),color:a(Qt),option_ids:O(r())}),In=n({synced_property_id:r(),synced_property_name:r()}),D=n({name:r(),description:a(r())}),_n=["title","rich_text","number","checkbox","url","email","phone_number","select","multi_select","status","date","people","files","unique_id","relation","place","formula","rollup","button","verification","last_visited_time","location","created_time","last_edited_time","created_by","last_edited_by"],Wt=B(_n),Xt=["title","rich_text","number","checkbox","url","email","phone_number","date","created_time","last_edited_time","people","created_by"],Kt=v("type",[n({...D.entries,type:i("title")}),n({...D.entries,type:i("rich_text")}),n({...D.entries,type:i("number")}),n({...D.entries,type:i("checkbox")}),n({...D.entries,type:i("url")}),n({...D.entries,type:i("email")}),n({...D.entries,type:i("phone_number")}),n({...D.entries,type:i("select"),options:O(vt)}),n({...D.entries,type:i("multi_select"),options:O(vt)}),n({...D.entries,type:i("status"),options:O(vt),groups:O(kn)}),n({...D.entries,type:i("date")}),n({...D.entries,type:i("people")}),n({...D.entries,type:i("files")}),n({...D.entries,type:i("unique_id")}),n({...D.entries,type:i("relation"),data_source_id:a(r()),dual_property:a(In)}),n({...D.entries,type:i("place")}),n({...D.entries,type:i("formula")}),n({...D.entries,type:i("rollup")}),n({...D.entries,type:i("button")}),n({...D.entries,type:i("verification")}),n({...D.entries,type:i("last_visited_time")}),n({...D.entries,type:i("location")}),n({...D.entries,type:i("created_time")}),n({...D.entries,type:i("last_edited_time")}),n({...D.entries,type:i("created_by")}),n({...D.entries,type:i("last_edited_by")})]);var Zt={created_time:{type:"created_time",name:"Created time"},last_edited_time:{type:"last_edited_time",name:"Last edited time"},created_by:{type:"created_by",name:"Created by"},last_edited_by:{type:"last_edited_by",name:"Last edited by"}};var Jt=n({id:a(K),propertiesById:Q(r(),Kt)});var Yt=n({collectionPointer:a($t),collectionSchema:a(Jt),propertyIdsByKey:a(Q(r(),a(r()))),inaccessible:a(i(!0))});var ve=Q(r(),Yt);function er(e){let t=Object.entries(e.manifestDataSource.properties??{}).map(([o,s])=>{let c=e.propertyIdsByKey?.[o],l=c===void 0?void 0:e.collectionSchema?.propertiesById[c];return xn(o,c,l?.type,s.type)});return e.collectionSchema===void 0?{status:"missing_schema",properties:t}:t.every(o=>o.status==="mapped")?{status:"complete",properties:t}:{status:"incomplete",properties:t}}function xn(e,t,o,s){return t===void 0?{status:"missing",propertyKey:e,propertyId:t}:o===void 0?{status:"invalid",propertyKey:e,propertyId:t}:{status:o===s?"mapped":"incompatible",propertyKey:e,propertyId:t}}var $e=n({type:i("page_id"),page_id:z}),Qe=n({type:i("data_source_id"),data_source_id:K}),Cn=n({type:i("workspace"),workspace:i(!0)}),Pn=n({type:i("block_id"),block_id:fe}),En=n({type:i("agent_id"),agent_id:Vt}),On=n({type:i("unavailable")}),re=v("type",[$e,Qe,Cn,Pn,En,On]);var Ce=v("type",[n({type:i("unavailable")}),n({type:i("page"),id:z,parent:re})]);var Pe=B(["standard","high"]),tr="standard";var Ee=B(["light","dark"]);var rr=n({capability:r(),resource:r()});var Rn=v("type",[n({type:i("emoji"),emoji:r()}),n({type:i("external"),url:r()})]),Bn=n({name:r(),description:a(r()),type:Wt}),jn=n({name:r(),description:a(r()),icon:a(Rn),properties:a(Q(r(),Bn),{})}),he=n({version:i(1),name:a(r()),description:a(r()),slashCommand:a(r()),icon:a(n({type:i("emoji"),emoji:r()})),dataSources:a(Q(r(),jn),{}),capabilities:a(O(rr))});var We=A(r(),me("NotionUserId"));var ce=n({object:i("user"),id:We,name:a(r()),avatar_url:q(r()),type:i("person"),person:n({email:r()})});var Mn=r(),Fe=n({code:Mn,message:r(),isRetryable:g()}),Ue=class extends Error{constructor(t){super(t.message),this.name="CustomBlockInitializationError",this.code=t.code,this.isRetryable=t.isRetryable}code;isRetryable},Xe=v("status",[n({type:i("init"),initializationId:r(),status:i("success"),theme:Ee,contrastMode:Pe,blockId:fe,parent:re,page:Ce,manifest:he,dataSources:n({bindings:ve}),currentUser:ce}),n({type:i("init"),initializationId:r(),status:i("error"),error:Fe})]);var or=n({type:i("contrastModeChanged"),contrastMode:Pe});var nr=n({type:i("pageChanged"),page:Ce});var ir=n({type:i("parentChanged"),parent:re});var sr=n({type:i("themeChanged"),theme:Ee});var ar=n({type:i("dataSourcesChanged"),dataSources:n({bindings:ve})});var Ke=n({unit:B(["year","month","week","day"]),value:R(),time:r(),defaultTimeZone:a(r())}),Dn=n({unit:B(["hour","minute"]),value:R()}),ze=n({unit:i("none")}),ht=d([Ke,Dn]),ur=a(d([Ke,ze])),cr=a(d([ht,ze])),wn=n({type:i("date"),start_date:r(),reminder:ur}),Tn=n({type:i("daterange"),start_date:r(),end_date:r(),reminder:ur}),qn=n({type:i("datetime"),start_date:r(),start_time:r(),time_zone:a(r()),reminder:cr}),An=n({type:i("datetimerange"),start_date:r(),start_time:r(),end_date:r(),end_time:r(),time_zone:a(r()),reminder:cr}),lr=v("type",[wn,Tn,qn,An]);var Ze=n({id:r(),table:r()});var pr=d([r(),R(),g(),lr,O(r()),O(Ze)]);var mr=n({id:z,is_archived:g(),in_trash:g(),propertiesById:Q(r(),a(pr))});var Nn=r(),Un=B(["gray","lightgray","brown","yellow","orange","green","blue","purple","pink","red"]),gt=d([Un,r()]),bt=Ge({type:i("icon"),icon:Ge({name:Nn,color:a(gt)})});var fr=n({type:i("emoji"),emoji:r()}),yr=n({type:i("custom_emoji"),custom_emoji:n({id:r(),name:a(r()),url:a(r())})}),St=n({type:i("external"),external:n({url:r()})}),kt=n({type:i("file"),file:n({url:r(),expiry_time:a(r())})}),Oe=v("type",[bt,fr,yr,St,kt]),ge=v("type",[St,kt]),dr=v("type",[bt,fr,yr,St,kt]);var L=q(r());var It={start:r(),end:a(L),time_zone:a(L),reminder:a(d([ht,ze]))},vr=d([n({...It,start:A(r(),lt("T"))}),n({...It,time_zone:r()}),n({...It,reminder:a(d([Ke,ze]))})]);var hr=d([n({type:i("external"),name:r(),external:n({url:r()})}),n({type:i("file"),name:r(),file:n({url:r(),expiry_time:a(r())})})]);var Re=q(n({...Ze.entries,table:B(["notion_user","bot","organization_bot"]),spaceId:a(r())}));var gr=n({lat:R(),lon:R(),name:a(L),address:a(L),aws_place_id:a(L),google_place_id:a(L)});var br=n({id:r()});var _t=Q(r(),Se());var Je=d([n({id:r(),name:a(r()),color:a(r()),description:a(L)}),n({name:r(),id:a(r()),color:a(r()),description:a(L)})]);var Sr=d([n({object:a(i("user")),id:r()}),n({object:i("group"),id:r(),name:a(L)})]);var w={id:r()},xt=v("type",[n({...w,type:i("title"),title:O(_t)}),n({...w,type:i("rich_text"),rich_text:O(_t)}),n({...w,type:i("number"),number:q(R())}),n({...w,type:i("url"),url:L}),n({...w,type:i("email"),email:L}),n({...w,type:i("phone_number"),phone_number:L}),n({...w,type:i("checkbox"),checkbox:g()}),n({...w,type:i("select"),select:q(Je)}),n({...w,type:i("status"),status:q(Je)}),n({...w,type:i("multi_select"),multi_select:O(Je)}),n({...w,type:i("date"),date:q(vr)}),n({...w,type:i("people"),people:O(Sr)}),n({...w,type:i("relation"),has_more:a(g()),relation:O(br)}),n({...w,type:i("files"),files:O(hr)}),n({...w,type:i("place"),place:q(gr)}),n({...w,type:i("created_time"),created_time:L}),n({...w,type:i("last_edited_time"),last_edited_time:L}),n({...w,type:i("created_by"),created_by:Re}),n({...w,type:i("last_edited_by"),last_edited_by:Re}),n({...w,type:i("last_visited_time"),last_visited_time:L}),n({...w,type:i("unique_id"),unique_id:r()}),n({...w,type:i("button"),button:r()}),n({...w,type:i("formula"),formula:r()}),n({...w,type:i("location"),location:r()}),n({...w,type:i("rollup"),rollup:r()}),n({...w,type:i("verification"),verification:r()})]);var Be=Q(r(),xt),kr=Q(r(),q(xt));var oe=n({object:i("page"),id:z,parent:re,properties:kr,created_by:a(Re,null),last_edited_by:a(Re,null),last_visited_time:a(q(r()),null),created_time:a(q(r()),null),last_edited_time:a(q(r()),null),icon:a(q(Oe),null),cover:a(q(ge),null),url:a(q(r()),null),public_url:a(q(r()),null),is_archived:g(),in_trash:g()});var Ir=d([m({equals:g()}),m({does_not_equal:g()})]);var le=d([m({is_empty:i(!0)}),m({is_not_empty:i(!0)})]);var ke=d([r(),O(r())]);var _r=d([m({contains:ke}),m({contains_all:ke}),m({does_not_contain:ke}),le]);var xr=m({object:i("user"),id:A(r(),be(1),qe(2e3))}),Cr=d([m({contains:xr}),m({does_not_contain:xr}),m({is_empty:i(!0)}),m({is_not_empty:i(!0)})]);var Z=B(["start_date","end_date"]),Fn=B(["today","tomorrow","yesterday","one_week_ago","one_week_from_now","one_month_ago","one_month_from_now"]),He=d([Fn,r()]),Pr=d([m({target:a(Z),equals:He}),m({target:a(Z),before:He}),m({target:a(Z),after:He}),m({target:a(Z),on_or_before:He}),m({target:a(Z),on_or_after:He}),m({target:a(Z),this_week:m({})}),m({target:a(Z),past_week:m({})}),m({target:a(Z),past_month:m({})}),m({target:a(Z),past_year:m({})}),m({target:a(Z),next_week:m({})}),m({target:a(Z),next_month:m({})}),m({target:a(Z),next_year:m({})}),m({target:a(Z),is_empty:i(!0)}),m({target:a(Z),is_not_empty:i(!0)})]);var Er=d([m({equals:R()}),m({does_not_equal:R()}),m({greater_than:R()}),m({less_than:R()}),m({greater_than_or_equal_to:R()}),m({less_than_or_equal_to:R()}),le]);var Ye=d([m({equals:ke}),m({does_not_equal:ke}),le]);var Or=m({object:B(["user","group"]),id:A(r(),be(1))}),Rr=d([m({contains:Or}),m({does_not_contain:Or}),le]);var Br=A(z,pt(/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})$/i),mt(e=>e.replaceAll("-","").toLowerCase().replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5"))),et=d([m({contains:Br}),m({does_not_contain:Br}),m({is_empty:i(!0)}),m({is_not_empty:i(!0)})]);var jr=B(["To-do","In progress","Complete","Current","Future"]),Mr=d([jr,A(O(jr),be(1),qe(5))]),Dr=d([m({group_equals:Mr}),m({group_does_not_equal:Mr})]);var wr=d([Ye,Dr]);var je=d([m({equals:r()}),m({does_not_equal:r()}),m({contains:r()}),m({does_not_contain:r()}),m({starts_with:r()}),m({ends_with:r()}),le]);var Ct=d([m({propertyId:r(),relation:et}),m({propertyId:r(),created_by:Cr}),m({propertyId:r(),title:je}),m({propertyId:r(),rich_text:je}),m({propertyId:r(),url:je}),m({propertyId:r(),email:je}),m({propertyId:r(),phone_number:je}),m({propertyId:r(),number:Er}),m({propertyId:r(),checkbox:Ir}),m({propertyId:r(),select:Ye}),m({propertyId:r(),multi_select:_r}),m({propertyId:r(),status:wr}),m({propertyId:r(),date:Pr}),m({propertyId:r(),people:Rr})]);var Tr=d([Ct,m({and:O(Ct)})]);var qr=B(["ascending","descending"]);var Pt=10,Ar=m({propertyId:r(),direction:qr});var Nr=n({type:i("queryDataSource"),subscriptionId:r(),dataSourceId:K,limit:R(),filter:a(Tr),sorts:a(O(Ar))}),zn=r(),Ur=n({code:zn,message:r(),isRetryable:g()}),Fr=v("status",[n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:O(oe),hasMore:g()}),n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:Ur})]),zr=v("status",[n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("success"),items:O(d([oe,mr])),hasMore:g()}),n({type:i("queryDataSourceResult"),subscriptionId:r(),status:i("error"),error:Ur})]);var Hn=r(),Ln=n({code:Hn,message:r(),isRetryable:g()}),Hr=n({type:i("openExternalUrl"),requestId:r(),url:r()}),Lr=v("status",[n({type:i("openExternalUrlResult"),requestId:r(),status:i("success")}),n({type:i("openExternalUrlResult"),requestId:r(),status:i("error"),error:Ln})]);var Me=n({object:i("page"),id:z,parent:re,properties:Be,created_time:a(r()),last_edited_time:a(r()),icon:a(Oe),cover:a(ge),url:a(r()),public_url:a(r()),is_archived:g(),in_trash:g()});var Vn=r(),Gr=n({code:Vn,message:r(),isRetryable:g()}),$r=v("status",[n({type:i("createPageResult"),requestId:r(),status:i("success"),page:oe}),n({type:i("createPageResult"),requestId:r(),status:i("error"),error:Gr})]),Qr=v("status",[n({type:i("createPageResult"),requestId:r(),status:i("success"),page:d([oe,Me])}),n({type:i("createPageResult"),requestId:r(),status:i("error"),error:Gr})]),Gn=v("type",[n({type:i("start")}),n({type:i("end")}),n({type:i("before"),blockId:fe}),n({type:i("after"),blockId:fe})]),fu=v("type",[$e,Qe]),Vr={type:i("createPage"),requestId:r(),properties:Be,icon:a(dr),cover:a(ge)},Wr=v("type",[n({...Vr,parent:$e,position:a(Gn)}),n({...Vr,parent:Qe,position:a(dt())})]);var $n=r(),Xr=n({code:$n,message:r(),isRetryable:g()}),Kr=n({type:i("getPage"),requestId:r(),pageId:z,dataSourceId:a(K)}),Zr=v("status",[n({type:i("getPageResult"),requestId:r(),status:i("success"),page:oe}),n({type:i("getPageResult"),requestId:r(),status:i("error"),error:Xr})]),Jr=v("status",[n({type:i("getPageResult"),requestId:r(),status:i("success"),page:d([oe,Me])}),n({type:i("getPageResult"),requestId:r(),status:i("error"),error:Xr})]);var Qn=B(["side_peek","center_peek"]),Wn=r(),Xn=n({code:Wn,message:r(),isRetryable:g()}),Yr=n({type:i("openPage"),requestId:r(),pageId:z,mode:Qn}),eo=v("status",[n({type:i("openPageResult"),requestId:r(),status:i("success"),pageId:z}),n({type:i("openPageResult"),requestId:r(),status:i("error"),error:Xn})]);var Kn=r(),to=n({code:Kn,message:r(),isRetryable:g()}),ro=v("status",[n({type:i("updatePageResult"),requestId:r(),status:i("success"),page:oe}),n({type:i("updatePageResult"),requestId:r(),status:i("error"),error:to})]),oo=v("status",[n({type:i("updatePageResult"),requestId:r(),status:i("success"),page:d([oe,Me])}),n({type:i("updatePageResult"),requestId:r(),status:i("error"),error:to})]),no=n({type:i("updatePage"),requestId:r(),pageId:z,dataSourceId:a(K),properties:a(Be),icon:a(Oe),cover:a(ge),archived:a(g())});var io=n({type:i("currentUserChanged"),currentUser:ce});var Zn=r(),Jn=n({code:Zn,message:r(),isRetryable:g()}),so=n({type:i("getUser"),requestId:r(),userId:We}),ao=v("status",[n({type:i("getUserResult"),requestId:r(),status:i("success"),user:ce}),n({type:i("getUserResult"),requestId:r(),status:i("error"),error:Jn})]);var uo=n({object:i("list"),results:O(ce),next_cursor:q(r()),has_more:g(),type:i("user"),user:Q(r(),Se())});var Yn=r(),ei=n({code:Yn,message:r(),isRetryable:g()}),co=n({type:i("listUsers"),requestId:r(),startCursor:a(r()),pageSize:a(R())}),lo=v("status",[n({type:i("listUsersResult"),requestId:r(),status:i("success"),list:uo}),n({type:i("listUsersResult"),requestId:r(),status:i("error"),error:ei})]);var po=n({type:i("invalidSandboxMessage"),requestId:a(r()),reason:r()});var mo=v("type",[Xe,sr,or,ir,nr,io,ar,ao,lo,eo,Lr,po]),fo=v("type",[...mo.options,Fr,Zr,$r,ro]),Yu=v("type",[...mo.options,zr,Jr,Qr,oo]);function yo(e){return{...e,dataSources:{bindings:Object.fromEntries(Object.entries(e.dataSources.bindings).map(([t,o])=>[t,{...o,collectionSchema:{...o.collectionSchema,propertiesById:{...o.collectionSchema?.propertiesById,...Zt}}}]))}}}function Y(e){throw new Error(`[custom-blocks-host] Unexpected value encountered: ${JSON.stringify(e)}`)}function tt(e){return{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([t,o])=>{switch(o?.type){case"unique_id":case"button":case"formula":case"location":case"rollup":case"verification":return[t,null];case"title":case"rich_text":case"number":case"url":case"email":case"phone_number":case"checkbox":case"select":case"status":case"multi_select":case"date":case"people":case"relation":case"files":case"place":case"created_time":case"last_edited_time":case"created_by":case"last_edited_by":case"last_visited_time":case void 0:return[t,o];default:return Y(o)}}))}}function De(e){if(e?.type!=="icon")return e;let{name:t,color:o}=e.icon;return{type:"external",external:{url:`https://www.notion.so/icons/${t}_${o??"gray"}.svg`}}}function vo(e){return{...e,properties:Object.fromEntries(Object.values(e.properties).flatMap(t=>t?[[t.id,t]]:[])),icon:De(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 Ie(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"}}var _e=class extends Error{};function Et(e){try{return ti(e)}catch(t){throw t instanceof RangeError?new _e(t.message):t}}function ti(e){let{start:t,end:o,time_zone:s,reminder:c}=e;if(!t.split("T")[0])throw new _e("Date values must include a date.");let l=t.includes("T")||s!=null,p=t.match(/([+-])(\d{2}):(\d{2})$/),h=p?(Number(p[2])*60+Number(p[3]))*(p[1]==="-"?-1:1):0,y=s?.match(/^UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?$/),x=y?(Number(y[2]??0)*60+Number(y[3]??0))*(y[1]==="-"?-1:1):h,k=b=>{if(!b.split("T")[0])throw new _e("Date values must include a date.");if(!b.includes("T"))return{date:b,time:"00:00"};let N=b.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?$/);if(N)return{date:N[1],time:N[2]};if(!s||y){let U=new Date(new Date(b).getTime()+x*6e4).toISOString();return{date:U.slice(0,10),time:U.slice(11,16)}}let j=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(b)),H=U=>j.find(ee=>ee.type===U)?.value;return{date:`${H("year")}-${H("month")}-${H("day")}`,time:`${H("hour")}:${H("minute")}`}},T=k(t),W=o?k(o):void 0;if(!l){if(c&&!("time"in c)&&c.unit!=="none")throw new _e("Hour and minute reminders require a date with a time.");return W?{type:"daterange",start_date:T.date,end_date:W.date,reminder:c}:{type:"date",start_date:T.date,reminder:c}}let V=s??(h===0?"UTC":`UTC${h<0?"-":"+"}${Math.floor(Math.abs(h)/60)}${Math.abs(h)%60===0?"":`:${String(Math.abs(h)%60).padStart(2,"0")}`}`);return W?{type:"datetimerange",start_date:T.date,start_time:T.time,end_date:W.date,end_time:W.time,time_zone:V,reminder:c}:{type:"datetime",start_date:T.date,start_time:T.time,time_zone:V,reminder:c}}function go(e){switch(e.type){case"title":return ho(e.title);case"rich_text":return ho(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?Et(e.date):void 0;case"people":return e.people.map(t=>t.object==="group"?{id:t.id,table:"space_permission_group",spaceId:t.id.split("|")[1]}:{id:t.id,table:"notion_user"});case"relation":return e.relation.map(t=>({id:t.id,table:"block"}));case"files":return e.files.map(t=>t.name).join(",");case"unique_id":return e.unique_id;case"button":return e.button;case"formula":return e.formula;case"location":return e.location;case"rollup":return e.rollup;case"verification":return e.verification;case"place":return"";case"created_time":return Ie(e.created_time);case"last_edited_time":return Ie(e.last_edited_time);case"last_visited_time":return Ie(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 Y(e)}}function ho(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 bo(e){let t={};for(let o of Object.values(e.properties))o&&(t[o.id]=go(o));return{id:e.id,is_archived:e.is_archived,in_trash:e.in_trash,propertiesById:{...t,created_time:Ie(e.created_time),last_edited_time:Ie(e.last_edited_time),created_by:e.created_by?[e.created_by]:void 0,last_edited_by:e.last_edited_by?[e.last_edited_by]:void 0}}}function So(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(bo)}:{...e,page:vo(tt(e.page))}}function Io(e){return e.type==="queryDataSourceResult"?{...e,items:e.items.map(ko)}:{...e,page:ko(e.page)}}function ko(e){return{...tt(e),icon:De(e.icon)}}function xo(e){if(e.type==="queryDataSourceResult")return e.items.some(o=>o.icon?.type==="icon")?{...e,items:e.items.map(_o)}:e;let t=_o(e.page);return t===e.page?e:{...e,page:t}}function _o(e){let t=De(e.icon);return t===e.icon?e:{...e,icon:t}}function Co(e,t){return e.type==="init"&&e.status==="success"||e.type==="dataSourcesChanged"?t<5?yo(e):e:e.type!=="queryDataSourceResult"&&e.type!=="getPageResult"&&e.type!=="createPageResult"&&e.type!=="updatePageResult"||e.status==="error"?e:t<6?So(e):t<7?Io(e):t<9?xo(e):e}var Ot=n({theme:Ee,contrastMode:a(Pe),blockId:fe,parent:re,page:Ce,manifest:he,dataSources:n({bindings:ve}),currentUser:ce}),Po=v("status",[n({status:i("success"),initialState:Lt(Ot,["manifest"])}),n({status:i("error"),error:Fe})]);var rt=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=[],s=!1;for(let c of this.bySubscriptionId.values())if(c.message.dataSourceId===t){if(s=!0,c.isRefreshing){c.shouldRefreshAgain=!0;continue}c.isRefreshing=!0,o.push({message:c.message,token:c.token})}return s?o:void 0}finish(t,o){let s=this.bySubscriptionId.get(t);if(s?.token===o&&(s.isRefreshing=!1,!!s.shouldRefreshAgain))return s.shouldRefreshAgain=!1,s.isRefreshing=!0,{message:s.message,token:s.token}}unsubscribeAll(){for(let t of this.bySubscriptionId.keys())this.unsubscribe(t)}};function Eo(e,t){if(e===void 0)return;let o="and"in e?e.and:[e];for(let s of o){let c=ii(s,t);if(c!==void 0)return c}}function ii(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],s=Object.keys(e).find(h=>h!=="propertyId");if(s!==o.type)return{code:"invalid_data_source_query_filter",message:`Data source query filter branch "${s}" does not match property type "${o.type}".`,isRetryable:!1};if("status"in e&&o.type==="status"){let h=e.status;if("group_equals"in h||"group_does_not_equal"in h){let y="group_equals"in h?h.group_equals:h.group_does_not_equal,k=(Array.isArray(y)?y:[y]).find(T=>!o.groups.some(W=>W.name===T));return k===void 0?void 0:{code:"invalid_data_source_query_filter",message:`Unknown status group "${k}".`,isRetryable:!1}}}if("relation"in e&&!Ht(et,e.relation))return{code:"invalid_data_source_query_filter",message:"Relation filters require a page ID.",isRetryable:!1};let c=si(e);if(c===void 0||o.type!==c.propertyType)return;let l=new Set(o.options.map(h=>h.name)),p=ai(c.operator).find(h=>!l.has(h));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 si(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 ai(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?[]:Y(e);return Array.isArray(t)?t:[t]}var ui=new Set(Xt);function Oo(e,t){if(e===void 0)return;if(e.length>Pt)return{code:"invalid_data_source_query_sort",message:`Data source query sorts may contain at most ${Pt} entries.`,isRetryable:!1};let o=new Set;for(let s of e){if(o.has(s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sorts cannot contain duplicate property ID "${s.propertyId}".`,isRetryable:!1};if(o.add(s.propertyId),!Object.hasOwn(t.propertiesById,s.propertyId))return{code:"invalid_data_source_query_sort",message:`Data source query sort property ID "${s.propertyId}" is not defined in the bound data source schema.`,isRetryable:!1};let c=t.propertiesById[s.propertyId];if(!ui.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}}}function Ro(){return{code:"initial_state_timeout",message:"Host did not prepare initial state before the timeout.",isRetryable:!0}}function Rt(e){let{currentBridgeProtocolVersion:t}=e;return{code:"invalid_protocol_version",message:`Sandbox reported an invalid bridge protocol version: ${t}`,isRetryable:!1}}function Bo(){return{code:"no_connect",message:"Sandbox did not send a connect message.",isRetryable:!0}}function jo(){return{code:"no_init_result",message:"Sandbox did not acknowledge initialization.",isRetryable:!0}}function ot(){return{code:"unknown_error",message:"Unexpected error while initializing custom block.",isRetryable:!1}}function Bt(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 jt(e){return Number.isFinite(e)&&Number.isInteger(e)&&e>=1}var ci=5e3,li=5e3,pi=5e3;function Mo(e){let{manifestSource:t,prepareInit:o,sendInitMessage:s,warn:c,flushPendingHostStateChanges:l,minBridgeProtocolVersion:p,noConnectTimeoutMs:h=ci,initialStateTimeoutMs:y=li,noInitResultTimeoutMs:x=pi,stopHostWithFailure:k,onInitResult:T,onInitSent:W,onConnectionFailure:V}=e,b="waitingForConnect",N,j,H,U,ee=!1,ye=!1;function te(){N!==void 0&&(window.clearTimeout(N),N=void 0)}function F(){j!==void 0&&(window.clearTimeout(j),j=void 0)}function G(){H!==void 0&&(window.clearTimeout(H),H=void 0)}function X(I){let{initializationId:P,error:_,phase:ae,source:it}=I;switch(b){case"waitingForConnect":case"preparingInit":break;case"waitingForInitResult":case"initialized":case"failed":case"stopped":return;default:return Y(b)}b="failed",U=P,te(),F(),s({type:"init",initializationId:P,status:"error",error:_}),V({..._,phase:ae,source:it})}async function se(I){if(b==="waitingForConnect"){b="preparingInit",U=I.initializationId,te(),j=window.setTimeout(()=>{if(b!=="preparingInit")return;let P=Ro();c({...P,initializationId:I.initializationId}),X({initializationId:I.initializationId,error:P,phase:"init",source:"host"})},y);try{let P=await o(I);if(b!=="preparingInit")return;if(F(),P.status==="error"){X({initializationId:I.initializationId,error:P.error,phase:"init",source:"host"});return}b="waitingForInitResult";let _={type:"init",initializationId:I.initializationId,status:"success",theme:P.initialState.theme,contrastMode:P.initialState.contrastMode??tr,blockId:P.initialState.blockId,parent:P.initialState.parent,page:P.initialState.page,currentUser:P.initialState.currentUser,manifest:P.initialState.manifest,dataSources:P.initialState.dataSources};if(s(_),b!=="waitingForInitResult"||(W(),b!=="waitingForInitResult"))return;H=window.setTimeout(()=>{if(b!=="waitingForInitResult")return;b="failed";let ae=jo();V({...ae,phase:"initResult",source:"host"}),c({...ae,initializationId:I.initializationId})},x)}catch(P){if(b!=="preparingInit")return;c({message:"Failed to prepare custom block initialization",error:P}),X({initializationId:I.initializationId,error:ot(),phase:"init",source:"host"})}}}function J(I){if(b!=="stopped"&&b==="waitingForConnect"){if(!jt(I.bridgeProtocolVersion)){let P=Rt({currentBridgeProtocolVersion:I.bridgeProtocolVersion});X({initializationId:I.initializationId,error:P,phase:"connect",source:"host"});return}if(I.bridgeProtocolVersion<p){let P=Bt({currentBridgeProtocolVersion:I.bridgeProtocolVersion,minBridgeProtocolVersion:p});X({initializationId:I.initializationId,error:P,phase:"connect",source:"host"});return}if(I.status==="error"&&(t==="sandbox"||I.error.code!=="manifest_invalid")){X({initializationId:I.initializationId,error:I.error,phase:"connect",source:"sandbox"});return}ye=!0,se(I)}}function C(I){if(b==="stopped"||b!=="waitingForConnect")return"handled";let{initializationId:P,bridgeProtocolVersion:_}=I;if(P===void 0)return"nack";let ae=I.error;return _!==void 0&&(jt(_)?_<p&&(ae=Bt({currentBridgeProtocolVersion:_,minBridgeProtocolVersion:p})):ae=Rt({currentBridgeProtocolVersion:_})),X({initializationId:P,error:ae,phase:"connect",source:"host"}),"handled"}function ne(I){let{initializationId:P,error:_}=I;b!=="waitingForInitResult"||P===void 0||P!==U||(te(),G(),b="failed",c(_),V({..._,phase:"initResult",source:"host"}))}function Le(){if(b!=="stopped"){if(ee){k({phase:"runtime",source:"host",code:"iframe_reloaded",message:"The iframe reloaded. Create a new host and iframe to reconnect.",isRetryable:!0});return}ee=!0,te(),b==="waitingForConnect"&&(N=window.setTimeout(()=>{if(b!=="waitingForConnect")return;b="failed";let I=Bo();c(I),V({...I,phase:"connect",source:"host"})},h))}}function we(I){if(b!=="waitingForInitResult"||I.initializationId!==U){c({message:"Ignored stale or unexpected initResult",payload:I});return}G(),b=I.status==="success"?"initialized":"failed",I.status==="success"?l():V({...I.error,phase:"initResult",source:"sandbox"}),T(I)}function de(){b="stopped",te(),F(),G()}return{get status(){return b},get hasConnectedSandbox(){return ye},handleConnect:J,handleInitResult:we,handleInvalidConnect:C,handleInvalidInitResult:ne,onIframeLoad:Le,stop:de}}function Mt(){return{code:"context_unavailable",message:"Host page context is unavailable.",isRetryable:!0}}function Dt(){return{code:"invalid_local_preview_url",message:"Local custom blocks require an HTTP(S) URL on localhost, a .localhost subdomain, or 127.0.0.1, without credentials and on a different origin from the host.",isRetryable:!1}}function Do(){return{code:"invalid_property_binding",message:"A mapped data source property is missing or incompatible.",isRetryable:!1}}function wo(){return{code:"missing_data_source_binding",message:"A required data source is not mapped.",isRetryable:!1}}function To(){return{code:"missing_property_binding",message:"A required data source property is not mapped.",isRetryable:!1}}function qo(e){return(e.protocol==="http:"||e.protocol==="https:")&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname.endsWith(".localhost"))&&e.username===""&&e.password===""}function nt({url:e,hostOrigin:t}){return typeof t=="string"&&t!==""&&e.origin!==t&&qo(e)}async function Ao(e){return e.manifestSource==="host"?e.hostManifest:e.connectManifest!==void 0?{status:"success",manifest:e.connectManifest}:{status:"error",error:{code:"manifest_unavailable",message:"The sandbox did not provide a manifest in connect.",isRetryable:!1}}}var No=v("status",[n({status:i("success"),manifest:he}),n({status:i("error"),error:Fe})]);function Uo(e){switch(e.type){case"connect":case"init":case"initResult":return!0;default:return!1}}var Fo=n({type:i("resize"),height:A(R(),Te(),Ae(0))});var zo=n({type:i("unsubscribeDataSourceQuery"),subscriptionId:r()});var Ho=n({code:r(),message:r(),isRetryable:g()});var Lo={type:i("connect"),initializationId:r(),bridgeProtocolVersion:R(),sdkVersion:r()},Vo=v("status",[n({status:i("success"),manifest:a(he),...Lo}),n({status:i("error"),error:Ho,...Lo})]);var mi=r(),fi=n({code:mi,message:r(),isRetryable:g()}),Go=v("status",[n({type:i("initResult"),initializationId:r(),status:i("success"),initialHeight:a(A(R(),Te(),Ae(0)))}),n({type:i("initResult"),initializationId:r(),status:i("error"),error:fi})]);var $o=n({type:i("invalidHostMessage"),requestId:a(r()),reason:r()});var Qo=v("type",[Vo,Go,Nr,zo,Wr,Kr,so,co,Yr,Hr,no,Fo,$o]);function Wo(e){return ie(Qo,e)}function Xo(){return{code:"invalid_connect_payload",message:"Sandbox sent an invalid connect message.",isRetryable:!1}}function Ko(){return{code:"invalid_init_result_payload",message:"Sandbox sent an invalid initialization result.",isRetryable:!1}}function Zo(e){if(typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string")return e.type}var yi=n({requestId:r()});function Jo(e){let t=ie(yi,e);return t.success?t.output.requestId:void 0}function Yo(e){let t=Zo(e);if(t==="invalidHostMessage"||t==="invalidSandboxMessage")return{incomingType:t};let o=Jo(e);return{incomingType:t,nack:{type:"invalidSandboxMessage",...o!==void 0?{requestId:o}:{},reason:di(t)}}}function di(e){return e!==void 0?`Unsupported sandbox message of type "${e}"`:"Unsupported sandbox message (no `type` field or non-object payload)"}var vi=n({type:B(["updatePage","createPage"]),requestId:r(),icon:n({type:i("icon"),icon:n({color:Se()})})});function en(e){let t=ie(vi,e);if(!t.success)return;let o=t.output.icon.icon.color;if(!(o===void 0||ie(gt,o).success))return{type:t.output.type==="createPage"?"createPageResult":"updatePageResult",requestId:t.output.requestId,status:"error",error:{code:"invalid_icon_color",message:"Use a supported Notion icon color.",isRetryable:!1}}}var tn=n({initializationId:r()}),hi=n({bridgeProtocolVersion:d([R(),yt()])});function rn(e){let{iframe:t,sandboxOrigin:o,getInitStatus:s,emit:c,sendNack:l,sendPageMutationError:p,onInvalidConnect:h,onInvalidInitResult:y,onConnect:x,onInitResult:k,onQueryDataSource:T,onUnsubscribeDataSourceQuery:W,onCreatePage:V,onGetPage:b,onOpenPage:N,onOpenExternalUrl:j,onGetUser:H,onListUsers:U,onUpdatePage:ee,onResize:ye}=e;function te(F,G){let X=en(F);if(X!==void 0&&s()==="initialized"){p(X);return}c("warn",{message:"Ignored unsupported sandbox message",payload:wt(F),issues:G});let se=Yo(F);if(se.incomingType==="connect"){let J=ie(tn,F),C=ie(hi,F);if(h({initializationId:J.success?J.output.initializationId:void 0,error:Xo(),bridgeProtocolVersion:C.success?C.output.bridgeProtocolVersion:void 0})==="handled")return}if(se.incomingType==="initResult"){let J=ie(tn,F);y({initializationId:J.success?J.output.initializationId:void 0,error:Ko()})}se.nack!==void 0&&s()!=="stopped"&&l(se.nack)}return function(G){let X=G.source===t.contentWindow,se=G.origin===o;if(!X||!se)return;let J=Wo(G.data);if(!J.success){te(G.data,J.issues);return}let C=J.output;if(!Uo(C)&&s()!=="initialized"){c("warn",{message:`Ignored ${C.type} before initialization completed`,payload:wt(C)});return}switch(c("in",wt(C)),C.type){case"connect":x(C);return;case"initResult":k(C);return;case"queryDataSource":T(C);return;case"unsubscribeDataSourceQuery":W(C);return;case"createPage":V(C);return;case"openPage":N(C);return;case"openExternalUrl":j(C);return;case"getPage":b(C);return;case"getUser":H(C);return;case"listUsers":U(C);return;case"updatePage":ee(C);return;case"resize":ye(C);return;case"invalidHostMessage":return;default:Y(C)}}}function wt(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="openExternalUrl"?{type:"openExternalUrl",..."requestId"in e?{requestId:e.requestId}:{}}:e}function on(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}var sn=5;function bi(e){let{iframe:t,prepareInitialState:o,handlers:s,onStatusChange:c,onLog:l,onQueryUnsubscribed:p,minBridgeProtocolVersion:h,noConnectTimeoutMs:y,initialStateTimeoutMs:x,noInitResultTimeoutMs:k}=e,T=Si(e.sandboxUrl,e.manifestSource),W=T.origin,V=Math.max(h??3,3),b=new AbortController,N,j={},H=!1,U=new AbortController,ee,ye,te=9,F=new rt(u=>{p?.(u)});function G(u,S){l?.(u,S)}function X(u){let S=_.status;switch(S){case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"initialized":case"failed":break;case"stopped":return;default:return Y(S)}let E=Co(u,te);G("out",E),t.contentWindow?.postMessage(E,W)}function se(u){X(ue(Xe,u))}function J(u){X(u)}function C(u){let S=_.status;switch(S){case"initialized":X(ue(fo,u));return;case"waitingForConnect":case"preparingInit":case"waitingForInitResult":case"failed":case"stopped":return;default:Y(S)}}async function ne(u,S){try{let E=S===void 0?Ii(u.type):await S(u);C({...E,type:`${u.type}Result`,requestId:u.requestId})}catch(E){if(_.status!=="initialized")return;G("warn",E),C({type:`${u.type}Result`,requestId:u.requestId,status:"error",error:{code:"unknown_error",message:`The host could not complete ${u.type}.`,isRetryable:!1}})}}function Le(u){let S=u.response.status==="error"?{type:"queryDataSourceResult",subscriptionId:u.subscriptionId,status:"error",error:u.response.error}:{type:"queryDataSourceResult",subscriptionId:u.subscriptionId,status:"success",items:u.response.items,hasMore:u.response.hasMore};C(S)}async function we(u,S=F.subscribe(u)){try{let E=ki(ye,u.dataSourceId),pe=_i(u,E);if(pe!==void 0){F.isCurrent(u.subscriptionId,S)&&(F.unsubscribe(u.subscriptionId),Le({subscriptionId:u.subscriptionId,response:{status:"error",error:pe}}));return}let at=await s.queryDataSource(u);if(!F.isCurrent(u.subscriptionId,S))return;at.status==="error"&&!at.error.isRetryable&&F.unsubscribe(u.subscriptionId),Le({subscriptionId:u.subscriptionId,response:at})}finally{let E=F.finish(u.subscriptionId,S);E!==void 0&&we(E.message,E.token)}}function de(u){_.status==="stopped"||_.status==="failed"||(Object.assign(j,u),P())}async function I(u){if(b.signal.aborted)return;let S=s.openExternalUrl;if(S===void 0){await ne(u,void 0);return}if(N===u.requestId)return;if(N!==void 0){let pe={type:"openExternalUrlResult",requestId:u.requestId,status:"error",error:{code:"pending_navigation",message:"Another external navigation request is pending.",isRetryable:!0}};C(pe);return}let E=on(u.url);if(E===void 0){let pe={type:"openExternalUrlResult",requestId:u.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}};C(pe);return}N=u.requestId;try{await ne(u,()=>S({...u,url:E},{signal:b.signal}))}finally{N===u.requestId&&(N=void 0)}}function P(){if(_.status!=="initialized")return;let u=j;j={},u.theme!==void 0&&C({type:"themeChanged",theme:u.theme}),u.contrastMode!==void 0&&C({type:"contrastModeChanged",contrastMode:u.contrastMode}),u.parent!==void 0&&C({type:"parentChanged",parent:u.parent}),u.page!==void 0&&C({type:"pageChanged",page:u.page}),u.dataSources!==void 0&&C({type:"dataSourcesChanged",dataSources:u.dataSources}),u.currentUser!==void 0&&C({type:"currentUserChanged",currentUser:u.currentUser})}let _=Mo({manifestSource:e.manifestSource,async prepareInit(u){let S=u.status==="success"?u.manifest:void 0;te=u.bridgeProtocolVersion,c({status:"preparingInit",localManifest:nt({url:T,hostOrigin:window.location.origin})?S:void 0,bridgeProtocolVersion:u.bridgeProtocolVersion,sdkVersion:u.sdkVersion});let E=await(cn??qt(S));return _.status!=="preparingInit"?E:ae(E)},sendInitMessage:se,onInitSent:()=>c({status:"waitingForInitResult"}),warn:u=>G("warn",u),flushPendingHostStateChanges:P,minBridgeProtocolVersion:V,noConnectTimeoutMs:y,initialStateTimeoutMs:x,noInitResultTimeoutMs:k,stopHostWithFailure:Nt,onInitResult(u){u.status==="success"&&ee!==void 0&&c({status:"initialized",resolvedManifest:ee,initialHeight:u.initialHeight})},onConnectionFailure:u=>{U.abort(),c({status:"failed",error:u})}});function ae(u){if(u.status==="error")return u;let S=ue(Ot,{...u.initialState,...j});if(ee=S.manifest,j={},te<sn&&S.page.type==="unavailable")return{status:"error",error:Mt()};let E=an(S.manifest,S.dataSources);return E!==void 0?{status:"error",error:E}:(ye=S.dataSources,H=!0,{status:"success",initialState:S})}let it=ln().catch(Tt),cn=e.manifestSource==="host"?qt(void 0).catch(Tt):void 0;async function ln(){U.signal.throwIfAborted();let u=await e.getPersistedManifest({signal:U.signal});return U.signal.throwIfAborted(),ue(No,u)}function Tt(u){return U.signal.aborted||G("warn",{message:"Failed to prepare custom block initialization",error:u}),{status:"error",error:ot()}}async function qt(u){U.signal.throwIfAborted();let S=await Ao({manifestSource:e.manifestSource,hostManifest:it,connectManifest:u});if(U.signal.throwIfAborted(),S.status==="error")return S;let E=ue(Po,await o({manifest:S.manifest,signal:U.signal}));return E.status==="error"?E:{status:"success",initialState:{...E.initialState,manifest:S.manifest}}}let At=rn({iframe:t,sandboxOrigin:W,getInitStatus:()=>_.status,emit:G,sendNack:J,sendPageMutationError:X,onInvalidConnect:_.handleInvalidConnect,onInvalidInitResult:_.handleInvalidInitResult,onConnect:_.handleConnect,onInitResult:_.handleInitResult,onQueryDataSource:we,onUnsubscribeDataSourceQuery:u=>F.unsubscribe(u.subscriptionId),onOpenExternalUrl:I,onCreatePage:u=>ne(u,s.createPage),onGetPage:u=>ne(u,s.getPage),onOpenPage:u=>ne(u,s.openPage),onGetUser:u=>ne(u,s.getUser),onListUsers:u=>ne(u,s.listUsers),onUpdatePage:u=>ne(u,s.updatePage),onResize:u=>s.resize?.(u)});window.addEventListener("message",At),t.addEventListener("load",_.onIframeLoad);function st(){b.abort(),U.abort(),window.removeEventListener("message",At),t.removeEventListener("load",_.onIframeLoad),_.stop(),F.unsubscribeAll()}function pn(){let u=_.status;st(),u!=="stopped"&&u!=="failed"&&c({status:"stopped"})}function Nt(u){if(_.status!=="stopped"){if(_.status==="failed"){st();return}st(),G("warn",u),c({status:"failed",error:u})}}return c({status:"waitingForConnect"}),{stop:pn,setTheme(u){de({theme:u})},setContrastMode(u){de({contrastMode:u})},setParent(u){de({parent:u})},setPage(u){if(u.type==="unavailable"&&te<sn&&(_.status==="preparingInit"&&H||_.status==="waitingForInitResult"||_.status==="initialized")){Nt({...Mt(),phase:"runtime",source:"host"});return}de({page:u})},setCurrentUser(u){de({currentUser:u})},setDataSources(u){let S={bindings:ue(ve,u.bindings)},E=_.hasConnectedSandbox&&ee!==void 0?an(ee,S):void 0;return E!==void 0?(G("warn",{message:"Ignored invalid data source bindings update",payload:S}),{status:"error",error:E}):(ye=S,de({dataSources:S}),{status:"success"})},refreshQuery({dataSourceId:u}){if(_.status!=="initialized")return;let S=ue(K,u),E=F.refresh(S);if(E===void 0){G("warn",`No active query exists for data source "${u}"`);return}for(let pe of E)we(pe.message,pe.token)}}}function Si(e,t){let o;try{o=new URL(e)}catch(s){throw t==="host"?s:new Ue(Dt())}if(t==="sandbox"&&!nt({url:o,hostOrigin:window.location.origin}))throw new Ue(Dt());return o}function ki(e,t){return Object.values(e?.bindings??{}).find(o=>o.collectionPointer?.id===t)?.collectionSchema}function an(e,t){for(let[o,s]of Object.entries(e.dataSources)){let c=t.bindings[o];if(c?.inaccessible===!0)continue;let l=er({manifestDataSource:s,collectionSchema:c?.collectionSchema,propertyIdsByKey:c?.propertyIdsByKey});if(c?.collectionPointer===void 0||l.status==="missing_schema")return wo();for(let p of l.properties){if(p.status==="missing")return To();if(p.status!=="mapped")return Do()}}}function Ii(e){return{status:"error",error:{code:"unsupported_operation",message:`The host does not support ${e}.`,isRetryable:!1}}}function _i(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}:Eo(e.filter,t)??Oo(e.sorts,t)}function xi(e){let{manifestProperties:t,propertySchemasById:o}=e,s=[];for(let[c,l]of Object.entries(t)){let p=Ci({propertyKey:c,manifestProperty:l,propertySchemasById:o});p!==void 0&&s.push([c,p])}return Object.fromEntries(s)}function Ci(e){let{propertyKey:t,manifestProperty:o,propertySchemasById:s}=e,c=un(o.name),l=Object.entries(s).filter(([p,h])=>h.type===o.type&&(p===t||un(h.name)===c));return l.length===1?l[0][0]:void 0}function un(e){return e.trim().toLowerCase()}function Pi(e){return ue(z,e)}export{_e as InvalidNotionDateError,bi as createCustomBlockHost,xi as getAutoBoundPropertyIdsByKey,nt as isAllowedLocalPreviewUrl,Et as toNotionDateValue,Pi as toNotionPageId};
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,iDAAiD,EACjD,MAAM,4DAA4D,CAAA;AASnE;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,iDAAiD,CAiCnD"}
1
+ {"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,iDAAiD,EACjD,MAAM,4DAA4D,CAAA;AAWnE;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,iDAAiD,CAoCnD"}
@@ -1,7 +1,8 @@
1
- import { TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "../protocol/utils/protocolVersion.js";
1
+ import { NATIVE_ICON_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "../protocol/utils/protocolVersion.js";
2
2
  import { addMetadataReadSchemasForProtocol3To4 } from "./protocol3To4/addMetadataReadSchemasForProtocol3To4.js";
3
3
  import { normalizePageResultsForProtocol3To5 } from "./protocol3To5/normalizePageResultsForProtocol3To5.js";
4
4
  import { normalizePageResultsForProtocol6 } from "./protocol6/normalizePageResultsForProtocol6.js";
5
+ import { normalizePageResultsForProtocol7To8 } from "./protocol7To8/normalizePageResultsForProtocol7To8.js";
5
6
  /**
6
7
  * Encodes current host messages for the sandbox's declared protocol. Handlers use
7
8
  * current shapes. Each target adapter starts from that shape to avoid data loss.
@@ -35,5 +36,8 @@ export function normalizeHostToSandboxMessage(message, bridgeProtocolVersion) {
35
36
  if (bridgeProtocolVersion < TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION) {
36
37
  return normalizePageResultsForProtocol6(message);
37
38
  }
39
+ if (bridgeProtocolVersion < NATIVE_ICON_PROTOCOL_VERSION) {
40
+ return normalizePageResultsForProtocol7To8(message);
41
+ }
38
42
  return message;
39
43
  }
@@ -797,6 +797,46 @@ export declare function normalizeSandboxToHostMessage(payload: unknown): v.SafeP
797
797
  readonly type: v.LiteralSchema<"verification", undefined>;
798
798
  readonly verification: v.StringSchema<undefined>;
799
799
  }, undefined>], undefined>, undefined>;
800
+ readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.LooseObjectSchema<{
801
+ readonly type: v.LiteralSchema<"icon", undefined>;
802
+ readonly icon: v.LooseObjectSchema<{
803
+ readonly name: v.StringSchema<undefined>;
804
+ readonly color: v.OptionalSchema<v.GenericSchema<import("../protocol/index.js").NotionIconColor>, undefined>;
805
+ }, undefined>;
806
+ }, undefined>, v.ObjectSchema<{
807
+ readonly type: v.LiteralSchema<"emoji", undefined>;
808
+ readonly emoji: v.StringSchema<undefined>;
809
+ }, undefined>, v.ObjectSchema<{
810
+ readonly type: v.LiteralSchema<"custom_emoji", undefined>;
811
+ readonly custom_emoji: v.ObjectSchema<{
812
+ readonly id: v.StringSchema<undefined>;
813
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
814
+ readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
815
+ }, undefined>;
816
+ }, undefined>, v.ObjectSchema<{
817
+ readonly type: v.LiteralSchema<"external", undefined>;
818
+ readonly external: v.ObjectSchema<{
819
+ readonly url: v.StringSchema<undefined>;
820
+ }, undefined>;
821
+ }, undefined>, v.ObjectSchema<{
822
+ readonly type: v.LiteralSchema<"file", undefined>;
823
+ readonly file: v.ObjectSchema<{
824
+ readonly url: v.StringSchema<undefined>;
825
+ readonly expiry_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
826
+ }, undefined>;
827
+ }, undefined>], undefined>, undefined>;
828
+ readonly cover: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
829
+ readonly type: v.LiteralSchema<"external", undefined>;
830
+ readonly external: v.ObjectSchema<{
831
+ readonly url: v.StringSchema<undefined>;
832
+ }, undefined>;
833
+ }, undefined>, v.ObjectSchema<{
834
+ readonly type: v.LiteralSchema<"file", undefined>;
835
+ readonly file: v.ObjectSchema<{
836
+ readonly url: v.StringSchema<undefined>;
837
+ readonly expiry_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
838
+ }, undefined>;
839
+ }, undefined>], undefined>, undefined>;
800
840
  readonly parent: v.ObjectSchema<{
801
841
  readonly type: v.LiteralSchema<"page_id", undefined>;
802
842
  readonly page_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
@@ -1030,6 +1070,46 @@ export declare function normalizeSandboxToHostMessage(payload: unknown): v.SafeP
1030
1070
  readonly type: v.LiteralSchema<"verification", undefined>;
1031
1071
  readonly verification: v.StringSchema<undefined>;
1032
1072
  }, undefined>], undefined>, undefined>;
1073
+ readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.LooseObjectSchema<{
1074
+ readonly type: v.LiteralSchema<"icon", undefined>;
1075
+ readonly icon: v.LooseObjectSchema<{
1076
+ readonly name: v.StringSchema<undefined>;
1077
+ readonly color: v.OptionalSchema<v.GenericSchema<import("../protocol/index.js").NotionIconColor>, undefined>;
1078
+ }, undefined>;
1079
+ }, undefined>, v.ObjectSchema<{
1080
+ readonly type: v.LiteralSchema<"emoji", undefined>;
1081
+ readonly emoji: v.StringSchema<undefined>;
1082
+ }, undefined>, v.ObjectSchema<{
1083
+ readonly type: v.LiteralSchema<"custom_emoji", undefined>;
1084
+ readonly custom_emoji: v.ObjectSchema<{
1085
+ readonly id: v.StringSchema<undefined>;
1086
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1087
+ readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1088
+ }, undefined>;
1089
+ }, undefined>, v.ObjectSchema<{
1090
+ readonly type: v.LiteralSchema<"external", undefined>;
1091
+ readonly external: v.ObjectSchema<{
1092
+ readonly url: v.StringSchema<undefined>;
1093
+ }, undefined>;
1094
+ }, undefined>, v.ObjectSchema<{
1095
+ readonly type: v.LiteralSchema<"file", undefined>;
1096
+ readonly file: v.ObjectSchema<{
1097
+ readonly url: v.StringSchema<undefined>;
1098
+ readonly expiry_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1099
+ }, undefined>;
1100
+ }, undefined>], undefined>, undefined>;
1101
+ readonly cover: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
1102
+ readonly type: v.LiteralSchema<"external", undefined>;
1103
+ readonly external: v.ObjectSchema<{
1104
+ readonly url: v.StringSchema<undefined>;
1105
+ }, undefined>;
1106
+ }, undefined>, v.ObjectSchema<{
1107
+ readonly type: v.LiteralSchema<"file", undefined>;
1108
+ readonly file: v.ObjectSchema<{
1109
+ readonly url: v.StringSchema<undefined>;
1110
+ readonly expiry_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1111
+ }, undefined>;
1112
+ }, undefined>], undefined>, undefined>;
1033
1113
  readonly parent: v.ObjectSchema<{
1034
1114
  readonly type: v.LiteralSchema<"data_source_id", undefined>;
1035
1115
  readonly data_source_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>;
@@ -1278,7 +1358,13 @@ export declare function normalizeSandboxToHostMessage(payload: unknown): v.SafeP
1278
1358
  readonly type: v.LiteralSchema<"verification", undefined>;
1279
1359
  readonly verification: v.StringSchema<undefined>;
1280
1360
  }, undefined>], undefined>, undefined>, undefined>;
1281
- readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
1361
+ readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.LooseObjectSchema<{
1362
+ readonly type: v.LiteralSchema<"icon", undefined>;
1363
+ readonly icon: v.LooseObjectSchema<{
1364
+ readonly name: v.StringSchema<undefined>;
1365
+ readonly color: v.OptionalSchema<v.GenericSchema<import("../protocol/index.js").NotionIconColor>, undefined>;
1366
+ }, undefined>;
1367
+ }, undefined>, v.ObjectSchema<{
1282
1368
  readonly type: v.LiteralSchema<"emoji", undefined>;
1283
1369
  readonly emoji: v.StringSchema<undefined>;
1284
1370
  }, undefined>, v.ObjectSchema<{
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeSandboxToHostMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeSandboxToHostMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAE7D"}
1
+ {"version":3,"file":"normalizeSandboxToHostMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeSandboxToHostMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAE7D"}
@@ -0,0 +1,4 @@
1
+ import type { NotionPageIcon } from "../../protocol/pages/pageAppearance.js";
2
+ /** Converts native icons for legacy receivers. Delete when the runtime minimum reaches 9. */
3
+ export declare function toIconForProtocol3To8(icon: NotionPageIcon | null): NotionPageIcon | null;
4
+ //# sourceMappingURL=toIconForProtocol3To8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toIconForProtocol3To8.d.ts","sourceRoot":"","sources":["../../../src/compatibility/pages/toIconForProtocol3To8.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0DAA0D,CAAA;AAE9F,6FAA6F;AAC7F,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,cAAc,GAAG,IAAI,GACzB,cAAc,GAAG,IAAI,CAWvB"}
@@ -0,0 +1,13 @@
1
+ /** Converts native icons for legacy receivers. Delete when the runtime minimum reaches 9. */
2
+ export function toIconForProtocol3To8(icon) {
3
+ if (icon?.type !== "icon") {
4
+ return icon;
5
+ }
6
+ const { name, color } = icon.icon;
7
+ return {
8
+ type: "external",
9
+ external: {
10
+ url: `https://www.notion.so/icons/${name}_${color ?? "gray"}.svg`,
11
+ },
12
+ };
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"toPageForProtocol3To5.d.ts","sourceRoot":"","sources":["../../../src/compatibility/protocol3To5/toPageForProtocol3To5.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2EAA2E,CAAA;AAC1H,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sDAAsD,CAAA;AAEtF;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,UAAU,GACd,yBAAyB,CAe3B"}
1
+ {"version":3,"file":"toPageForProtocol3To5.d.ts","sourceRoot":"","sources":["../../../src/compatibility/protocol3To5/toPageForProtocol3To5.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2EAA2E,CAAA;AAC1H,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sDAAsD,CAAA;AAGtF;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,UAAU,GACd,yBAAyB,CAe3B"}
@@ -1,3 +1,4 @@
1
+ import { toIconForProtocol3To8 } from "../pages/toIconForProtocol3To8.js";
1
2
  /**
2
3
  * Converts current page data to the page-operation format used by protocols 3–5.
3
4
  * Keys property objects by raw ID and omits null properties. Optional icons,
@@ -10,7 +11,7 @@ export function toPageForProtocol3To5(page) {
10
11
  return {
11
12
  ...page,
12
13
  properties: Object.fromEntries(Object.values(page.properties).flatMap(property => property ? [[property.id, property]] : [])),
13
- icon: page.icon ?? undefined,
14
+ icon: toIconForProtocol3To8(page.icon) ?? undefined,
14
15
  cover: page.cover ?? undefined,
15
16
  created_time: page.created_time ?? undefined,
16
17
  last_edited_time: page.last_edited_time ?? undefined,
@@ -48,11 +48,11 @@ export declare function toQueryPageForProtocol3To5(page: BridgePage): {
48
48
  value: number;
49
49
  time: string;
50
50
  defaultTimeZone?: string | undefined;
51
- } | {
52
- unit: "none";
53
51
  } | {
54
52
  unit: "hour" | "minute";
55
53
  value: number;
54
+ } | {
55
+ unit: "none";
56
56
  } | undefined;
57
57
  } | {
58
58
  type: "datetimerange";
@@ -66,11 +66,11 @@ export declare function toQueryPageForProtocol3To5(page: BridgePage): {
66
66
  value: number;
67
67
  time: string;
68
68
  defaultTimeZone?: string | undefined;
69
- } | {
70
- unit: "none";
71
69
  } | {
72
70
  unit: "hour" | "minute";
73
71
  value: number;
72
+ } | {
73
+ unit: "none";
74
74
  } | undefined;
75
75
  } | undefined;
76
76
  last_edited_time: string | number | boolean | string[] | {
@@ -109,11 +109,11 @@ export declare function toQueryPageForProtocol3To5(page: BridgePage): {
109
109
  value: number;
110
110
  time: string;
111
111
  defaultTimeZone?: string | undefined;
112
- } | {
113
- unit: "none";
114
112
  } | {
115
113
  unit: "hour" | "minute";
116
114
  value: number;
115
+ } | {
116
+ unit: "none";
117
117
  } | undefined;
118
118
  } | {
119
119
  type: "datetimerange";
@@ -127,11 +127,11 @@ export declare function toQueryPageForProtocol3To5(page: BridgePage): {
127
127
  value: number;
128
128
  time: string;
129
129
  defaultTimeZone?: string | undefined;
130
- } | {
131
- unit: "none";
132
130
  } | {
133
131
  unit: "hour" | "minute";
134
132
  value: number;
133
+ } | {
134
+ unit: "none";
135
135
  } | undefined;
136
136
  } | undefined;
137
137
  created_by: {
@@ -1 +1 @@
1
- {"version":3,"file":"normalizePageResultsForProtocol6.d.ts","sourceRoot":"","sources":["../../../src/compatibility/protocol6/normalizePageResultsForProtocol6.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AACtG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAGlE;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,oBAAoB,GAC3B,oBAAoB,CAWtB"}
1
+ {"version":3,"file":"normalizePageResultsForProtocol6.d.ts","sourceRoot":"","sources":["../../../src/compatibility/protocol6/normalizePageResultsForProtocol6.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAEtG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAIlE;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,oBAAoB,GAC3B,oBAAoB,CAWtB"}
@@ -1,3 +1,4 @@
1
+ import { toIconForProtocol3To8 } from "../pages/toIconForProtocol3To8.js";
1
2
  import { toPageWithNullTextFallbackProperties } from "../pages/toPageWithNullTextFallbackProperties.js";
2
3
  /**
3
4
  * Encodes protocol 6 pages, whose receivers require null for text fallback properties.
@@ -8,11 +9,17 @@ export function normalizePageResultsForProtocol6(message) {
8
9
  if (message.type === "queryDataSourceResult") {
9
10
  return {
10
11
  ...message,
11
- items: message.items.map(toPageWithNullTextFallbackProperties),
12
+ items: message.items.map(toPageForProtocol6),
12
13
  };
13
14
  }
14
15
  return {
15
16
  ...message,
16
- page: toPageWithNullTextFallbackProperties(message.page),
17
+ page: toPageForProtocol6(message.page),
18
+ };
19
+ }
20
+ function toPageForProtocol6(page) {
21
+ return {
22
+ ...toPageWithNullTextFallbackProperties(page),
23
+ icon: toIconForProtocol3To8(page.icon),
17
24
  };
18
25
  }
@@ -0,0 +1,4 @@
1
+ import type { SuccessfulPageResult } from "../pages/pageResult.js";
2
+ /** Encodes icons for protocols 7–8. Delete when the runtime minimum reaches 9. */
3
+ export declare function normalizePageResultsForProtocol7To8(message: SuccessfulPageResult): SuccessfulPageResult;
4
+ //# sourceMappingURL=normalizePageResultsForProtocol7To8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizePageResultsForProtocol7To8.d.ts","sourceRoot":"","sources":["../../../src/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAGlE,kFAAkF;AAClF,wBAAgB,mCAAmC,CAClD,OAAO,EAAE,oBAAoB,GAC3B,oBAAoB,CAStB"}