@nylas/react 1.0.0-prealpha1 → 1.0.1-prealpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-circle-icon.entry-4b8debfa.js +15 -0
- package/dist/add-circle-icon.entry-c5fdaa6f.cjs +1 -0
- package/dist/{archive-icon_7.entry-53aede1b.js → archive-icon_7.entry-9f3eca2c.js} +16 -16
- package/dist/{archive-icon_7.entry-8c90815a.cjs → archive-icon_7.entry-baecb43c.cjs} +1 -1
- package/dist/{arrow-icon.entry-a2f53919.cjs → arrow-icon.entry-9ab0c414.cjs} +1 -1
- package/dist/{arrow-icon.entry-2867f4fb.js → arrow-icon.entry-a3b36218.js} +4 -4
- package/dist/{bold-icon_3.entry-e0bc6774.cjs → bold-icon_3.entry-50406bc7.cjs} +1 -1
- package/dist/{bold-icon_3.entry-ad806730.js → bold-icon_3.entry-b0d81839.js} +6 -6
- package/dist/{calendar-cancel-icon.entry-74051835.js → calendar-cancel-icon.entry-0d07e33c.js} +5 -5
- package/dist/{calendar-cancel-icon.entry-546b7bd4.cjs → calendar-cancel-icon.entry-8f498984.cjs} +1 -1
- package/dist/{calendar-check-icon_3.entry-f5846fee.cjs → calendar-check-icon_3.entry-5415e916.cjs} +1 -1
- package/dist/{calendar-check-icon_3.entry-42bab0b4.js → calendar-check-icon_3.entry-cfb612c6.js} +4 -4
- package/dist/{calendar-icon.entry-25474b1e.cjs → calendar-icon.entry-219efd7a.cjs} +1 -1
- package/dist/{calendar-icon.entry-c751873f.js → calendar-icon.entry-e5f20598.js} +5 -5
- package/dist/chevron-icon.entry-3c709061.cjs +1 -0
- package/dist/chevron-icon.entry-f5d5d1b1.js +15 -0
- package/dist/close-icon_2.entry-eca351c4.js +25 -0
- package/dist/{close-icon_2.entry-aa015993.cjs → close-icon_2.entry-fa4f6d3e.cjs} +1 -1
- package/dist/{document-refresh-icon.entry-ca2ef29e.cjs → document-refresh-icon.entry-3a29a6e6.cjs} +1 -1
- package/dist/{document-refresh-icon.entry-b27207eb.js → document-refresh-icon.entry-89ad42fa.js} +5 -5
- package/dist/elements/index.d.ts +4 -0
- package/dist/{elements-60ebdb01-24595598.cjs → elements-dc5b338e-81a0319c.cjs} +577 -555
- package/dist/{elements-60ebdb01-5d144002.js → elements-dc5b338e-fb5dbfb5.js} +3339 -2763
- package/dist/{forward-icon_6.entry-dc8f7235.js → forward-icon_6.entry-0a6dff18.js} +127 -127
- package/dist/{forward-icon_6.entry-725d1be4.cjs → forward-icon_6.entry-ce725f05.cjs} +3 -3
- package/dist/{globe-icon.entry-796d3f48.js → globe-icon.entry-71414bc6.js} +4 -4
- package/dist/{globe-icon.entry-918cfd35.cjs → globe-icon.entry-a0c9599a.cjs} +1 -1
- package/dist/index-586a4206.cjs +30 -0
- package/dist/{index-4f65b6f9.js → index-98d3a4da.js} +410 -401
- package/dist/{index-2b85580a-bfc3ceac.cjs → index-b30d446a-3d69a3cc.cjs} +1 -1
- package/dist/{index-2b85580a-f9211f23.js → index-b30d446a-e0eaccad.js} +4 -9
- package/dist/{loading-icon.entry-8e49fab0.js → loading-icon.entry-15debb7d.js} +4 -4
- package/dist/loading-icon.entry-d2680046.cjs +1 -0
- package/dist/{mailbox-store-0019772c-06d31a90.js → mailbox-store-19f0c6c9-23a4e72f.js} +1 -1
- package/dist/{mailbox-store-0019772c-d1254c5c.cjs → mailbox-store-19f0c6c9-9a3ef58a.cjs} +1 -1
- package/dist/{nylas-booked-event-card_9.entry-ea02f083.cjs → nylas-booked-event-card_10.entry-27efa654.cjs} +6 -139
- package/dist/{nylas-booked-event-card_9.entry-d995d7cb.js → nylas-booked-event-card_10.entry-f2481a57.js} +1818 -1927
- package/dist/{nylas-if-state_3.entry-e8c831b7.cjs → nylas-if-state_3.entry-6c0bf8eb.cjs} +1 -1
- package/dist/{nylas-if-state_3.entry-ce816adb.js → nylas-if-state_3.entry-d805d4c6.js} +6 -6
- package/dist/{nylas-list-folders.entry-8134344b.js → nylas-list-folders.entry-472bd255.js} +3 -3
- package/dist/{nylas-list-folders.entry-de8cca60.cjs → nylas-list-folders.entry-cc04a07e.cjs} +1 -1
- package/dist/{nylas-list-threads.entry-93b70a1a.cjs → nylas-list-threads.entry-795c5a2b.cjs} +1 -1
- package/dist/{nylas-list-threads.entry-1367fe30.js → nylas-list-threads.entry-f3266bf7.js} +3 -3
- package/dist/{nylas-mailbox-pagination.entry-568ac217.js → nylas-mailbox-pagination.entry-bd0d3bda.js} +2 -2
- package/dist/{nylas-mailbox-pagination.entry-6bb0ee37.cjs → nylas-mailbox-pagination.entry-f701fd83.cjs} +1 -1
- package/dist/{nylas-mailbox-toolbar-button.entry-9214b283.js → nylas-mailbox-toolbar-button.entry-9641b5cd.js} +8 -8
- package/dist/{nylas-mailbox-toolbar-button.entry-d4ad5c15.cjs → nylas-mailbox-toolbar-button.entry-b9d6a3c8.cjs} +1 -1
- package/dist/{nylas-open-hours-picker.entry-109f13f5.js → nylas-open-hours-picker.entry-42942946.js} +58 -58
- package/dist/{nylas-open-hours-picker.entry-2c19643f.cjs → nylas-open-hours-picker.entry-aa103daf.cjs} +1 -1
- package/dist/{nylas-provider.entry-87fa9276.cjs → nylas-provider.entry-5bb55b2d.cjs} +1 -1
- package/dist/{nylas-provider.entry-2cfe5f0e.js → nylas-provider.entry-b94198a1.js} +7 -7
- package/dist/nylas-scheduler.entry-3b7cb841.js +230 -0
- package/dist/nylas-scheduler.entry-ea6fb146.cjs +1 -0
- package/dist/{nylas-threads-refresh.entry-6d61a689.cjs → nylas-threads-refresh.entry-4002608b.cjs} +1 -1
- package/dist/{nylas-threads-refresh.entry-9111a403.js → nylas-threads-refresh.entry-7d567ed1.js} +4 -4
- package/dist/nylas-threads-search.entry-556f1219.cjs +1 -0
- package/dist/{nylas-threads-search.entry-2124f663.js → nylas-threads-search.entry-c881d54b.js} +12 -12
- package/dist/{nylas-view-thread.entry-4ecbcd78.cjs → nylas-view-thread.entry-6faf1b51.cjs} +1 -1
- package/dist/{nylas-view-thread.entry-fe51c1f6.js → nylas-view-thread.entry-d8de6c83.js} +3 -3
- package/dist/play-icon_2.entry-2e21b8b9.cjs +1 -0
- package/dist/play-icon_2.entry-cae94826.js +25 -0
- package/dist/react.cjs +1 -1
- package/dist/react.js +57 -53
- package/dist/{refresh-icon.entry-9f24e833.cjs → refresh-icon.entry-3e0aef26.cjs} +1 -1
- package/dist/{refresh-icon.entry-4ddd53b0.js → refresh-icon.entry-9563850b.js} +4 -4
- package/dist/{register-component-55376f31-5eaf8954.js → register-component-152c6ad2-418db864.js} +1 -1
- package/dist/{register-component-55376f31-8d6ddee4.cjs → register-component-152c6ad2-b0d34c36.cjs} +1 -1
- package/dist/scheduler-store-7d48e682-39104219.js +289 -0
- package/dist/scheduler-store-7d48e682-449277d4.cjs +1 -0
- package/dist/search-icon_3.entry-9b027cfc.cjs +1 -0
- package/dist/search-icon_3.entry-e36548ec.js +101 -0
- package/package.json +1 -1
- package/dist/chevron-icon.entry-60842fb6.js +0 -15
- package/dist/chevron-icon.entry-97e4621e.cjs +0 -1
- package/dist/close-icon_2.entry-ef03bd27.js +0 -25
- package/dist/index-29d0e781.cjs +0 -30
- package/dist/loading-icon.entry-b2534e3e.cjs +0 -1
- package/dist/nylas-scheduler.entry-6ec8e574.js +0 -195
- package/dist/nylas-scheduler.entry-b41cbf99.cjs +0 -1
- package/dist/nylas-threads-search.entry-03073490.cjs +0 -1
- package/dist/play-icon_2.entry-8e156535.js +0 -25
- package/dist/play-icon_2.entry-cf1cbc8d.cjs +0 -1
- package/dist/property-0065dde7-83dc9cc4.cjs +0 -23
- package/dist/property-0065dde7-c57b8fa3.js +0 -589
- package/dist/scheduler-store-5a39585a-117668e3.js +0 -173
- package/dist/scheduler-store-5a39585a-2c848bec.cjs +0 -1
- package/dist/translate-icon.entry-0cd24de4.cjs +0 -1
- package/dist/translate-icon.entry-db2cdf1d.js +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const T=require("./utils-5074a070-d5ba6add.cjs"),Ye=require("./index-29d0e781.cjs");class ir{constructor(e,n,r=!0,s){this.automaticComponentRegistration=!0,this.registeredComponents={},this.propStateRegistrations=new Map,this.eventListenerRegistrations=new Map,this.host=e,this.stores=n,this.automaticComponentRegistration=r,this.eventOverrides=s,T.debug(`[${this.hostTagName}] Initializing (abstract) provider.`,{eventOverrides:s}),this.registerComponent=this.registerComponent.bind(this),this.getStore=this.getStore.bind(this),Object.keys(this.stores).forEach(i=>{this.propStateRegistrations.set(i,new Map)})}async componentWillLoad(e){T.debug(`[${this.hostTagName}] Will load`),this.setupStoreListeners(),this.nylasConnector=e;const n=Array.from(this.host.querySelectorAll("*")).filter(r=>r.tagName.toLowerCase().startsWith("nylas-"));T.debug(`[${this.hostTagName}] Found ${n.length} child component(s).`,{childComponents:n}),n.forEach(r=>{const s=r;if(!s){T.debug(`[~${this.hostTagName}] Component ${s.tagName} does not have a name. Skipping.`);return}if(!s.registerNylasComponent){T.debug(`[~${this.hostTagName}] Component ${s.tagName} is not a component that can be registered. Skipping.`,{component:s});return}const i={element:s,name:s.tagName.toLowerCase(),getStoresToProp:s.getStoresToProp,storeToProps:s.storeToProps,stateToProps:s.stateToProps,authToProp:s.authToProp,eventToProps:s.eventToProps,connectorToProp:s.connectorToProp};this.registerComponent(i)})}async componentDidLoad(){T.debug(`[${this.hostTagName}] Did load`)}async componentDisconnected(){Object.values(this.stores).forEach(e=>{e.dispose()})}async registerComponentHandler(e){if(e.stopPropagation(),!this.automaticComponentRegistration){T.debug(`[${this.hostTagName}] Automatic component registration disabled. Skipping registration of ${e.detail.name}.`);return}this.registerComponent(e.detail)}async unregisterComponentHandler(e){if(e.stopPropagation(),!this.automaticComponentRegistration){T.debug(`[${this.hostTagName}] Automatic component registration disabled. Skipping unregistration of ${e.detail.name}.`);return}this.unregisterComponent(e.detail)}registerComponent(e){T.debug(`[${this.hostTagName}] Registering component ${e.name}.`);const n=e.element.dataset.nylasId;if(n&&this.registeredComponents[n]){T.debug(`[${this.hostTagName}] Component ${e.name} already registered. Skipping.`);return}const{stateToProps:r,getStoresToProp:s,eventToProps:i,storeToProps:o,connectorToProp:u,element:a}=e;a.dataset.nylasId=T.uniqueID(),this.registeredComponents[a.dataset.nylasId]=e;const l=this.eventOverrides;i==null||i.forEach((h,c)=>{var y;const d=this.nylasConnector,g=async m=>{T.debug(`[${this.hostTagName}] Handling "${e.name}" prop "${String(c)}" event.`,{eventOverrides:l}),c in l&&(T.debug(`[${this.hostTagName}] Found event override for "${String(c)}" event. Calling override.`),await l[c](m,d)),m.defaultPrevented||await h(m,d)},p=e.element.dataset.nylasId;p&&!this.eventListenerRegistrations.has(p)&&this.eventListenerRegistrations.set(p,[]),p&&((y=this.eventListenerRegistrations.get(p))==null||y.push([a,c,g])),T.debug(`[${this.hostTagName}] Setting "${e.name}" event "${String(c)}" to automcially call NylasConnector method.`);const f=T.formatEventName(c.toString());T.debug(`[${this.hostTagName}] Adding event listener for "${f}" on "${a.tagName}"`),a.addEventListener(f,g)}),r==null||r.forEach((h,c)=>{var y,m,v,b;const[d,g]=c.split("."),f=this.getStore(d).state[g];if(!a.dataset.nylasId){T.debug(`[${this.hostTagName}] Component "${e.name}" not registered. Skipping.`,{component:e});return}this.propStateRegistrations.has(d)||this.propStateRegistrations.set(d,new Map),(y=this.propStateRegistrations.get(d))!=null&&y.has(g)?(b=(v=this.propStateRegistrations.get(d))==null?void 0:v.get(g))==null||b.push({elementId:a.dataset.nylasId,propKey:h}):(m=this.propStateRegistrations.get(d))==null||m.set(g,[{elementId:a.dataset.nylasId,propKey:h}]),a[h.toString()]=f,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${h.toString()}" to "${c}" value.`,{stateValue:f})}),s&&(a[s==null?void 0:s.toString()]=this.getStore,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${s.toString()}" to "getStore" method.`)),o==null||o.forEach((h,c)=>{const d=this.getStore(c);a[h.toString()]=d,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${h.toString()}" to "${c}" store.`,{store:d})}),u&&(a[u==null?void 0:u.toString()]=this.nylasConnector,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${u.toString()}" to "nylasConnector" value.`,{connectorToProp:u})),T.debug(`[${this.hostTagName}] Component ${e.name} registered.`)}unregisterComponent(e){T.debug(`[${this.hostTagName}] Unregistering component ${e.name}.`);const n=e.element.dataset.nylasId;if(!n){T.debug(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);return}if(this.registeredComponents[n]){T.debug(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);return}this.propStateRegistrations.forEach((s,i)=>{s.forEach((o,u)=>{var h,c;const a=(h=this.propStateRegistrations.get(i))==null?void 0:h.get(u),l=a==null?void 0:a.filter(d=>d.elementId!==n);l&&((c=this.propStateRegistrations.get(i))==null||c.set(u,l))})});const r=this.eventListenerRegistrations.get(n);r==null||r.forEach(([s,i,o])=>{const u=T.formatEventName(i.toString());T.debug(`[${this.hostTagName}] Removing event listener for "${u}" on "${s.tagName}"`),s.removeEventListener(u,o)}),delete this.registeredComponents[n]}getStore(e){const n=this.stores[e];if(!n)throw new Error(`[${this.hostTagName}] Store "${e.toString()}" not found.`);return n}async setupStoreListeners(){const e=this;Object.entries(this.stores).forEach(([n,r])=>{T.debug(`[${e.hostTagName}] Listening for changes in "${n}" store.`),r.use({set(s,i,o){var l;if(T.debug(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" changed`,{newValue:i,oldValue:o}),i===o){T.debug(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" unchanged. Skipping.`);return}const u=e.registeredComponents;if(!u){T.debug(`[${e.hostTagName}] No registered components found. Skipping.`);return}const a=((l=e.propStateRegistrations.get(n))==null?void 0:l.get(s.toString()))||[];T.debug(`[${e.hostTagName}] Found ${a.length} prop(s) registered for "${s.toString()}" store.`,{props:a,propStateRegistrations:e.propStateRegistrations}),a.forEach(({elementId:h,propKey:c})=>{const d=u[h];if(!d){T.debug(`[${e.hostTagName}] Component "${h}" not found. Skipping.`,{component:d});return}const p=e.getStore(n).state[s];d.element[c.toString()]=p,T.debug(`[${e.hostTagName}] Setting "${d.name}" prop "${c.toString()}" to "${s.toString()}" value.`,{stateValue:p})})}})})}get hostTagName(){var e,n;return((n=(e=this.host)==null?void 0:e.tagName)==null?void 0:n.toLowerCase())??"nylas-provider"}}class or extends ir{}var ar=Object.defineProperty,ur=(t,e,n)=>e in t?ar(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ct=(t,e,n)=>(ur(t,typeof e!="symbol"?e+"":e,n),n),Cn=(t=>(t.Error="error",t.Warning="warning",t.Info="info",t.Success="success",t))(Cn||{});const cr=t=>"error"in t;class lr extends Error{constructor(e){super(e==null?void 0:e.message),ct(this,"apiError"),this.name="NylasAPIError",this.stack=new Error().stack,this.apiError=e}}async function fn(t){const e=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",e),r=Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("");return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}const R=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,$=Object.keys,F=Array.isArray;function U(t,e){return typeof e!="object"||$(e).forEach(function(n){t[n]=e[n]}),t}typeof Promise>"u"||R.Promise||(R.Promise=Promise);const Be=Object.getPrototypeOf,hr={}.hasOwnProperty;function z(t,e){return hr.call(t,e)}function Ee(t,e){typeof e=="function"&&(e=e(Be(t))),(typeof Reflect>"u"?$:Reflect.ownKeys)(e).forEach(n=>{ee(t,n,e[n])})}const Tn=Object.defineProperty;function ee(t,e,n,r){Tn(t,e,U(n&&z(n,"get")&&typeof n.get=="function"?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function ke(t){return{from:function(e){return t.prototype=Object.create(e.prototype),ee(t.prototype,"constructor",t),{extend:Ee.bind(null,t.prototype)}}}}const dr=Object.getOwnPropertyDescriptor;function en(t,e){let n;return dr(t,e)||(n=Be(t))&&en(n,e)}const fr=[].slice;function lt(t,e,n){return fr.call(t,e,n)}function An(t,e){return e(t)}function Ie(t){if(!t)throw new Error("Assertion Failed")}function On(t){R.setImmediate?setImmediate(t):setTimeout(t,0)}function In(t,e){return t.reduce((n,r,s)=>{var i=e(r,s);return i&&(n[i[0]]=i[1]),n},{})}function te(t,e){if(z(t,e))return t[e];if(!e)return t;if(typeof e!="string"){for(var n=[],r=0,s=e.length;r<s;++r){var i=te(t,e[r]);n.push(i)}return n}var o=e.indexOf(".");if(o!==-1){var u=t[e.substr(0,o)];return u===void 0?void 0:te(u,e.substr(o+1))}}function H(t,e,n){if(t&&e!==void 0&&(!("isFrozen"in Object)||!Object.isFrozen(t)))if(typeof e!="string"&&"length"in e){Ie(typeof n!="string"&&"length"in n);for(var r=0,s=e.length;r<s;++r)H(t,e[r],n[r])}else{var i=e.indexOf(".");if(i!==-1){var o=e.substr(0,i),u=e.substr(i+1);if(u==="")n===void 0?F(t)&&!isNaN(parseInt(o))?t.splice(o,1):delete t[o]:t[o]=n;else{var a=t[o];a&&z(t,o)||(a=t[o]={}),H(a,u,n)}}else n===void 0?F(t)&&!isNaN(parseInt(e))?t.splice(e,1):delete t[e]:t[e]=n}}function Rn(t){var e={};for(var n in t)z(t,n)&&(e[n]=t[n]);return e}const pr=[].concat;function Kn(t){return pr.apply([],t)}const jn="Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(Kn([8,16,32,64].map(t=>["Int","Uint","Float"].map(e=>e+t+"Array")))).filter(t=>R[t]),gr=jn.map(t=>R[t]);In(jn,t=>[t,!0]);let se=null;function We(t){se=typeof WeakMap<"u"&&new WeakMap;const e=At(t);return se=null,e}function At(t){if(!t||typeof t!="object")return t;let e=se&&se.get(t);if(e)return e;if(F(t)){e=[],se&&se.set(t,e);for(var n=0,r=t.length;n<r;++n)e.push(At(t[n]))}else if(gr.indexOf(t.constructor)>=0)e=t;else{const i=Be(t);for(var s in e=i===Object.prototype?{}:Object.create(i),se&&se.set(t,e),t)z(t,s)&&(e[s]=At(t[s]))}return e}const{toString:mr}={};function Ot(t){return mr.call(t).slice(8,-1)}const It=typeof Symbol<"u"?Symbol.iterator:"@@iterator",yr=typeof It=="symbol"?function(t){var e;return t!=null&&(e=t[It])&&e.apply(t)}:function(){return null},_e={};function J(t){var e,n,r,s;if(arguments.length===1){if(F(t))return t.slice();if(this===_e&&typeof t=="string")return[t];if(s=yr(t)){for(n=[];!(r=s.next()).done;)n.push(r.value);return n}if(t==null)return[t];if(typeof(e=t.length)=="number"){for(n=new Array(e);e--;)n[e]=t[e];return n}return[t]}for(e=arguments.length,n=new Array(e);e--;)n[e]=arguments[e];return n}const tn=typeof Symbol<"u"?t=>t[Symbol.toStringTag]==="AsyncFunction":()=>!1;var G=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function Dn(t,e){G=t,$n=e}var $n=()=>!0;const vr=!new Error("").stack;function Pe(){if(vr)try{throw new Error}catch(t){return t}return new Error}function Rt(t,e){var n=t.stack;return n?(e=e||0,n.indexOf(t.name)===0&&(e+=(t.name+t.message).split(`
|
|
1
|
+
"use strict";const T=require("./utils-5074a070-d5ba6add.cjs"),Ye=require("./index-586a4206.cjs");class ir{constructor(e,n,r=!0,s){this.automaticComponentRegistration=!0,this.registeredComponents={},this.propStateRegistrations=new Map,this.eventListenerRegistrations=new Map,this.host=e,this.stores=n,this.automaticComponentRegistration=r,this.eventOverrides=s,T.debug(`[${this.hostTagName}] Initializing (abstract) provider.`,{eventOverrides:s}),this.registerComponent=this.registerComponent.bind(this),this.getStore=this.getStore.bind(this),Object.keys(this.stores).forEach(i=>{this.propStateRegistrations.set(i,new Map)})}async componentWillLoad(e){T.debug(`[${this.hostTagName}] Will load`),this.setupStoreListeners(),this.nylasConnector=e;const n=Array.from(this.host.querySelectorAll("*")).filter(r=>r.tagName.toLowerCase().startsWith("nylas-"));T.debug(`[${this.hostTagName}] Found ${n.length} child component(s).`,{childComponents:n}),n.forEach(r=>{const s=r;if(!s){T.debug(`[~${this.hostTagName}] Component ${s.tagName} does not have a name. Skipping.`);return}if(!s.registerNylasComponent){T.debug(`[~${this.hostTagName}] Component ${s.tagName} is not a component that can be registered. Skipping.`,{component:s});return}const i={element:s,name:s.tagName.toLowerCase(),getStoresToProp:s.getStoresToProp,storeToProps:s.storeToProps,stateToProps:s.stateToProps,authToProp:s.authToProp,eventToProps:s.eventToProps,connectorToProp:s.connectorToProp};this.registerComponent(i)})}async componentDidLoad(){T.debug(`[${this.hostTagName}] Did load`)}async componentDisconnected(){Object.values(this.stores).forEach(e=>{e.dispose()})}async registerComponentHandler(e){if(e.stopPropagation(),!this.automaticComponentRegistration){T.debug(`[${this.hostTagName}] Automatic component registration disabled. Skipping registration of ${e.detail.name}.`);return}this.registerComponent(e.detail)}async unregisterComponentHandler(e){if(e.stopPropagation(),!this.automaticComponentRegistration){T.debug(`[${this.hostTagName}] Automatic component registration disabled. Skipping unregistration of ${e.detail.name}.`);return}this.unregisterComponent(e.detail)}registerComponent(e){T.debug(`[${this.hostTagName}] Registering component ${e.name}.`);const n=e.element.dataset.nylasId;if(n&&this.registeredComponents[n]){T.debug(`[${this.hostTagName}] Component ${e.name} already registered. Skipping.`);return}const{stateToProps:r,getStoresToProp:s,eventToProps:i,storeToProps:o,connectorToProp:u,element:a}=e;a.dataset.nylasId=T.uniqueID(),this.registeredComponents[a.dataset.nylasId]=e;const l=this.eventOverrides;i==null||i.forEach((h,c)=>{var y;const d=this.nylasConnector,g=async m=>{T.debug(`[${this.hostTagName}] Handling "${e.name}" prop "${String(c)}" event.`,{event:m}),c in l&&(T.debug(`[${this.hostTagName}] Found event override for "${String(c)}" event. Calling override.`),await l[c](m,d)),m.defaultPrevented||await h(m,d)},p=e.element.dataset.nylasId;p&&!this.eventListenerRegistrations.has(p)&&this.eventListenerRegistrations.set(p,[]),p&&((y=this.eventListenerRegistrations.get(p))==null||y.push([a,c,g])),T.debug(`[${this.hostTagName}] Setting "${e.name}" event "${String(c)}" to automcially call NylasConnector method.`);const f=T.formatEventName(c.toString());T.debug(`[${this.hostTagName}] Adding event listener for "${f}" on "${a.tagName}"`),a.addEventListener(f,g)}),r==null||r.forEach((h,c)=>{var y,m,v,b;const[d,g]=c.split("."),f=this.getStore(d).state[g];if(!a.dataset.nylasId){T.debug(`[${this.hostTagName}] Component "${e.name}" not registered. Skipping.`,{component:e});return}this.propStateRegistrations.has(d)||this.propStateRegistrations.set(d,new Map),(y=this.propStateRegistrations.get(d))!=null&&y.has(g)?(b=(v=this.propStateRegistrations.get(d))==null?void 0:v.get(g))==null||b.push({elementId:a.dataset.nylasId,propKey:h}):(m=this.propStateRegistrations.get(d))==null||m.set(g,[{elementId:a.dataset.nylasId,propKey:h}]),a[h.toString()]=f,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${h.toString()}" to "${c}" value.`,{stateValue:f})}),s&&(a[s==null?void 0:s.toString()]=this.getStore,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${s.toString()}" to "getStore" method.`)),o==null||o.forEach((h,c)=>{const d=this.getStore(c);a[h.toString()]=d,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${h.toString()}" to "${c}" store.`,{store:d})}),u&&(a[u==null?void 0:u.toString()]=this.nylasConnector,T.debug(`[${this.hostTagName}] Setting "${e.name}" prop "${u.toString()}" to "nylasConnector" value.`,{connectorToProp:u})),T.debug(`[${this.hostTagName}] Component ${e.name} registered.`)}unregisterComponent(e){T.debug(`[${this.hostTagName}] Unregistering component ${e.name}.`);const n=e.element.dataset.nylasId;if(!n){T.debug(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);return}if(this.registeredComponents[n]){T.debug(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);return}this.propStateRegistrations.forEach((s,i)=>{s.forEach((o,u)=>{var h,c;const a=(h=this.propStateRegistrations.get(i))==null?void 0:h.get(u),l=a==null?void 0:a.filter(d=>d.elementId!==n);l&&((c=this.propStateRegistrations.get(i))==null||c.set(u,l))})});const r=this.eventListenerRegistrations.get(n);r==null||r.forEach(([s,i,o])=>{const u=T.formatEventName(i.toString());T.debug(`[${this.hostTagName}] Removing event listener for "${u}" on "${s.tagName}"`),s.removeEventListener(u,o)}),delete this.registeredComponents[n]}getStore(e){const n=this.stores[e];if(!n)throw new Error(`[${this.hostTagName}] Store "${e.toString()}" not found.`);return n}async setupStoreListeners(){const e=this;Object.entries(this.stores).forEach(([n,r])=>{T.debug(`[${e.hostTagName}] Listening for changes in "${n}" store.`),r.use({set(s,i,o){var l;if(T.debug(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" changed`,{newValue:i,oldValue:o}),i===o){T.debug(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" unchanged. Skipping.`);return}const u=e.registeredComponents;if(!u){T.debug(`[${e.hostTagName}] No registered components found. Skipping.`);return}const a=((l=e.propStateRegistrations.get(n))==null?void 0:l.get(s.toString()))||[];T.debug(`[${e.hostTagName}] Found ${a.length} prop(s) registered for "${s.toString()}" store.`,{props:a,propStateRegistrations:e.propStateRegistrations}),a.forEach(({elementId:h,propKey:c})=>{const d=u[h];if(!d){T.debug(`[${e.hostTagName}] Component "${h}" not found. Skipping.`,{component:d});return}const p=e.getStore(n).state[s];d.element[c.toString()]=p,T.debug(`[${e.hostTagName}] Setting "${d.name}" prop "${c.toString()}" to "${s.toString()}" value.`,{stateValue:p})})}})})}get hostTagName(){var e,n;return((n=(e=this.host)==null?void 0:e.tagName)==null?void 0:n.toLowerCase())??"nylas-provider"}}class or extends ir{}var ar=Object.defineProperty,ur=(t,e,n)=>e in t?ar(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ct=(t,e,n)=>(ur(t,typeof e!="symbol"?e+"":e,n),n),Cn=(t=>(t.Error="error",t.Warning="warning",t.Info="info",t.Success="success",t))(Cn||{});const cr=t=>"error"in t;class lr extends Error{constructor(e){super(e==null?void 0:e.message),ct(this,"apiError"),this.name="NylasAPIError",this.stack=new Error().stack,this.apiError=e}}async function fn(t){const e=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",e),r=Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("");return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}const R=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,$=Object.keys,F=Array.isArray;function U(t,e){return typeof e!="object"||$(e).forEach(function(n){t[n]=e[n]}),t}typeof Promise>"u"||R.Promise||(R.Promise=Promise);const Be=Object.getPrototypeOf,hr={}.hasOwnProperty;function z(t,e){return hr.call(t,e)}function Ee(t,e){typeof e=="function"&&(e=e(Be(t))),(typeof Reflect>"u"?$:Reflect.ownKeys)(e).forEach(n=>{ee(t,n,e[n])})}const Tn=Object.defineProperty;function ee(t,e,n,r){Tn(t,e,U(n&&z(n,"get")&&typeof n.get=="function"?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function ke(t){return{from:function(e){return t.prototype=Object.create(e.prototype),ee(t.prototype,"constructor",t),{extend:Ee.bind(null,t.prototype)}}}}const dr=Object.getOwnPropertyDescriptor;function en(t,e){let n;return dr(t,e)||(n=Be(t))&&en(n,e)}const fr=[].slice;function lt(t,e,n){return fr.call(t,e,n)}function An(t,e){return e(t)}function Ie(t){if(!t)throw new Error("Assertion Failed")}function On(t){R.setImmediate?setImmediate(t):setTimeout(t,0)}function In(t,e){return t.reduce((n,r,s)=>{var i=e(r,s);return i&&(n[i[0]]=i[1]),n},{})}function te(t,e){if(z(t,e))return t[e];if(!e)return t;if(typeof e!="string"){for(var n=[],r=0,s=e.length;r<s;++r){var i=te(t,e[r]);n.push(i)}return n}var o=e.indexOf(".");if(o!==-1){var u=t[e.substr(0,o)];return u===void 0?void 0:te(u,e.substr(o+1))}}function H(t,e,n){if(t&&e!==void 0&&(!("isFrozen"in Object)||!Object.isFrozen(t)))if(typeof e!="string"&&"length"in e){Ie(typeof n!="string"&&"length"in n);for(var r=0,s=e.length;r<s;++r)H(t,e[r],n[r])}else{var i=e.indexOf(".");if(i!==-1){var o=e.substr(0,i),u=e.substr(i+1);if(u==="")n===void 0?F(t)&&!isNaN(parseInt(o))?t.splice(o,1):delete t[o]:t[o]=n;else{var a=t[o];a&&z(t,o)||(a=t[o]={}),H(a,u,n)}}else n===void 0?F(t)&&!isNaN(parseInt(e))?t.splice(e,1):delete t[e]:t[e]=n}}function Rn(t){var e={};for(var n in t)z(t,n)&&(e[n]=t[n]);return e}const pr=[].concat;function Kn(t){return pr.apply([],t)}const jn="Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(Kn([8,16,32,64].map(t=>["Int","Uint","Float"].map(e=>e+t+"Array")))).filter(t=>R[t]),gr=jn.map(t=>R[t]);In(jn,t=>[t,!0]);let se=null;function We(t){se=typeof WeakMap<"u"&&new WeakMap;const e=At(t);return se=null,e}function At(t){if(!t||typeof t!="object")return t;let e=se&&se.get(t);if(e)return e;if(F(t)){e=[],se&&se.set(t,e);for(var n=0,r=t.length;n<r;++n)e.push(At(t[n]))}else if(gr.indexOf(t.constructor)>=0)e=t;else{const i=Be(t);for(var s in e=i===Object.prototype?{}:Object.create(i),se&&se.set(t,e),t)z(t,s)&&(e[s]=At(t[s]))}return e}const{toString:mr}={};function Ot(t){return mr.call(t).slice(8,-1)}const It=typeof Symbol<"u"?Symbol.iterator:"@@iterator",yr=typeof It=="symbol"?function(t){var e;return t!=null&&(e=t[It])&&e.apply(t)}:function(){return null},_e={};function J(t){var e,n,r,s;if(arguments.length===1){if(F(t))return t.slice();if(this===_e&&typeof t=="string")return[t];if(s=yr(t)){for(n=[];!(r=s.next()).done;)n.push(r.value);return n}if(t==null)return[t];if(typeof(e=t.length)=="number"){for(n=new Array(e);e--;)n[e]=t[e];return n}return[t]}for(e=arguments.length,n=new Array(e);e--;)n[e]=arguments[e];return n}const tn=typeof Symbol<"u"?t=>t[Symbol.toStringTag]==="AsyncFunction":()=>!1;var G=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function Dn(t,e){G=t,$n=e}var $n=()=>!0;const vr=!new Error("").stack;function Pe(){if(vr)try{throw new Error}catch(t){return t}return new Error}function Rt(t,e){var n=t.stack;return n?(e=e||0,n.indexOf(t.name)===0&&(e+=(t.name+t.message).split(`
|
|
2
2
|
`).length),n.split(`
|
|
3
3
|
`).slice(e).filter($n).map(r=>`
|
|
4
4
|
`+r).join("")):""}var Nn=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],nn=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(Nn),br={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function xe(t,e){this._e=Pe(),this.name=t,this.message=e}function Bn(t,e){return t+". Errors: "+Object.keys(e).map(n=>e[n].toString()).filter((n,r,s)=>s.indexOf(n)===r).join(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as T, u as or, e as dn } from "./utils-5074a070-ce33ee6b.js";
|
|
2
|
-
import { a as fn, f as pn } from "./index-
|
|
2
|
+
import { a as fn, f as pn } from "./index-98d3a4da.js";
|
|
3
3
|
class ar {
|
|
4
4
|
constructor(e, n, r = !0, s) {
|
|
5
5
|
this.automaticComponentRegistration = !0, this.registeredComponents = {}, this.propStateRegistrations = /* @__PURE__ */ new Map(), this.eventListenerRegistrations = /* @__PURE__ */ new Map(), this.host = e, this.stores = n, this.automaticComponentRegistration = r, this.eventOverrides = s, T(`[${this.hostTagName}] Initializing (abstract) provider.`, { eventOverrides: s }), this.registerComponent = this.registerComponent.bind(this), this.getStore = this.getStore.bind(this), Object.keys(this.stores).forEach((i) => {
|
|
@@ -67,7 +67,7 @@ class ar {
|
|
|
67
67
|
i == null || i.forEach((h, c) => {
|
|
68
68
|
var y;
|
|
69
69
|
const d = this.nylasConnector, m = async (g) => {
|
|
70
|
-
T(`[${this.hostTagName}] Handling "${e.name}" prop "${String(c)}" event.`, {
|
|
70
|
+
T(`[${this.hostTagName}] Handling "${e.name}" prop "${String(c)}" event.`, { event: g }), c in l && (T(`[${this.hostTagName}] Found event override for "${String(c)}" event. Calling override.`), await l[c](g, d)), g.defaultPrevented || await h(g, d);
|
|
71
71
|
}, p = e.element.dataset.nylasId;
|
|
72
72
|
p && !this.eventListenerRegistrations.has(p) && this.eventListenerRegistrations.set(p, []), p && ((y = this.eventListenerRegistrations.get(p)) == null || y.push([a, c, m])), T(`[${this.hostTagName}] Setting "${e.name}" event "${String(c)}" to automcially call NylasConnector method.`);
|
|
73
73
|
const f = dn(c.toString());
|
|
@@ -3078,10 +3078,7 @@ function ms(t) {
|
|
|
3078
3078
|
*/
|
|
3079
3079
|
async isAccessTokenValid() {
|
|
3080
3080
|
const o = await (n == null ? void 0 : n.getTokenInfo());
|
|
3081
|
-
return o ? "data" in await this.nylasAPIRequest(
|
|
3082
|
-
`/v3/connect/tokeninfo?id_token=${o.id_token}`,
|
|
3083
|
-
"GET"
|
|
3084
|
-
) : !1;
|
|
3081
|
+
return o ? "data" in await this.nylasAPIRequest(`/v3/connect/tokeninfo?id_token=${o.id_token}`, "GET") : !1;
|
|
3085
3082
|
},
|
|
3086
3083
|
/**
|
|
3087
3084
|
* This method will make a request to the Nylas API to refresh the current access token.
|
|
@@ -3110,9 +3107,7 @@ function ms(t) {
|
|
|
3110
3107
|
const l = a.scope.toLowerCase().split(" ");
|
|
3111
3108
|
let h = [];
|
|
3112
3109
|
const c = Array.isArray(u) ? u : [u];
|
|
3113
|
-
return o === "email" && (h = [...s, ...r].filter(
|
|
3114
|
-
(d) => c.includes(d.type)
|
|
3115
|
-
)), h.every((d) => l.includes(d.value));
|
|
3110
|
+
return o === "email" && (h = [...s, ...r].filter((d) => c.includes(d.type))), h.every((d) => l.includes(d.value));
|
|
3116
3111
|
},
|
|
3117
3112
|
/**
|
|
3118
3113
|
* A helper method to check if the current access token has a given scope.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { r as t, h as
|
|
1
|
+
import { r as t, h as e } from "./index-98d3a4da.js";
|
|
2
2
|
import "react";
|
|
3
3
|
import "react-dom";
|
|
4
4
|
const i = ".wave{display:flex;align-items:center;justify-content:center}.dot{width:4px;height:4px;background-color:var(--dot-color, white);border-radius:50%;margin:0 2px;animation:wave 1.5s infinite ease-in-out}.dot:nth-child(2){animation-delay:0.2s}.dot:nth-child(3){animation-delay:0.4s}@keyframes wave{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}", n = i, o = class {
|
|
5
|
-
constructor(
|
|
6
|
-
t(this,
|
|
5
|
+
constructor(a) {
|
|
6
|
+
t(this, a), this.width = "15", this.height = "15";
|
|
7
7
|
}
|
|
8
8
|
render() {
|
|
9
|
-
return
|
|
9
|
+
return e("div", { key: "bf96616e119f5ffef943b4bee1c45cbf9919bba7", class: "wave" }, e("div", { key: "cb1a652eae22004ac8f265f68a8dbf56adeaf0e1", class: "dot" }), e("div", { key: "5f608e19d592c0fb0fd81b43702c391af2667f41", class: "dot" }), e("div", { key: "1b2d7ab591ec6e8fe0c1502a8e290281ce140e52", class: "dot" }));
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
o.style = n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-586a4206.cjs");require("react");require("react-dom");const i=".wave{display:flex;align-items:center;justify-content:center}.dot{width:4px;height:4px;background-color:var(--dot-color, white);border-radius:50%;margin:0 2px;animation:wave 1.5s infinite ease-in-out}.dot:nth-child(2){animation-delay:0.2s}.dot:nth-child(3){animation-delay:0.4s}@keyframes wave{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}",n=i,t=class{constructor(a){e.registerInstance(this,a),this.width="15",this.height="15"}render(){return e.h("div",{key:"bf96616e119f5ffef943b4bee1c45cbf9919bba7",class:"wave"},e.h("div",{key:"cb1a652eae22004ac8f265f68a8dbf56adeaf0e1",class:"dot"}),e.h("div",{key:"5f608e19d592c0fb0fd81b43702c391af2667f41",class:"dot"}),e.h("div",{key:"1b2d7ab591ec6e8fe0c1502a8e290281ce140e52",class:"dot"}))}};t.style=n;exports.loading_icon=t;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as o } from "./utils-5074a070-ce33ee6b.js";
|
|
2
|
-
import { c as f, X as u, Z as d } from "./index-
|
|
2
|
+
import { c as f, X as u, Z as d } from "./index-b30d446a-e0eaccad.js";
|
|
3
3
|
class S {
|
|
4
4
|
constructor(t, e) {
|
|
5
5
|
this.nylasAuth = t, this.nylasAuthStore = e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("./utils-5074a070-d5ba6add.cjs"),i=require("./index-2b85580a-bfc3ceac.cjs");class g{constructor(t,e){this.nylasAuth=t,this.nylasAuthStore=e}async validateSession(){const t=await this.isAccessTokenValid();if(!t)this.logout();else{let e=await this.nylasAuth.getTokenInfo();if(e){const a=Math.floor(Date.now()/1e3);if(e.expires_in&&e.expires_in-a<3e5&&(o.debug("[NylasAuthConnectorMixin] Refreshing access token"),e=await this.nylasAuth.refreshAccessToken(),!e)){o.debug("[NylasAuthConnectorMixin] Token is expired and could not be refreshed. Logging out."),this.logout();return}this.nylasAuthStore.state.tokenInfo=e}}this.nylasAuthStore.state.isAuthenticated=t}async isAuthenticated(){return this.nylasAuth.isAuthenticated()}async getTokenInfo(){return this.nylasAuth.getTokenInfo()}async isAccessTokenValid(){return this.nylasAuth.isAccessTokenValid()}async logout(){await this.nylasAuth.logout()}async getHostedAuthRedirectURL(t,e,s){return this.nylasAuth.getHostedAuthRedirectURL(t,e,s)}async manageHostedAuthCodeExchange(t){const s=new URL(t).searchParams.get("code");if(s){const a=await this.nylasAuth.exchangeAuthCodeForTokenInfo(s);if(a)return this.nylasAuthStore.state.tokenInfo=a,this.nylasAuthStore.state.isAuthenticated=!0,a}return null}}class f{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getMessages(){var n;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");this.nylasMailboxStore.state.state="loading";const t=this.nylasMailboxStore.state.messgeQueryParams,e=new URLSearchParams;for(const h in t){const u=(n=t[h])==null?void 0:n.toString();u&&e.append(h,u)}const s=`/v3/grants/me/messages?${e.toString()}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.messages=r,this.nylasMailboxStore.state.state="ready",r}async getThreadMessages(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest(`/v3/grants/me/messages?thread_id=${t}&fields=include_headers`);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.messages=s,s}downloadMessageAttachments(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=[],s=t.attachments||[];for(const a of s){const r=this.nylasAuth.nylasDownloadFileRequest(`/v3/grants/me/attachments/${a.id}?message_id=${t.id}`);e.push(r)}return e}async summarizeText(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/summarize","POST",{message:{body:t}},!0,this.nylasAuth.config.elementsApiUri);if(i.Xr(e))throw new i.Zr(e.error);return e.data.summary}async textToSpeech(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");return this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/tts","POST",{text:t},!1,this.nylasAuth.config.elementsApiUri,{...e?{signal:e==null?void 0:e.signal}:{}})}}class w{constructor(t,e,s,a){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s,this.router=a}async getThreads(t,e="overwrite",s=!0){var c;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");s&&(this.nylasMailboxStore.state.state="loading");const a=t||this.nylasMailboxStore.state.threadsQueryParams,r=new URLSearchParams;for(const y in a){const d=(c=a[y])==null?void 0:c.toString();typeof d<"u"&&d!==null&&r.append(y,d)}a.search_query_native?this.router.navigate(`/?query=${a.search_query_native}`,!0):this.nylasMailboxStore.state.threadsQueryParams.search_query_native&&!a.search_query_native&&this.router.navigate("/",!0),a.page_token||(this.nylasMailboxStore.state.previousThreadPageTokens=[]),this.nylasMailboxStore.state.threadsQueryParams=a;const n=`/v3/grants/me/threads?${r.toString()}`,h=await this.nylasAuth.nylasAPIRequest(n);if(i.Xr(h))throw new i.Zr(h.error);const u=h.data;switch(e){case"prepend":this.nylasMailboxStore.state.threads=[...u,...this.nylasMailboxStore.state.threads];break;case"append":this.nylasMailboxStore.state.threads=[...this.nylasMailboxStore.state.threads,...u];break;case"overwrite":default:this.nylasMailboxStore.state.threads=u;break}return h.next_cursor?this.nylasMailboxStore.state.nextThreadPageToken=h.next_cursor:this.nylasMailboxStore.state.nextThreadPageToken=null,s&&(this.nylasMailboxStore.state.state="ready"),u}async getThread(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");const e=this.nylasMailboxStore.state.threads.find(n=>n.id===t);if(e)return e;this.nylasMailboxStore.state.state="loading";const s=`/v3/grants/me/threads/${t}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.state="ready",r}async nextThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.nextThreadPageToken)throw new Error("No next page token");this.nylasMailboxStore.state.previousThreadPageTokens=Array.from(new Set([...this.nylasMailboxStore.state.previousThreadPageTokens,this.nylasMailboxStore.state.threadsQueryParams.page_token??null]));const s=this.nylasMailboxStore.state.nextThreadPageToken;return this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:s},t,e)}async previousThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.previousThreadPageTokens.length)throw new Error("No previous page token");const s=[...this.nylasMailboxStore.state.previousThreadPageTokens],a=s.pop();return this.nylasMailboxStore.state.previousThreadPageTokens=s,this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:a??void 0},t,e)}updateThreadQueryParams(t){this.nylasMailboxStore.state.threadsQueryParams={...this.nylasMailboxStore.state.threadsQueryParams,...t}}back(){this.router.navigate("/",!0),this.nylasMailboxStore.state.selectedThread=null}unSelectThread(){this.nylasMailboxStore.state.selectedThread=null}async selectThread(t){this.router.navigate(`/thread/${t.id}`,!0),this.nylasMailboxStore.state.selectedThread=t,t.unread&&this.markThreadAsRead(t).catch(e=>{o.debug("Error marking thread as read",e)})}async markThreadAsRead(t){return this.updateThread(t,{unread:!1})}async updateThread(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email","modify"))throw new Error("Missing thread:modify scope");const s=`/v3/grants/me/threads/${t.id}`,a=await this.nylasAuth.nylasAPIRequest(s,"PUT",e);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.selectedThread=r,r}}class m{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getFolders(){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");this.nylasMailboxStore.state.state="loading";const t="/v3/grants/me/folders",e=await this.nylasAuth.nylasAPIRequest(t);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.folders=s,this.nylasMailboxStore.state.state="ready",s}async selectFolder(t){this.nylasMailboxStore.state.threadsQueryParams={in:t.id,...this.nylasMailboxStore.state.threadsQueryParams||{}}}}class p extends Event{constructor(t,e){super(t,e),this.oldURL=e.oldURL,this.newURL=e.newURL}}class S{constructor(){this.routeChangeListeners=[],o.debug("HashRouter constructor")}destroy(){o.debug("HashRouter destroy"),window.removeEventListener("hashchange",this.onRouteChange.bind(this))}init(){if(o.debug("HashRouter init"),window.addEventListener("hashchange",this.onRouteChange.bind(this)),typeof HashChangeEvent<"u"){const t=new HashChangeEvent("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}else{const t=new p("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}}addRouteChangeListener(t,e){o.debug("HashRouter addRouteChangeListener"),this.routeChangeListeners.push([t,e])}navigate(t,e){if(o.debug("HashRouter navigate"),e)return window.history.pushState(null,"",`#${t}`);window.location.hash=t}setRoute(t){o.debug("HashRouter setRoute"),window.location.hash=t}matchRoute(t,e){const s=t.split("/"),a=e.split("/");if(o.debug(`HashRouter matchRoute route=${t} path=${e}`,{routeParts:s,pathParts:a}),s[1]===""&&a[0]==="")return!0;if(s.length!==a.length)return!1;for(let r=0;r<s.length;r++){const n=s[r],h=a[r];if(!n.startsWith(":")&&n!==h)return!1}return!0}getRouteParams(t){o.debug("HashRouter getRouteParams");const e={},s=t.split("/"),a=window.location.hash.split("/");return s.forEach((r,n)=>{if(r.startsWith(":")){const h=r.substring(1);e[h]=a[n]}}),e}getRouteWithParams(t,e){o.debug("HashRouter getRouteWithParams");let s=t;return Object.keys(e).forEach(a=>{s=s.replace(`:${a}`,e[a])}),s}getRoute(){return o.debug("HashRouter getRoute"),window.location.hash}onRouteChange(t){this.routeChangeListeners.forEach(async([e,s])=>{const a=t.newURL.indexOf("#")===-1?"":t.newURL.substring(t.newURL.indexOf("#")+1);if(o.debug(`HashRouter onRouteChange route=${e} path=${a}`,{event:t}),!this.matchRoute(e,a)){o.debug(`HashRouter onRouteChange route=${e} path=${a} does not match`);return}const r=this.getRouteParams(e);await s(e,a,r)})}getBasePath(){return o.debug("HashRouter getBasePath"),""}}function A(l={}){const t={isAuthenticated:!1,tokenInfo:null,state:"ready",...l},e=i.createStore(t);return e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}function T(l={}){const t={state:"ready",messages:[],threads:[],folders:[],selectedThread:null,nextThreadPageToken:null,previousThreadPageTokens:[],searchQuery:"",hasNextThreadPage:!1,hasPreviousThreadPage:!1,selectedFolder:"inbox",threadsQueryParams:{in:"inbox"},messgeQueryParams:{fields:"include_headers"},...l},e=i.createStore({...t});return e.onChange("nextThreadPageToken",s=>{e.set("hasNextThreadPage",s!==null)}),e.onChange("previousThreadPageTokens",s=>{e.set("hasPreviousThreadPage",s.length>0)}),e.onChange("threadsQueryParams",s=>{e.set("selectedFolder",s.in||"inbox"),e.set("searchQuery",s.search_query_native||"")}),e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}exports.CreateNylasAuthStore=A;exports.CreateNylasMailboxStore=T;exports.HashRouter=S;exports.NylasAuthConnector=g;exports.NylasFoldersConnector=m;exports.NylasMessagesConnector=f;exports.NylasThreadsConnector=w;
|
|
1
|
+
"use strict";const o=require("./utils-5074a070-d5ba6add.cjs"),i=require("./index-b30d446a-3d69a3cc.cjs");class g{constructor(t,e){this.nylasAuth=t,this.nylasAuthStore=e}async validateSession(){const t=await this.isAccessTokenValid();if(!t)this.logout();else{let e=await this.nylasAuth.getTokenInfo();if(e){const a=Math.floor(Date.now()/1e3);if(e.expires_in&&e.expires_in-a<3e5&&(o.debug("[NylasAuthConnectorMixin] Refreshing access token"),e=await this.nylasAuth.refreshAccessToken(),!e)){o.debug("[NylasAuthConnectorMixin] Token is expired and could not be refreshed. Logging out."),this.logout();return}this.nylasAuthStore.state.tokenInfo=e}}this.nylasAuthStore.state.isAuthenticated=t}async isAuthenticated(){return this.nylasAuth.isAuthenticated()}async getTokenInfo(){return this.nylasAuth.getTokenInfo()}async isAccessTokenValid(){return this.nylasAuth.isAccessTokenValid()}async logout(){await this.nylasAuth.logout()}async getHostedAuthRedirectURL(t,e,s){return this.nylasAuth.getHostedAuthRedirectURL(t,e,s)}async manageHostedAuthCodeExchange(t){const s=new URL(t).searchParams.get("code");if(s){const a=await this.nylasAuth.exchangeAuthCodeForTokenInfo(s);if(a)return this.nylasAuthStore.state.tokenInfo=a,this.nylasAuthStore.state.isAuthenticated=!0,a}return null}}class f{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getMessages(){var n;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");this.nylasMailboxStore.state.state="loading";const t=this.nylasMailboxStore.state.messgeQueryParams,e=new URLSearchParams;for(const h in t){const u=(n=t[h])==null?void 0:n.toString();u&&e.append(h,u)}const s=`/v3/grants/me/messages?${e.toString()}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.messages=r,this.nylasMailboxStore.state.state="ready",r}async getThreadMessages(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest(`/v3/grants/me/messages?thread_id=${t}&fields=include_headers`);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.messages=s,s}downloadMessageAttachments(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=[],s=t.attachments||[];for(const a of s){const r=this.nylasAuth.nylasDownloadFileRequest(`/v3/grants/me/attachments/${a.id}?message_id=${t.id}`);e.push(r)}return e}async summarizeText(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/summarize","POST",{message:{body:t}},!0,this.nylasAuth.config.elementsApiUri);if(i.Xr(e))throw new i.Zr(e.error);return e.data.summary}async textToSpeech(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");return this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/tts","POST",{text:t},!1,this.nylasAuth.config.elementsApiUri,{...e?{signal:e==null?void 0:e.signal}:{}})}}class w{constructor(t,e,s,a){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s,this.router=a}async getThreads(t,e="overwrite",s=!0){var c;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");s&&(this.nylasMailboxStore.state.state="loading");const a=t||this.nylasMailboxStore.state.threadsQueryParams,r=new URLSearchParams;for(const y in a){const d=(c=a[y])==null?void 0:c.toString();typeof d<"u"&&d!==null&&r.append(y,d)}a.search_query_native?this.router.navigate(`/?query=${a.search_query_native}`,!0):this.nylasMailboxStore.state.threadsQueryParams.search_query_native&&!a.search_query_native&&this.router.navigate("/",!0),a.page_token||(this.nylasMailboxStore.state.previousThreadPageTokens=[]),this.nylasMailboxStore.state.threadsQueryParams=a;const n=`/v3/grants/me/threads?${r.toString()}`,h=await this.nylasAuth.nylasAPIRequest(n);if(i.Xr(h))throw new i.Zr(h.error);const u=h.data;switch(e){case"prepend":this.nylasMailboxStore.state.threads=[...u,...this.nylasMailboxStore.state.threads];break;case"append":this.nylasMailboxStore.state.threads=[...this.nylasMailboxStore.state.threads,...u];break;case"overwrite":default:this.nylasMailboxStore.state.threads=u;break}return h.next_cursor?this.nylasMailboxStore.state.nextThreadPageToken=h.next_cursor:this.nylasMailboxStore.state.nextThreadPageToken=null,s&&(this.nylasMailboxStore.state.state="ready"),u}async getThread(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");const e=this.nylasMailboxStore.state.threads.find(n=>n.id===t);if(e)return e;this.nylasMailboxStore.state.state="loading";const s=`/v3/grants/me/threads/${t}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.state="ready",r}async nextThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.nextThreadPageToken)throw new Error("No next page token");this.nylasMailboxStore.state.previousThreadPageTokens=Array.from(new Set([...this.nylasMailboxStore.state.previousThreadPageTokens,this.nylasMailboxStore.state.threadsQueryParams.page_token??null]));const s=this.nylasMailboxStore.state.nextThreadPageToken;return this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:s},t,e)}async previousThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.previousThreadPageTokens.length)throw new Error("No previous page token");const s=[...this.nylasMailboxStore.state.previousThreadPageTokens],a=s.pop();return this.nylasMailboxStore.state.previousThreadPageTokens=s,this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:a??void 0},t,e)}updateThreadQueryParams(t){this.nylasMailboxStore.state.threadsQueryParams={...this.nylasMailboxStore.state.threadsQueryParams,...t}}back(){this.router.navigate("/",!0),this.nylasMailboxStore.state.selectedThread=null}unSelectThread(){this.nylasMailboxStore.state.selectedThread=null}async selectThread(t){this.router.navigate(`/thread/${t.id}`,!0),this.nylasMailboxStore.state.selectedThread=t,t.unread&&this.markThreadAsRead(t).catch(e=>{o.debug("Error marking thread as read",e)})}async markThreadAsRead(t){return this.updateThread(t,{unread:!1})}async updateThread(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email","modify"))throw new Error("Missing thread:modify scope");const s=`/v3/grants/me/threads/${t.id}`,a=await this.nylasAuth.nylasAPIRequest(s,"PUT",e);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.selectedThread=r,r}}class m{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getFolders(){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");this.nylasMailboxStore.state.state="loading";const t="/v3/grants/me/folders",e=await this.nylasAuth.nylasAPIRequest(t);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.folders=s,this.nylasMailboxStore.state.state="ready",s}async selectFolder(t){this.nylasMailboxStore.state.threadsQueryParams={in:t.id,...this.nylasMailboxStore.state.threadsQueryParams||{}}}}class p extends Event{constructor(t,e){super(t,e),this.oldURL=e.oldURL,this.newURL=e.newURL}}class S{constructor(){this.routeChangeListeners=[],o.debug("HashRouter constructor")}destroy(){o.debug("HashRouter destroy"),window.removeEventListener("hashchange",this.onRouteChange.bind(this))}init(){if(o.debug("HashRouter init"),window.addEventListener("hashchange",this.onRouteChange.bind(this)),typeof HashChangeEvent<"u"){const t=new HashChangeEvent("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}else{const t=new p("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}}addRouteChangeListener(t,e){o.debug("HashRouter addRouteChangeListener"),this.routeChangeListeners.push([t,e])}navigate(t,e){if(o.debug("HashRouter navigate"),e)return window.history.pushState(null,"",`#${t}`);window.location.hash=t}setRoute(t){o.debug("HashRouter setRoute"),window.location.hash=t}matchRoute(t,e){const s=t.split("/"),a=e.split("/");if(o.debug(`HashRouter matchRoute route=${t} path=${e}`,{routeParts:s,pathParts:a}),s[1]===""&&a[0]==="")return!0;if(s.length!==a.length)return!1;for(let r=0;r<s.length;r++){const n=s[r],h=a[r];if(!n.startsWith(":")&&n!==h)return!1}return!0}getRouteParams(t){o.debug("HashRouter getRouteParams");const e={},s=t.split("/"),a=window.location.hash.split("/");return s.forEach((r,n)=>{if(r.startsWith(":")){const h=r.substring(1);e[h]=a[n]}}),e}getRouteWithParams(t,e){o.debug("HashRouter getRouteWithParams");let s=t;return Object.keys(e).forEach(a=>{s=s.replace(`:${a}`,e[a])}),s}getRoute(){return o.debug("HashRouter getRoute"),window.location.hash}onRouteChange(t){this.routeChangeListeners.forEach(async([e,s])=>{const a=t.newURL.indexOf("#")===-1?"":t.newURL.substring(t.newURL.indexOf("#")+1);if(o.debug(`HashRouter onRouteChange route=${e} path=${a}`,{event:t}),!this.matchRoute(e,a)){o.debug(`HashRouter onRouteChange route=${e} path=${a} does not match`);return}const r=this.getRouteParams(e);await s(e,a,r)})}getBasePath(){return o.debug("HashRouter getBasePath"),""}}function A(l={}){const t={isAuthenticated:!1,tokenInfo:null,state:"ready",...l},e=i.createStore(t);return e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}function T(l={}){const t={state:"ready",messages:[],threads:[],folders:[],selectedThread:null,nextThreadPageToken:null,previousThreadPageTokens:[],searchQuery:"",hasNextThreadPage:!1,hasPreviousThreadPage:!1,selectedFolder:"inbox",threadsQueryParams:{in:"inbox"},messgeQueryParams:{fields:"include_headers"},...l},e=i.createStore({...t});return e.onChange("nextThreadPageToken",s=>{e.set("hasNextThreadPage",s!==null)}),e.onChange("previousThreadPageTokens",s=>{e.set("hasPreviousThreadPage",s.length>0)}),e.onChange("threadsQueryParams",s=>{e.set("selectedFolder",s.in||"inbox"),e.set("searchQuery",s.search_query_native||"")}),e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}exports.CreateNylasAuthStore=A;exports.CreateNylasMailboxStore=T;exports.HashRouter=S;exports.NylasAuthConnector=g;exports.NylasFoldersConnector=m;exports.NylasMessagesConnector=f;exports.NylasThreadsConnector=w;
|