@nylas/web-elements 1.4.2 → 1.4.4
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/cdn/nylas-scheduler-editor/nylas-scheduler-editor.es.js +56 -27
- package/dist/cdn/nylas-scheduling/nylas-scheduling.es.js +4842 -4822
- package/dist/cjs/checkmark-icon_15.cjs.entry.js +3 -3
- package/dist/cjs/checkmark-icon_15.cjs.entry.js.map +1 -1
- package/dist/cjs/google-logo-icon_6.cjs.entry.js +4 -4
- package/dist/cjs/input-component.cjs.entry.js +13 -2
- package/dist/cjs/input-component.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/nylas-booked-event-card_12.cjs.entry.js +40 -11
- package/dist/cjs/nylas-booked-event-card_12.cjs.entry.js.map +1 -1
- package/dist/cjs/nylas-event-calendar_3.cjs.entry.js +53 -24
- package/dist/cjs/nylas-event-calendar_3.cjs.entry.js.map +1 -1
- package/dist/cjs/nylas-provider.cjs.entry.js +1 -1
- package/dist/cjs/nylas-scheduling.cjs.entry.js +3 -3
- package/dist/cjs/nylas-web-elements.cjs.js +1 -1
- package/dist/cjs/{scheduler-store-d6f5cff3.js → scheduler-store-5dcefe7e.js} +2 -2
- package/dist/cjs/{scheduler-store-d6f5cff3.js.map → scheduler-store-5dcefe7e.js.map} +1 -1
- package/dist/collection/components/design-system/input-component/input-component.js +13 -2
- package/dist/collection/components/design-system/input-component/input-component.js.map +1 -1
- package/dist/collection/components/scheduler/nylas-date-picker/nylas-date-picker.js +40 -6
- package/dist/collection/components/scheduler/nylas-date-picker/nylas-date-picker.js.map +1 -1
- package/dist/collection/components/scheduler/nylas-timeslot-picker/nylas-timeslot-picker.js +8 -5
- package/dist/collection/components/scheduler/nylas-timeslot-picker/nylas-timeslot-picker.js.map +1 -1
- package/dist/collection/components/scheduler-editor/nylas-event-calendar/nylas-event-calendar.js +28 -17
- package/dist/collection/components/scheduler-editor/nylas-event-calendar/nylas-event-calendar.js.map +1 -1
- package/dist/collection/components/scheduler-editor/nylas-event-capacity/nylas-event-capacity.css +15 -0
- package/dist/collection/components/scheduler-editor/nylas-event-capacity/nylas-event-capacity.js +13 -2
- package/dist/collection/components/scheduler-editor/nylas-event-capacity/nylas-event-capacity.js.map +1 -1
- package/dist/collection/components/scheduler-editor/nylas-event-timeslot/nylas-event-timeslot.css +1 -1
- package/dist/collection/components/scheduler-editor/nylas-event-timeslot/nylas-event-timeslot.js +12 -4
- package/dist/collection/components/scheduler-editor/nylas-event-timeslot/nylas-event-timeslot.js.map +1 -1
- package/dist/collection/components/scheduler-editor/nylas-event-title/nylas-event-title.js +3 -3
- package/dist/collection/components/scheduler-editor/nylas-event-title/nylas-event-title.js.map +1 -1
- package/dist/components/index.es.js +1 -1
- package/dist/components/input-component2.js +13 -2
- package/dist/components/input-component2.js.map +1 -1
- package/dist/components/nylas-date-picker2.js +38 -8
- package/dist/components/nylas-date-picker2.js.map +1 -1
- package/dist/components/nylas-editor-tabs-group2.js +2 -2
- package/dist/components/nylas-editor-tabs2.js +2 -2
- package/dist/components/nylas-event-calendar2.js +29 -18
- package/dist/components/nylas-event-calendar2.js.map +1 -1
- package/dist/components/nylas-event-capacity2.js +14 -3
- package/dist/components/nylas-event-capacity2.js.map +1 -1
- package/dist/components/nylas-event-timeslot2.js +14 -6
- package/dist/components/nylas-event-timeslot2.js.map +1 -1
- package/dist/components/nylas-event-title2.js +3 -3
- package/dist/components/nylas-event-title2.js.map +1 -1
- package/dist/components/nylas-list-configurations2.js +1 -1
- package/dist/components/nylas-locale-switch2.js +1 -1
- package/dist/components/nylas-scheduler-editor.js +1 -1
- package/dist/components/nylas-scheduling.js +3 -3
- package/dist/components/nylas-timeslot-picker2.js +9 -6
- package/dist/components/nylas-timeslot-picker2.js.map +1 -1
- package/dist/components/scheduler-store.js +2 -2
- package/dist/components/utils.js +1 -1
- package/dist/esm/calendar-agenda-fill-icon_36.entry.js +2 -2
- package/dist/esm/checkmark-icon_15.entry.js +5 -5
- package/dist/esm/checkmark-icon_15.entry.js.map +1 -1
- package/dist/esm/{feedbackSync-aa8d23d1.js → feedbackSync-57bb471a.js} +2 -2
- package/dist/esm/{feedbackSync-aa8d23d1.js.map → feedbackSync-57bb471a.js.map} +1 -1
- package/dist/esm/globe-icon_2.entry.js +1 -1
- package/dist/esm/google-logo-icon_6.entry.js +7 -7
- package/dist/esm/{index.es-6d4b50d5.js → index.es-13ff6710.js} +2 -2
- package/dist/esm/{index.es-6d4b50d5.js.map → index.es-13ff6710.js.map} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/input-component.entry.js +14 -3
- package/dist/esm/input-component.entry.js.map +1 -1
- package/dist/esm/input-dropdown_2.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/multi-select-dropdown_2.entry.js +1 -1
- package/dist/esm/{nylas-api-request-c5400df5.js → nylas-api-request-2e5f4c7f.js} +2 -2
- package/dist/esm/{nylas-api-request-c5400df5.js.map → nylas-api-request-2e5f4c7f.js.map} +1 -1
- package/dist/esm/nylas-booked-event-card_12.entry.js +42 -13
- package/dist/esm/nylas-booked-event-card_12.entry.js.map +1 -1
- package/dist/esm/nylas-event-calendar_3.entry.js +55 -26
- package/dist/esm/nylas-event-calendar_3.entry.js.map +1 -1
- package/dist/esm/nylas-form-card.entry.js +2 -2
- package/dist/esm/nylas-if-state.entry.js +2 -2
- package/dist/esm/nylas-login.entry.js +2 -2
- package/dist/esm/nylas-provider.entry.js +3 -3
- package/dist/esm/nylas-scheduler-editor.entry.js +3 -3
- package/dist/esm/nylas-scheduling.entry.js +6 -6
- package/dist/esm/nylas-web-elements.js +1 -1
- package/dist/esm/{register-component-238f28de.js → register-component-02a05665.js} +2 -2
- package/dist/esm/{register-component-238f28de.js.map → register-component-02a05665.js.map} +1 -1
- package/dist/esm/{scheduler-store-82bb212a.js → scheduler-store-fe9e85a4.js} +3 -3
- package/dist/esm/{scheduler-store-82bb212a.js.map → scheduler-store-fe9e85a4.js.map} +1 -1
- package/dist/esm/textarea-component.entry.js +1 -1
- package/dist/esm/{utils-7d962146.js → utils-e27d0e4b.js} +2 -2
- package/dist/esm/{utils-7d962146.js.map → utils-e27d0e4b.js.map} +1 -1
- package/dist/nylas-web-elements/index.esm.js +1 -1
- package/dist/nylas-web-elements/nylas-web-elements.esm.js +1 -1
- package/dist/nylas-web-elements/nylas-web-elements.esm.js.map +1 -1
- package/dist/nylas-web-elements/{p-12bf5148.js → p-189b24e6.js} +2 -2
- package/dist/nylas-web-elements/p-1cbe8a56.entry.js +2 -0
- package/dist/nylas-web-elements/{p-d132fbaa.entry.js.map → p-1cbe8a56.entry.js.map} +1 -1
- package/dist/nylas-web-elements/{p-fdc35ad8.entry.js → p-23971057.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-ba831977.entry.js → p-2dd05606.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-797578de.js → p-388c456c.js} +2 -2
- package/dist/nylas-web-elements/{p-cf650f4f.js → p-3ea1c7c9.js} +2 -2
- package/dist/nylas-web-elements/{p-de9d8218.entry.js → p-5f683e34.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-c2b6e0ca.entry.js → p-68ab7563.entry.js} +2 -2
- package/dist/nylas-web-elements/p-68ab7563.entry.js.map +1 -0
- package/dist/nylas-web-elements/{p-ec2c12a9.js → p-6b7fb948.js} +2 -2
- package/dist/nylas-web-elements/{p-cfd42146.js → p-7477410d.js} +2 -2
- package/dist/nylas-web-elements/{p-b62ef1be.js → p-7d9cdd23.js} +2 -2
- package/dist/nylas-web-elements/{p-00577fba.entry.js → p-8a7a6947.entry.js} +2 -2
- package/dist/nylas-web-elements/p-97f87422.entry.js +2 -0
- package/dist/nylas-web-elements/p-97f87422.entry.js.map +1 -0
- package/dist/nylas-web-elements/{p-9999c233.entry.js → p-aaf12216.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-a452d4ea.entry.js → p-b55a87fa.entry.js} +2 -2
- package/dist/nylas-web-elements/p-b55a87fa.entry.js.map +1 -0
- package/dist/nylas-web-elements/{p-888d0c66.entry.js → p-c5f86111.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-dd98c443.entry.js → p-cc6dbd73.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-b59288fd.entry.js → p-d5a2cec8.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-83216795.entry.js → p-deb33dfb.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-83216795.entry.js.map → p-deb33dfb.entry.js.map} +1 -1
- package/dist/nylas-web-elements/{p-2531d4fa.entry.js → p-e2dc32d9.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-a263330c.entry.js → p-eedabd6a.entry.js} +2 -2
- package/dist/nylas-web-elements/{p-355b34cb.entry.js → p-f57e68b1.entry.js} +2 -2
- package/dist/types/components/scheduler/nylas-date-picker/nylas-date-picker.d.ts +4 -0
- package/dist/types/components/scheduler-editor/nylas-event-capacity/nylas-event-capacity.d.ts +1 -0
- package/package.json +4 -5
- package/CHANGELOG.md +0 -878
- package/dist/nylas-web-elements/p-203beca4.entry.js +0 -2
- package/dist/nylas-web-elements/p-203beca4.entry.js.map +0 -1
- package/dist/nylas-web-elements/p-a452d4ea.entry.js.map +0 -1
- package/dist/nylas-web-elements/p-c2b6e0ca.entry.js.map +0 -1
- package/dist/nylas-web-elements/p-d132fbaa.entry.js +0 -2
- /package/dist/nylas-web-elements/{p-12bf5148.js.map → p-189b24e6.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-fdc35ad8.entry.js.map → p-23971057.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-ba831977.entry.js.map → p-2dd05606.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-797578de.js.map → p-388c456c.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-cf650f4f.js.map → p-3ea1c7c9.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-de9d8218.entry.js.map → p-5f683e34.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-ec2c12a9.js.map → p-6b7fb948.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-cfd42146.js.map → p-7477410d.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-b62ef1be.js.map → p-7d9cdd23.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-00577fba.entry.js.map → p-8a7a6947.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-9999c233.entry.js.map → p-aaf12216.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-888d0c66.entry.js.map → p-c5f86111.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-dd98c443.entry.js.map → p-cc6dbd73.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-b59288fd.entry.js.map → p-d5a2cec8.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-2531d4fa.entry.js.map → p-e2dc32d9.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-a263330c.entry.js.map → p-eedabd6a.entry.js.map} +0 -0
- /package/dist/nylas-web-elements/{p-355b34cb.entry.js.map → p-f57e68b1.entry.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,c as a,h as l}from"./p-6f5a3998.js";import{n as r}from"./p-
|
|
2
|
-
//# sourceMappingURL=p-
|
|
1
|
+
import{r as e,c as a,h as l}from"./p-6f5a3998.js";import{n as r}from"./p-6b7fb948.js";import"./p-c79dcb59.js";const s=':host{display:block;--nylas-primary:#2563eb;--nylas-error:#cc4841;--nylas-error-pressed:#992222;--nylas-wraning:#f06c00;--nylas-success:#16a392;--nylas-info:#2b8fc2;--nylas-base-0:#ffffff;--nylas-base-25:#fcfcfd;--nylas-base-50:#f8f9fc;--nylas-base-100:#eaecf5;--nylas-base-200:#d5d9eb;--nylas-base-300:#b3b8d8;--nylas-base-400:#717bbc;--nylas-base-500:#4e5ba6;--nylas-base-600:#3e4784;--nylas-base-700:#263f72;--nylas-base-800:#293056;--nylas-base-900:#101323;--nylas-base-950:#0e101b;--nylas-color-blue-100:#e0e6f9;--nylas-border-radius:0.25rem;--nylas-border-radius-2x:0.5rem;--nylas-border-radius-3x:0.75rem;--nylas-font-family:"Inter", sans-serif;--nylas-color-black:#000000;--nylas-color-grey-900:#2c2c2c;--nylas-color-grey-800:#4b4b4b;--nylas-color-grey-700:#6e6e6e;--nylas-color-grey-600:#8e8e8e;--nylas-color-grey-500:#b3b3b3;--nylas-color-grey-400:#cacaca;--nylas-color-grey-300:#e1e1e1;--nylas-color-grey-200:#eaeaea;--nylas-color-grey-100:#f5f5f5;--nylas-color-grey-50:#fbfcfe;--nylas-color-white:#ffffff;--nylas-color-red-900:#992222;--nylas-color-red-700:#cc4841;--nylas-color-red-500:#ff786a;--nylas-color-red-300:#ffa79e;--nylas-color-red-100:#ffc5bf;--nylas-color-red-50:#ffeae8;--nylas-color-blue-900:#213571;--nylas-color-blue-700:#314fa9;--nylas-color-blue-500:#4169e1;--nylas-color-blue-300:#bdccf9;--nylas-color-blue-100:#e0e6f9;--nylas-color-blue-50:#f6f8fd;--nylas-color-yellow-900:#7c6506;--nylas-color-yellow-700:#c29f09;--nylas-color-yellow-500:#f7c90b;--nylas-color-yellow-300:#f9de70;--nylas-color-yellow-100:#fceba9;--nylas-color-yellow-50:#fdf4ce;--nylas-color-green-900:#0e6b60;--nylas-color-green-700:#16a392;--nylas-color-green-500:#17c3b2;--nylas-color-green-300:#74dbd1;--nylas-color-green-100:#a2e7e0;--nylas-color-green-50:#d1f3f0;--nylas-color-purple-900:#643554;--nylas-color-purple-700:#954f7d;--nylas-color-purple-500:#c769a7;--nylas-color-purple-300:#dda5ca;--nylas-color-purple-100:#e0bdd6;--nylas-color-purple-50:#e9dde5;--nylas-color-sky-900:#20698f;--nylas-color-sky-700:#2b8fc2;--nylas-color-sky-500:#6dceff;--nylas-color-sky-300:#8fdaff;--nylas-color-sky-100:#b8e7ff;--nylas-color-sky-50:#d9f2ff;width:100%}label{display:flex;color:var(--nylas-base-800, #293056);font-size:14px;font-style:normal;font-weight:400;line-height:150%;flex-direction:column;gap:4px;font-family:var(--nylas-font-family);font-size:16px;color:var(--nylas-base-800)}label.error{color:var(--nylas-error)}label span.required{color:var(--nylas-error);padding:0 0.25rem}label p{margin:0;display:flex;gap:4px;align-items:center}label .error{color:var(--nylas-error)}textarea{display:flex;height:48px;padding-left:16px;align-items:center;gap:8px;align-self:stretch;border-radius:var(--nylas-border-radius-2x);border:1px solid var(--nylas-base-300);background:var(--nylas-base-0);width:-webkit-fill-available;color:var(--nylas-base-900);font-size:16px;font-style:normal;font-weight:400;line-height:150%;padding:12px 16px;border-width:1;resize:vertical;border-radius:8px;font-family:var(--nylas-font-family);font-size:16px;line-height:24px}textarea:focus{outline-color:var(--nylas-primary)}textarea.error{border-radius:var(--nylas-border-radius-2x);font-weight:600;border-color:var(--nylas-error);border-width:2px}textarea.error::placeholder{font-weight:400}textarea::placeholder{color:var(--nylas-base-300)}textarea::-webkit-resizer{display:none}textarea:read-only{background-color:var(--nylas-base-100);cursor:not-allowed}';const o=s;const n=class{constructor(l){e(this,l);this.nylasFormInputChanged=a(this,"nylasFormInputChanged",7);this.name="textarea";this.defaultValue=undefined;this.label="";this.placeholder="";this.required=false;this.readOnly=false;this.autoFocus=false;this.maxLength=255;this.type="multi_line_text";this.tooltip="";this.value="";this.error=""}componentDidLoad(){this.value=r(this.defaultValue||"")}handleBookingFormSubmitted(e){this.validate(this.value);if(this.error){e.preventDefault()}}handletriggerValidation(e){this.validate(this.value);if(this.error){e.preventDefault()}}handleInput(e){this.error="";const a=e.target;this.value=r(a.value);this.nylasFormInputChanged.emit({value:this.value,name:this.name,error:this.error,label:this.label,type:this.type})}validate(e){if(this.required&&!e){this.error=`${this.label} is required.`}else if(e.length>this.maxLength){this.error=`${this.label} cannot exceed ${this.maxLength} characters.`}else{this.error=""}}render(){return l("label",{key:"dfa36b319e151ee064e1dce59391cc1be9cd2284",part:"tc__label",class:{error:!!this.error}},l("p",{key:"5dfc3110496c05244225cabc70ccca711b4cbb3b"},l("span",{key:"87c2996b6a258d78f829fe57bcab0654216ec3b9",class:"label"},this.label),this.required&&l("span",{class:"required"},"*"),this.tooltip&&l("tooltip-component",null,l("info-icon",{slot:"tooltip-icon"}),l("span",{slot:"tooltip-content"},this.tooltip))),l("textarea",{key:"ed5c0c9044999404daa9282b70e31698a4571463",name:this.name,title:this.readOnly?"read-only field":undefined,placeholder:this.placeholder,readOnly:this.readOnly,autoFocus:this.autoFocus,value:this.value,maxLength:this.maxLength,onInput:e=>this.handleInput(e),class:{error:!!this.error},part:"tc__textarea"}),this.error&&l("span",{class:"error help-text"},this.error))}};n.style=o;export{n as textarea_component};
|
|
2
|
+
//# sourceMappingURL=p-e2dc32d9.entry.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{h,F as Fragment,r as registerInstance,c as createEvent,H as Host,a as getElement}from"./p-6f5a3998.js";import{X as Xr,N as NylasBaseProvider}from"./p-12bf5148.js";import{N as NylasIdentityRequestWrapper}from"./p-cfd42146.js";import{t as timezone,d as dataResponse,c as getCalendarRange,a as debug,B as Buffer,p as process,i as instance}from"./p-ec2c12a9.js";import{a as dayjs,u as utc,c as commonjsGlobal}from"./p-c79dcb59.js";import{C as CreateNylasSchedulerConfigStore}from"./p-14894041.js";import{C as CONFIGURATION_EVENT_TYPE,E as EXPERIMENTAL_FEATURES,L as LANGUAGE_CODE,a as LANGUAGE_MAP}from"./p-6f7cb609.js";import"./p-fc5bc07b.js";dayjs.extend(utc);dayjs.extend(timezone);class NylasSchedulerConfigAPIConnector{constructor({nylasApiRequest:e,nylasSchedulerConfigStore:t}){this.nylasApiRequest=e;this.nylasSchedulerConfigStore=t}async currentUser(){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return null}return this.nylasApiRequest.currentUser()}async getCalendars(){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching calendars: Nylas API Request is not initialized"})}const[e,t]=await this.nylasApiRequest.request({method:"GET",path:`calendars`});if(t){return dataResponse(null,{message:"Error fetching calendars: "+t.message})}if(Xr(e)){return dataResponse(null,{message:"Error fetching calendars: "+e.error?.message})}this.nylasSchedulerConfigStore.state.calendars=e.data;return dataResponse(e.data)}async getConfigurationById(e,t=false){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching configuration: Nylas API Request is not initialized"})}if(!t){const t=this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e));if(t){this.nylasSchedulerConfigStore.state.selectedConfiguration=t;return dataResponse(t)}}const[n,i]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations/${e}`});if(i){return dataResponse(null,{message:"Error fetching configuration: "+i.message})}if(Xr(n)){return dataResponse(null,{message:"Error fetching configuration: "+n.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=n.data;if(this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e))){this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.map((t=>t.id===e?n.data:t))}else{this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,n.data]}return dataResponse(n.data)}async getConfigurations(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching configurations: Nylas API Request is not initialized"})}const t=50;const[n,i]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations?limit=${t}${e?`&page_token=${e}`:""}`});if(i){return dataResponse(null,{message:"Error fetching configurations: "+i.message})}if(Xr(n)){return dataResponse(null,{message:"Error fetching configurations: "+n.error?.message})}this.nylasSchedulerConfigStore.state.configurations=n.data;this.nylasSchedulerConfigStore.state.listConfigurationsNextCursor=n.next_cursor||null;return dataResponse(n.data)}async getMasterEventById(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching master event: Nylas API Request is not initialized"})}const t=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const n=t?.event?.calendar_id;if(!n){console.warn("Calendar ID is not present");return dataResponse(null,{message:"Error fetching master event: Calendar ID is not present"})}const i=new URLSearchParams;i.append("calendar_id",n);const[s,r]=await this.nylasApiRequest.request({method:"GET",path:`events/${e}?${i.toString()}`});if(r){return dataResponse(null,{message:"Error fetching master event: "+r.message})}if(Xr(s)){return dataResponse(null,{message:"Error fetching master event: "+s.error?.message})}const o=this.nylasSchedulerConfigStore.state.masterGroupEvents;if(o[e]){this.nylasSchedulerConfigStore.state.masterGroupEvents[e]=s.data}else{this.nylasSchedulerConfigStore.state.masterGroupEvents={...o,[e]:s.data}}return dataResponse(s.data)}async createConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error creating configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations`,body:e});if(n){return dataResponse(null,{message:"Error creating configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error creating configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=t.data;this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,t.data];return dataResponse(t.data)}async updateConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error updating configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"PUT",path:`scheduling/configurations/${e.id}`,body:e});if(n){return dataResponse(null,{message:"Error updating configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error updating configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=t.data;if(this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e.id))){this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.map((n=>n.id===e.id?t.data:n))}else{this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,t.data]}return dataResponse(t.data)}async deleteConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error deleting configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"DELETE",path:`scheduling/configurations/${e}`});if(n){return dataResponse(null,{message:"Error deleting configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error deleting configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.filter((t=>t.id!==e));if(this.nylasSchedulerConfigStore.state.selectedConfiguration?.id===e){this.nylasSchedulerConfigStore.resetSelectedConfiguration()}return dataResponse(t.data)}async createGroupEvent(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error creating group event: Nylas API Request is not initialized"})}const[n,i]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations/${t}/group-events`,body:e});if(i){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error creating group event: "+i.message})}if(Xr(n)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error creating group event: "+n.error?.message})}this.nylasSchedulerConfigStore.state.selectedGroupEvent=n.data;await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(n.data)}async getGroupEvents(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching group events: Nylas API Request is not initialized"})}const t=new URLSearchParams;t.append("show_all","true");const n=this.nylasSchedulerConfigStore.state.calendarViewDateRange;if(n){t.append("start_time",n.start_time);t.append("end_time",n.end_time)}else{const{startTime:e,endTime:n}=getCalendarRange((new Date).toISOString(),"week");t.append("start_time",e.toString());t.append("end_time",n.toString())}const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){t.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations/${e}/group-events?${t.toString()}`});if(r){return dataResponse(null,{message:"Error fetching group events: "+r.message})}if(Xr(s)){return dataResponse(null,{message:"Error fetching group events: "+s.error?.message})}this.nylasSchedulerConfigStore.state.groupEvents=s.data;return dataResponse(s.data)}async updateGroupEventById(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error updating group event: Nylas API Request is not initialized"})}const n=e.id;delete e.id;const[i,s]=await this.nylasApiRequest.request({method:"PATCH",path:`scheduling/configurations/${t}/group-events/${n}`,body:e});if(s){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error updating group event: "+s.message})}if(Xr(i)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error updating group event: "+i.error?.message})}this.nylasSchedulerConfigStore.state.selectedGroupEvent=i.data;await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(i.data)}async updateGroupEvent(e,t,n){this.nylasSchedulerConfigStore.state.isLoading=true;const i=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const s=i?.event?.master_event_id;const r=i?.event?.id;const o=i?.event?.when?.start_time;const a=i?.group_event_info?.rrule?.[0];const c=a?a.split(";").filter((e=>!e.startsWith("UNTIL"))).join(";"):"";const l=o?dayjs(o*1e3).subtract(1,"minute").format("YYYYMMDDTHHmmss[Z]"):"";if(t==="this"){return this.updateGroupEventById({...e,id:r,recurrence:s?undefined:e.recurrence},n)}else if(t==="future"&&s){const t=await this.createGroupEvent(e,n);const r={location:i?.event?.location,conferencing:i?.event?.conferencing,title:i?.event?.title,description:i?.event?.description,capacity:i?.group_event_info?.capacity,calendar_id:i?.event?.calendar_id,recurrence:c?[c+";UNTIL="+l]:[`RRULE:FREQ=DAILY;UNTIL=${l}`]};await this.updateGroupEventById({...r,id:s},n);return[r,t]}else if(t==="all"){const t=e?.when;const r=i?.event?.when;const o=this.nylasSchedulerConfigStore.state.masterGroupEvents?.[s];let a=o?.when;if(t?.start_time!==r?.start_time){a={...a,start_time:t?.start_time||a?.start_time}}if(t?.end_time!==r?.end_time){a={...a,end_time:t?.end_time||a?.end_time}}if(t?.start_timezone!==r?.start_timezone){a={...a,start_timezone:t?.start_timezone||a?.start_timezone}}if(t?.end_timezone!==r?.end_timezone){a={...a,end_timezone:t?.end_timezone||a?.end_timezone}}return this.updateGroupEventById({...e,when:a,id:s},n)}this.nylasSchedulerConfigStore.state.isLoading=false;throw new Error("Invalid option")}async deleteGroupEvent(e,t,n){this.nylasSchedulerConfigStore.state.isLoading=true;const i=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const s=i?.event?.master_event_id;const r=i?.event?.id;const o=i?.event?.when?.start_time;const a=i?.group_event_info?.rrule?.[0];const c=a?a.split(";").filter((e=>!e.startsWith("UNTIL"))).join(";"):"";const l=o?dayjs(o*1e3).format("YYYYMMDDTHHmmss[Z]"):"";const u={location:i?.event?.location,conferencing:i?.event?.conferencing,title:i?.event?.title,description:i?.event?.description,capacity:i?.group_event_info?.capacity,calendar_id:i?.event?.calendar_id,recurrence:c?[c+";UNTIL="+l]:[`RRULE:UNTIL=${l}`]};if(t==="this"&&r){return this.deleteGroupEventById(r,n)}else if(t==="future"&&s&&r){await this.deleteGroupEventById(r,n);return await this.updateGroupEventById({...u,id:s},n)}else if(t==="all"&&s){return this.deleteGroupEventById(s,n)}this.nylasSchedulerConfigStore.state.isLoading=false;throw new Error("Invalid option")}async deleteGroupEventById(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error deleting group event: Nylas API Request is not initialized"})}const n=new URLSearchParams;const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){n.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"DELETE",path:`scheduling/configurations/${t}/group-events/${e}?calendar_id=${i}`});if(r){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error deleting group event: "+r.message})}if(Xr(s)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error deleting group event: "+s.error?.message})}await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(s.data)}async importGroupEvent(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error importing group event: Nylas API Request is not initialized"})}const n=new URLSearchParams;const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){n.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations/${t}/import-group-events?${n.toString()}`,body:e});if(r){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error importing group event: "+r.message})}if(Xr(s)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error importing group event: "+s.error?.message})}if(s.data?.imported_events?.length>0){await this.getGroupEvents(t)}this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(s.data)}}class NylasSchedulerConfigConnector{constructor({nylasApiRequest:e,nylasSchedulerConfigStore:t}){this.nylasApiRequest=e;this.nylasSchedulerConfigStore=t}init(){debug("NylasSchedulerConfigConnector init")}get schedulerConfigStore(){return this.nylasSchedulerConfigStore}get schedulerConfig(){if(this._schedulerConfigConnector){return this._schedulerConfigConnector}this._schedulerConfigConnector=new NylasSchedulerConfigAPIConnector({nylasApiRequest:this.nylasApiRequest,nylasSchedulerConfigStore:this.nylasSchedulerConfigStore});return this._schedulerConfigConnector}resetStores(){debug("NylasSchedulerConfigConnector resetStores");this.nylasSchedulerConfigStore.reset()}async logout(){debug("NylasSchedulerConfigConnector logout");this.resetStores()}}class LocalStorage{get(e){return new Promise((t=>{const n=window.localStorage.getItem(e);if(!n){t(null)}else{t(JSON.parse(n))}}))}async remove(e){window.localStorage.removeItem(e);return new Promise((e=>{e(null)}))}set(e,t){window.localStorage.setItem(e,JSON.stringify(t));return new Promise((e=>{e(null)}))}}const PKCE_KEY="pkce";const GRANT_KEY="grant";const USER_KEY="user";class Storage{Storage=new LocalStorage;constructor(e){if(e){this.Storage=e;return}}setPKCE(e){const t=Buffer.from(e);this.Storage.set(PKCE_KEY,t.toString("base64"))}async getPKCE(){try{const e=await this.Storage.get(PKCE_KEY);if(e){const t=Buffer.from(e,"base64");return t.toString("utf8")}}catch(e){return null}return null}removePKCE(){this.Storage.remove(PKCE_KEY)}setGrant(e,t=false){const{grant_id:n}=e;this.Storage.set(`${GRANT_KEY}${t?"-"+n:""}`,e)}removeGrant(e,t=false){this.Storage.remove(`${GRANT_KEY}${t?"-"+e:""}`)}async getGrant(e,t=false){const n=await this.Storage.get(`${GRANT_KEY}${t?"-"+e:""}`);if(n){return n}return null}async setUserToken(e){const t=await this.getUserTokens();if(t){const n=t.find((t=>t.sub===e.sub));if(!n){const n=[...t,e];this.Storage.set(USER_KEY,n)}else{const n=t.map((t=>{if(t.sub===e.sub){t=e}return t}));this.Storage.set(USER_KEY,n)}}else{this.Storage.set(USER_KEY,[e])}}async getUserToken(e=""){const t=await this.Storage.get(USER_KEY);if(t){if(e===""){return t[0]}const n=t.find((t=>t.sub===e));return n}return null}async getUserTokens(){const e=await this.Storage.get(USER_KEY);if(e){return e}return null}removeUserTokens(){this.Storage.remove(USER_KEY)}async removeUserToken(e){const t=await this.getUserTokens();const n=t?.filter((t=>t.sub!==e));this.Storage.set(USER_KEY,n)}async clearSession(){const e=await this.getUserTokens();e?.forEach((e=>{this.removeGrant(e.sub)}));this.removePKCE();this.removeUserTokens()}}class IndexedDBStorage{databaseName="identity-db";storeName="identity";get(e){const t=this;return new Promise(((n,i)=>{t.openDatabase().then((function(s){const r=s.transaction(t.storeName,"readwrite");const o=r.objectStore(t.storeName);const a=o.get(e);a.onsuccess=()=>{n(a.result)};a.onerror=()=>{i(a.error)};r.oncomplete=()=>{s.close()}}))}))}async remove(e){const t=this;return new Promise(((n,i)=>{const s=indexedDB.open(this.databaseName);s.onupgradeneeded=function(e){const n=e.target.result;n.createObjectStore(t.storeName)};s.onerror=()=>{i(s.error)};s.onsuccess=t=>{const s=t.target.result;const r=s.transaction(this.storeName,"readwrite");const o=r.objectStore(this.storeName);const a=o.delete(e);a.onsuccess=()=>{n(null)};a.onerror=()=>{i(a.error)};r.oncomplete=()=>{s.close()}}}))}set(e,t){return new Promise(((n,i)=>{const s=indexedDB.open(this.databaseName);s.onerror=()=>{i(s.error)};s.onupgradeneeded=e=>{const t=e.target.result;t.createObjectStore(this.storeName)};s.onsuccess=s=>{const r=s.target.result;const o=r.transaction(this.storeName,"readwrite");const a=o.objectStore(this.storeName);const c=a.put(t,e);c.onsuccess=()=>{n(t)};c.onerror=()=>{i(c.error)};o.oncomplete=()=>{r.close()}}}))}openDatabase(){const e=this;return new Promise((function(t,n){const i=indexedDB.open(e.databaseName,2);i.onupgradeneeded=function(t){const n=t.target.result;n.createObjectStore(e.storeName)};i.onsuccess=function(e){t(e.target.result)};i.onerror=function(e){n(e.error)}}))}}var sha256={exports:{}};(function(module){(function(){var ERROR="input is invalid type";var WINDOW=typeof window==="object";var root=WINDOW?window:{};if(root.JS_SHA256_NO_WINDOW){WINDOW=false}var WEB_WORKER=!WINDOW&&typeof self==="object";var NODE_JS=!root.JS_SHA256_NO_NODE_JS&&typeof process==="object"&&process.versions&&process.versions.node;if(NODE_JS){root=commonjsGlobal}else if(WEB_WORKER){root=self}var COMMON_JS=!root.JS_SHA256_NO_COMMON_JS&&"object"==="object"&&module.exports;var ARRAY_BUFFER=!root.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer!=="undefined";var HEX_CHARS="0123456789abcdef".split("");var EXTRA=[-2147483648,8388608,32768,128];var SHIFT=[24,16,8,0];var K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];var OUTPUT_TYPES=["hex","array","digest","arrayBuffer"];var blocks=[];if(root.JS_SHA256_NO_NODE_JS||!Array.isArray){Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}}if(ARRAY_BUFFER&&(root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)){ArrayBuffer.isView=function(e){return typeof e==="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}}var createOutputMethod=function(e,t){return function(n){return new Sha256(t,true).update(n)[e]()}};var createMethod=function(e){var t=createOutputMethod("hex",e);if(NODE_JS){t=nodeWrap(t,e)}t.create=function(){return new Sha256(e)};t.update=function(e){return t.create().update(e)};for(var n=0;n<OUTPUT_TYPES.length;++n){var i=OUTPUT_TYPES[n];t[i]=createOutputMethod(i,e)}return t};var nodeWrap=function(method,is224){var crypto=eval("require('crypto')");var Buffer=eval("require('buffer').Buffer");var algorithm=is224?"sha224":"sha256";var nodeMethod=function(e){if(typeof e==="string"){return crypto.createHash(algorithm).update(e,"utf8").digest("hex")}else{if(e===null||e===undefined){throw new Error(ERROR)}else if(e.constructor===ArrayBuffer){e=new Uint8Array(e)}}if(Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer){return crypto.createHash(algorithm).update(new Buffer(e)).digest("hex")}else{return method(e)}};return nodeMethod};var createHmacOutputMethod=function(e,t){return function(n,i){return new HmacSha256(n,t,true).update(i)[e]()}};var createHmacMethod=function(e){var t=createHmacOutputMethod("hex",e);t.create=function(t){return new HmacSha256(t,e)};t.update=function(e,n){return t.create(e).update(n)};for(var n=0;n<OUTPUT_TYPES.length;++n){var i=OUTPUT_TYPES[n];t[i]=createHmacOutputMethod(i,e)}return t};function Sha256(e,t){if(t){blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0;this.blocks=blocks}else{this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}if(e){this.h0=3238371032;this.h1=914150663;this.h2=812702999;this.h3=4144912697;this.h4=4290775857;this.h5=1750603025;this.h6=1694076839;this.h7=3204075428}else{this.h0=1779033703;this.h1=3144134277;this.h2=1013904242;this.h3=2773480762;this.h4=1359893119;this.h5=2600822924;this.h6=528734635;this.h7=1541459225}this.block=this.start=this.bytes=this.hBytes=0;this.finalized=this.hashed=false;this.first=true;this.is224=e}Sha256.prototype.update=function(e){if(this.finalized){return}var t,n=typeof e;if(n!=="string"){if(n==="object"){if(e===null){throw new Error(ERROR)}else if(ARRAY_BUFFER&&e.constructor===ArrayBuffer){e=new Uint8Array(e)}else if(!Array.isArray(e)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(e)){throw new Error(ERROR)}}}else{throw new Error(ERROR)}t=true}var i,s=0,r,o=e.length,a=this.blocks;while(s<o){if(this.hashed){this.hashed=false;a[0]=this.block;a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0}if(t){for(r=this.start;s<o&&r<64;++s){a[r>>2]|=e[s]<<SHIFT[r++&3]}}else{for(r=this.start;s<o&&r<64;++s){i=e.charCodeAt(s);if(i<128){a[r>>2]|=i<<SHIFT[r++&3]}else if(i<2048){a[r>>2]|=(192|i>>6)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}else if(i<55296||i>=57344){a[r>>2]|=(224|i>>12)<<SHIFT[r++&3];a[r>>2]|=(128|i>>6&63)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}else{i=65536+((i&1023)<<10|e.charCodeAt(++s)&1023);a[r>>2]|=(240|i>>18)<<SHIFT[r++&3];a[r>>2]|=(128|i>>12&63)<<SHIFT[r++&3];a[r>>2]|=(128|i>>6&63)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}}}this.lastByteIndex=r;this.bytes+=r-this.start;if(r>=64){this.block=a[16];this.start=r-64;this.hash();this.hashed=true}else{this.start=r}}if(this.bytes>4294967295){this.hBytes+=this.bytes/4294967296<<0;this.bytes=this.bytes%4294967296}return this};Sha256.prototype.finalize=function(){if(this.finalized){return}this.finalized=true;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block;e[t>>2]|=EXTRA[t&3];this.block=e[16];if(t>=56){if(!this.hashed){this.hash()}e[0]=this.block;e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0}e[14]=this.hBytes<<3|this.bytes>>>29;e[15]=this.bytes<<3;this.hash()};Sha256.prototype.hash=function(){var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7,c=this.blocks,l,u,d,h,f,p,g,y,w,m,_;for(l=16;l<64;++l){f=c[l-15];u=(f>>>7|f<<25)^(f>>>18|f<<14)^f>>>3;f=c[l-2];d=(f>>>17|f<<15)^(f>>>19|f<<13)^f>>>10;c[l]=c[l-16]+u+c[l-7]+d<<0}_=t&n;for(l=0;l<64;l+=4){if(this.first){if(this.is224){y=300032;f=c[0]-1413257819;a=f-150054599<<0;i=f+24177077<<0}else{y=704751109;f=c[0]-210244248;a=f-1521486534<<0;i=f+143694565<<0}this.first=false}else{u=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10);d=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7);y=e&t;h=y^e&n^_;g=s&r^~s&o;f=a+d+g+K[l]+c[l];p=u+h;a=i+f<<0;i=f+p<<0}u=(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10);d=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7);w=i&e;h=w^i&t^y;g=a&s^~a&r;f=o+d+g+K[l+1]+c[l+1];p=u+h;o=n+f<<0;n=f+p<<0;u=(n>>>2|n<<30)^(n>>>13|n<<19)^(n>>>22|n<<10);d=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7);m=n&i;h=m^n&e^w;g=o&a^~o&s;f=r+d+g+K[l+2]+c[l+2];p=u+h;r=t+f<<0;t=f+p<<0;u=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10);d=(r>>>6|r<<26)^(r>>>11|r<<21)^(r>>>25|r<<7);_=t&n;h=_^t&i^m;g=r&o^~r&a;f=s+d+g+K[l+3]+c[l+3];p=u+h;s=e+f<<0;e=f+p<<0}this.h0=this.h0+e<<0;this.h1=this.h1+t<<0;this.h2=this.h2+n<<0;this.h3=this.h3+i<<0;this.h4=this.h4+s<<0;this.h5=this.h5+r<<0;this.h6=this.h6+o<<0;this.h7=this.h7+a<<0};Sha256.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7;var c=HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[e&15]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[t&15]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[n&15]+HEX_CHARS[i>>28&15]+HEX_CHARS[i>>24&15]+HEX_CHARS[i>>20&15]+HEX_CHARS[i>>16&15]+HEX_CHARS[i>>12&15]+HEX_CHARS[i>>8&15]+HEX_CHARS[i>>4&15]+HEX_CHARS[i&15]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[s&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[r&15]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[o&15];if(!this.is224){c+=HEX_CHARS[a>>28&15]+HEX_CHARS[a>>24&15]+HEX_CHARS[a>>20&15]+HEX_CHARS[a>>16&15]+HEX_CHARS[a>>12&15]+HEX_CHARS[a>>8&15]+HEX_CHARS[a>>4&15]+HEX_CHARS[a&15]}return c};Sha256.prototype.toString=Sha256.prototype.hex;Sha256.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7;var c=[e>>24&255,e>>16&255,e>>8&255,e&255,t>>24&255,t>>16&255,t>>8&255,t&255,n>>24&255,n>>16&255,n>>8&255,n&255,i>>24&255,i>>16&255,i>>8&255,i&255,s>>24&255,s>>16&255,s>>8&255,s&255,r>>24&255,r>>16&255,r>>8&255,r&255,o>>24&255,o>>16&255,o>>8&255,o&255];if(!this.is224){c.push(a>>24&255,a>>16&255,a>>8&255,a&255)}return c};Sha256.prototype.array=Sha256.prototype.digest;Sha256.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32);var t=new DataView(e);t.setUint32(0,this.h0);t.setUint32(4,this.h1);t.setUint32(8,this.h2);t.setUint32(12,this.h3);t.setUint32(16,this.h4);t.setUint32(20,this.h5);t.setUint32(24,this.h6);if(!this.is224){t.setUint32(28,this.h7)}return e};function HmacSha256(e,t,n){var i,s=typeof e;if(s==="string"){var r=[],o=e.length,a=0,c;for(i=0;i<o;++i){c=e.charCodeAt(i);if(c<128){r[a++]=c}else if(c<2048){r[a++]=192|c>>6;r[a++]=128|c&63}else if(c<55296||c>=57344){r[a++]=224|c>>12;r[a++]=128|c>>6&63;r[a++]=128|c&63}else{c=65536+((c&1023)<<10|e.charCodeAt(++i)&1023);r[a++]=240|c>>18;r[a++]=128|c>>12&63;r[a++]=128|c>>6&63;r[a++]=128|c&63}}e=r}else{if(s==="object"){if(e===null){throw new Error(ERROR)}else if(ARRAY_BUFFER&&e.constructor===ArrayBuffer){e=new Uint8Array(e)}else if(!Array.isArray(e)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(e)){throw new Error(ERROR)}}}else{throw new Error(ERROR)}}if(e.length>64){e=new Sha256(t,true).update(e).array()}var l=[],u=[];for(i=0;i<64;++i){var d=e[i]||0;l[i]=92^d;u[i]=54^d}Sha256.call(this,t,n);this.update(u);this.oKeyPad=l;this.inner=true;this.sharedMemory=n}HmacSha256.prototype=new Sha256;HmacSha256.prototype.finalize=function(){Sha256.prototype.finalize.call(this);if(this.inner){this.inner=false;var e=this.array();Sha256.call(this,this.is224,this.sharedMemory);this.update(this.oKeyPad);this.update(e);Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports;exports.sha224=createMethod(true);exports.sha256.hmac=createHmacMethod();exports.sha224.hmac=createHmacMethod(true);if(COMMON_JS){module.exports=exports}else{root.sha256=exports.sha256;root.sha224=exports.sha224}})()})(sha256);var getRandomValues;var rnds8=new Uint8Array(16);function rng(){if(!getRandomValues){getRandomValues=typeof crypto!=="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!=="undefined"&&typeof msCrypto.getRandomValues==="function"&&msCrypto.getRandomValues.bind(msCrypto);if(!getRandomValues){throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported")}}return getRandomValues(rnds8)}const REGEX=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function validate(e){return typeof e==="string"&®EX.test(e)}var byteToHex=[];for(var i=0;i<256;++i){byteToHex.push((i+256).toString(16).substr(1))}function stringify(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var n=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!validate(n)){throw TypeError("Stringified UUID is invalid")}return n}function v4(e,t,n){e=e||{};var i=e.random||(e.rng||rng)();i[6]=i[6]&15|64;i[8]=i[8]&63|128;if(t){n=n||0;for(var s=0;s<16;++s){t[n+s]=i[s]}return t}return stringify(i)}async function getBytes(e,t){const n=e.getReader();let i;while(!(i=await n.read()).done){t(i.value)}}function getLines(e){let t;let n;let i;let s=false;return function r(o){if(t===undefined){t=o;n=0;i=-1}else{t=concat(t,o)}const a=t.length;let c=0;while(n<a){if(s){if(t[n]===10){c=++n}s=false}let r=-1;for(;n<a&&r===-1;++n){switch(t[n]){case 58:if(i===-1){i=n-c}break;case 13:s=true;case 10:r=n;break}}if(r===-1){break}e(t.subarray(c,r),i);c=n;i=-1}if(c===a){t=undefined}else if(c!==0){t=t.subarray(c);n-=c}}}function getMessages(e,t,n){let i=newMessage();const s=new TextDecoder;return function r(o,a){if(o.length===0){n===null||n===void 0?void 0:n(i);i=newMessage()}else if(a>0){const n=s.decode(o.subarray(0,a));const r=a+(o[a+1]===32?2:1);const c=s.decode(o.subarray(r));switch(n){case"data":i.data=i.data?i.data+"\n"+c:c;break;case"event":i.event=c;break;case"id":e(i.id=c);break;case"retry":const n=parseInt(c,10);if(!isNaN(n)){t(i.retry=n)}break}}}}function concat(e,t){const n=new Uint8Array(e.length+t.length);n.set(e);n.set(t,e.length);return n}function newMessage(){return{data:"",event:"",id:"",retry:undefined}}var __rest=undefined&&undefined.__rest||function(e,t){var n={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0)n[i]=e[i];if(e!=null&&typeof Object.getOwnPropertySymbols==="function")for(var s=0,i=Object.getOwnPropertySymbols(e);s<i.length;s++){if(t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s]))n[i[s]]=e[i[s]]}return n};const EventStreamContentType="text/event-stream";const DefaultRetryInterval=1e3;const LastEventId="last-event-id";function fetchEventSource(e,t){var{signal:n,headers:i,onopen:s,onmessage:r,onclose:o,onerror:a,openWhenHidden:c,fetch:l}=t,u=__rest(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(((t,d)=>{const h=Object.assign({},i);if(!h.accept){h.accept=EventStreamContentType}let f;function p(){f.abort();if(!document.hidden){b()}}if(!c){document.addEventListener("visibilitychange",p)}let g=DefaultRetryInterval;let y=0;function w(){document.removeEventListener("visibilitychange",p);window.clearTimeout(y);f.abort()}n===null||n===void 0?void 0:n.addEventListener("abort",(()=>{w();t()}));const m=l!==null&&l!==void 0?l:window.fetch;const _=s!==null&&s!==void 0?s:defaultOnOpen;async function b(){var n;f=new AbortController;try{const n=await m(e,Object.assign(Object.assign({},u),{headers:h,signal:f.signal}));await _(n);await getBytes(n.body,getLines(getMessages((e=>{if(e){h[LastEventId]=e}else{delete h[LastEventId]}}),(e=>{g=e}),r)));o===null||o===void 0?void 0:o();w();t()}catch(e){if(!f.signal.aborted){try{const t=(n=a===null||a===void 0?void 0:a(e))!==null&&n!==void 0?n:g;window.clearTimeout(y);y=window.setTimeout(b,t)}catch(e){w();d(e)}}}}b()}))}function defaultOnOpen(e){const t=e.headers.get("content-type");if(!(t===null||t===void 0?void 0:t.startsWith(EventStreamContentType))){throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${t}`)}}function Base64EncodeUrl(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function getTimestamp(){return Math.floor(Date.now()/1e3)}function e(e){this.message=e}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r$1="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var n=String(t).replace(/=+$/,"");if(n.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,s,r=0,o=0,a="";s=n.charAt(o++);~s&&(i=r%4?64*i+s:s,r++%4)?a+=String.fromCharCode(255&i>>(-2*r&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return a};function t$1(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(r$1(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return r$1(t)}}function n$1(e){this.message=e}function o(e,t){if("string"!=typeof e)throw new n$1("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(t$1(e.split(".")[n]))}catch(e){throw new n$1("Invalid token specified: "+e.message)}}n$1.prototype=new Error,n$1.prototype.name="InvalidTokenError";class NylasSessions{clientId;redirectUri;accessType="online";domain="http://api.nylas.com";versioned=false;Storage;hosted=false;multiAccount=false;loginId="";constructor(e){this.clientId=e.clientId;this.redirectUri=e.redirectUri;if(e.domain){this.domain=e.domain;const t=this.domain.substring(this.domain.length-3);if(t.includes("/v")){this.versioned=true}}if(e.multiAccount){this.multiAccount=e.multiAccount}if(e.sw){const e=new IndexedDBStorage;this.Storage=new Storage(e)}else{this.Storage=new Storage}if(e.accessType){this.accessType=e.accessType}if(e.loginId){this.loginId=e.loginId}if(e.hosted){this.hosted=e.hosted}if(e.disableInitCodeExchange!==true){this.codeExchange(null)}}async validateAccessToken(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const{access_token:n}=t;try{const e=await fetch(`${this.domain}/connect/tokeninfo?access_token=${n}`,{method:"GET"});const t=await e.json();if(!t.data){return false}return true}catch(e){return false}}async validateIDToken(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const{id_token:n}=t;try{const e=await fetch(`${this.domain}/connect/tokeninfo?id_token=${n}`,{method:"GET"});if(e.status!==200){return false}const t=await e.json();if(!t.data){return false}return true}catch(e){return false}}getDomain(){return this.domain}async auth(e){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){await this.hostedSetCodeChallenge()}const t=await this.generateAuthURL(e);if(e.popup){this.popUp(t);return}return t}async generateAuthURL(e){const t=await this.getCodeChallege();let n=`${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;if(t){n+=`&code_challenge=${t}&code_challenge_method=S256&options=rotate_refresh_token`}if(e.provider){n+=`&provider=${e.provider}`}if(e.loginHint){n+=`&login_hint=${e.loginHint}`;if(e.includeGrantScopes){n+=`&include_grant_scopes=${e.includeGrantScopes}`}}if(e.scope){n+=`&scope=${e.scope.join(" ")}`}if(e.prompt){n+=`&prompt=${e.prompt}`}if(e.metadata){n+=`&metadata=${e.metadata}`}if(e.state||this.loginId){n+=`&state=${this.loginId?this.loginId:e.state}`}return n}async generateReauthURL(e,t){if(!e){throw new Error("Grant ID is required")}const n=await this.Storage.getUserToken(e);const i=await this.getCodeChallege();let s=`${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;if(i){s+=`&code_challenge=${i}&code_challenge_method=S256&options=rotate_refresh_token`}if(n?.provider){s+=`&provider=${n.provider}`}if(n?.email){s+=`&login_hint=${n.email}`}if(t){s+=`&scope=${t.join(" ")}`}return s}async generateCodeChallenge(){const e=await this.Storage.getPKCE();if(e){return}const t=v4();this.Storage.setPKCE(t);return}async hostedSetCodeChallenge(){if(!this.hosted){throw console.error("Method only used with hosted flag enabled")}const e=new URLSearchParams(window.location.search);const t=e.get("code_challenge");if(!t){const e=await this.Storage.getPKCE();if(e){return}console.warn("Code challenge is recomended");return}this.Storage.setPKCE(t)}async getCodeChallege(){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){const e=new URLSearchParams(window.location.search);const t=e.get("code_challenge");if(!t){console.warn("Code challenge is recomended");return""}return t}const e=await this.Storage.getPKCE();if(e){const t=sha256.exports.sha256(e);let n=Buffer.from(t).toString("base64");n=Base64EncodeUrl(n);return n}return""}async isLoggedIn(){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){return false}const e=await this.Storage.getUserTokens();if(e&&e.length>0){if(this.multiAccount){await this.generateCodeChallenge()}return true}await this.generateCodeChallenge();return false}isMultiAccount(){return this.multiAccount}async logout(){const e=await this.getProfile();await this.Storage.clearSession();const t={detail:e};window.dispatchEvent(new CustomEvent("onLogoutSuccess",t))}async getProfile(e=""){let t;if(e){t=await this.Storage.getUserToken(e)}else{t=await this.Storage.getUserToken()}if(t){return t}return null}async getProfiles(){const e=await this.Storage.getUserTokens();if(e){return e}return null}async removeProfile(e){await this.Storage.removeUserToken(e);await this.Storage.removeGrant(e);return null}async authIMAP(e){const t=await this.getCodeChallege();const n={imap_username:e.imap_username,imap_password:e.imap_password,imap_host:e.imap_host,imap_port:e.imap_port,type:e.type,smtp_host:e.smtp_host,smtp_port:e.smtp_port,provider:e.provider,redirect_uri:this.redirectUri,state:e.state,public_application_id:this.clientId,access_type:this.accessType};if(this.loginId){n.id=this.loginId}if(e.smtp_username&&e.smtp_password){n.smtp_username=e.smtp_username;n.smtp_password=e.smtp_password}if(t!=""){n.code_challenge=t;n.code_challenge_method="S256"}const i=await fetch(`${this.domain}/connect/login/imap`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(n)});const s=await i.json();return s}async authEWS(e){const t=await this.getCodeChallege();const n={...e,provider:"ews",redirect_uri:this.redirectUri,public_application_id:this.clientId,access_type:this.accessType};if(this.loginId){n.id=this.loginId}if(t!=""){n.code_challenge=t;n.code_challenge_method="S256"}const i=await fetch(`${this.domain}/connect/login/ews`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(n)});const s=await i.json();return s}async detectEmail(e){const t=await fetch(`${this.versioned?this.domain:this.domain+"/connect"}/providers/detect?client_id=${this.clientId}&email=${e}`,{method:"POST",headers:new Headers({"content-type":"application/json"})});const n=await t.json();return n}async applicationInfo(){const e=await fetch(`${this.versioned?this.domain:this.domain+"/connect"}/applications?client_id=${this.clientId}`,{method:"GET",headers:new Headers({"content-type":"application/json"})});const t=await e.json();return t.data}async getAvailableProviders(){const e=await fetch(`${this.domain}/connect/providers/find?client_id=${this.clientId}`,{method:"GET",headers:new Headers({"content-type":"application/json"})});if(e){const t=await e.json();const n=t.data;return n}return null}onLoginSuccess(e){window.addEventListener("onLoginSuccess",(t=>e(t)))}onLogoutSuccess(e){window.addEventListener("onLogoutSuccess",(t=>e(t)))}onLoginFail(e){window.addEventListener("onLoginFail",(t=>e(t)))}onTokenRefreshSuccess(e){window.addEventListener("onTokenRefreshSuccess",(t=>e(t)))}onTokenRefreshFail(e){window.addEventListener("onTokenRefreshFail",(t=>e(t)))}onSessionExpired(e){window.addEventListener("onSessionExpired",(t=>e(t)))}async codeExchange(e){let t=new URLSearchParams(window.location.search);if(e){t=new URLSearchParams(e)}const n=t.get("code");const i=t.get("state");const s=t.get("error");const r=t.get("error_description");const o=t.get("error_code");if(s&&r&&o){const e={detail:{error:s,error_description:r,error_code:o}};window.dispatchEvent(new CustomEvent("onLoginFail",e));window.history.pushState({},document.title,window.location.pathname);return false}if(!n){console.warn("No code found");return false}if(window.opener&&window.name==="uas-popup"){console.warn("Popup window detected");return false}const a=await this.Storage.getPKCE();if(!a){console.warn("No code verifier found");return false}try{const e={client_id:this.clientId,redirect_uri:this.redirectUri,code:n,grant_type:"authorization_code",code_verifier:a};const t=await fetch(`${this.domain}/connect/token`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(e)});const s=await t.json();if(s){if(s.error){const e={detail:s};window.dispatchEvent(new CustomEvent("onLoginFail",e));return true}const e=await this.handleCodeExchangeResponse(s);if(!e.valid){const t={detail:e.data};window.dispatchEvent(new CustomEvent("onLoginFail",t));return true}else{if(i){e.data.state=i}const t={detail:e.data};window.dispatchEvent(new CustomEvent("onLoginSuccess",t));window.history.pushState({},document.title,window.location.pathname)}}this.Storage.removePKCE();return true}catch(s){const e={detail:s};window.dispatchEvent(new CustomEvent("onLoginFail",e));window.history.pushState({},document.title,window.location.pathname);return false}}async tokenExchange(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const n=t.refresh_token;try{const t={client_id:this.clientId,redirect_uri:this.redirectUri,refresh_token:n,grant_type:"refresh_token"};const i=await fetch(`${this.domain}/connect/token`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(t)});const s=await i.json();if(s){if(s.error){const e={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",e));return true}const t=getTimestamp();s.expires_in=t+s.expires_in;this.Storage.setGrant(s,this.multiAccount);const n=await this.validateIDToken(e);if(!n){const e={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",e));return true}const i={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshSuccess",i));return true}this.Storage.removePKCE()}catch(e){const t={detail:e};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",t));return false}}async handleCodeExchangeResponse(e){const t=true;if(e.error){return{data:e,valid:false}}const n=getTimestamp();e.expires_in=n+e.expires_in;this.Storage.setGrant(e,this.multiAccount);const i=o(e.id_token);i.status="authenticated";this.Storage.setUserToken(i);const s=await this.validateIDToken(i.sub);if(!s){return{data:e,valid:false}}return{data:e,valid:t}}async popUp(e){const t=500;const n=600;const i=window.screenX+(window.outerWidth-t)/2;const s=window.screenY+(window.outerHeight-n)/2.5;const r=`uas-popup`;const o=e;const a=window.open(o,r,`width=${t},height=${n},left=${i},top=${s}`);if(!a){return}const c=setInterval((async()=>{if(a.closed){const e={detail:{error_description:"OAuth provider window closed"}};window.dispatchEvent(new CustomEvent("onLoginFail",e));c&&clearInterval(c);return}try{const e=a.location.href.split("?");if(!e[0]){return}const t=a.location.search;a.history.pushState({},document.title,window.location.pathname);if(e[0]===this.redirectUri&&e.length>1){const e=await this.codeExchange(t);a.close();if(e){location.reload()}c&&clearInterval(c);return}}catch(e){return}}),1e3)}async getAccessToken(e=""){const t=getTimestamp();const n=await this.Storage.getGrant(e,this.multiAccount);if(!n){return null}const{access_token:i,expires_in:s}=n;const r=i;if(r){if(s&&s>getTimestamp()){const e=s-t;if(e>30){return r}}}await this.tokenExchange(e);const o=await this.Storage.getGrant(e,this.multiAccount);return o.access_token}async sse(e,t){const n=t.headers||{};const i=n["Grant-ID"];let s="";if(this.multiAccount){if(!i){this.logout();throw new Error("Grant ID is required for multi account calls")}s=await this.getAccessToken(i)}else{s=await this.getAccessToken()}delete n["Grant-ID"];n["Authorization"]=`Bearer ${s}`;if(!n["content-type"]){n["content-type"]="application/json"}return fetchEventSource(`${this.domain}/${e}`,{...t,headers:n})}async fetch(e,t,n=true,i){let s="";let r=1;if(this.multiAccount){if(!t.grant_id){this.logout();throw new Error("Grant ID is required for multi account calls")}const e=await this.getProfiles();r=e?e.length:1;s=await this.getAccessToken(t.grant_id)}else{s=await this.getAccessToken()}if(!s){throw new Error("Access token not found")}let o=t.headers;if(!Headers.prototype.isPrototypeOf(o)){o=new Headers({Authorization:`Bearer ${s}`,"content-type":"application/json"})}else{o.append("Authorization",`Bearer ${s}`);if(!o.has("content-type")){o.append("content-type","application/json")}}try{if(t?.body){t.body=JSON.stringify(t?.body)}const s=await fetch(`${i||this.domain}/${e}`,{...t,headers:o});if(!n){return s}const a=await(s?.json());const c=await this.isAuthenticatedResponse(s.status,a);if(!c){if(r>1){const e=await this.getProfile(t.grant_id);if(e){e.status="unauthorized";await this.Storage.setUserToken(e);const t={detail:{user:e}};window.dispatchEvent(new CustomEvent("onSessionExpired",t))}}else{const e=await this.Storage.getUserToken();const t={detail:{user:e}};window.dispatchEvent(new CustomEvent("onSessionExpired",t))}this.logout();return}return a}catch(e){throw e}}async fetchRequest(e,t,n,i=true,s,r){const o=await this.isLoggedIn();const a=new URL(e,s??this.domain);const c=new Headers;c.append("Accept","application/json");c.append("Content-Type","application/json");c.append("User-Agent","nylas-identity");if(o){const e=await this.getAccessToken();c.append("Authorization",`Bearer ${e}`)}const l=await fetch(a.toString(),{method:t||"GET",headers:c,mode:"cors",referrer:location.origin,body:n?JSON.stringify(n):undefined,...r||{}});if(!i){return l.body}const u=await l.json();return u}async isAuthenticatedResponse(e,t){if(e==401&&t?.error?.type=="token.unauthorized_access"){return false}return true}addAPIKey(e,t,n){this.Storage.setUserToken({aud:"https://api-staging.us.nylas.com/",exp:2e9,email_verified:true,iat:getTimestamp(),iss:"",email:t,provider:"virtual-calendar",status:"authenticated",name:t,sub:e});this.Storage.setGrant({grant_id:e,access_token:n,expires_in:2e9},this.multiAccount)}}var react_production_min={};
|
|
1
|
+
import{h,F as Fragment,r as registerInstance,c as createEvent,H as Host,a as getElement}from"./p-6f5a3998.js";import{X as Xr,N as NylasBaseProvider}from"./p-189b24e6.js";import{N as NylasIdentityRequestWrapper}from"./p-7477410d.js";import{t as timezone,d as dataResponse,c as getCalendarRange,a as debug,B as Buffer,p as process,i as instance}from"./p-6b7fb948.js";import{a as dayjs,u as utc,c as commonjsGlobal}from"./p-c79dcb59.js";import{C as CreateNylasSchedulerConfigStore}from"./p-14894041.js";import{C as CONFIGURATION_EVENT_TYPE,E as EXPERIMENTAL_FEATURES,L as LANGUAGE_CODE,a as LANGUAGE_MAP}from"./p-6f7cb609.js";import"./p-fc5bc07b.js";dayjs.extend(utc);dayjs.extend(timezone);class NylasSchedulerConfigAPIConnector{constructor({nylasApiRequest:e,nylasSchedulerConfigStore:t}){this.nylasApiRequest=e;this.nylasSchedulerConfigStore=t}async currentUser(){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return null}return this.nylasApiRequest.currentUser()}async getCalendars(){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching calendars: Nylas API Request is not initialized"})}const[e,t]=await this.nylasApiRequest.request({method:"GET",path:`calendars`});if(t){return dataResponse(null,{message:"Error fetching calendars: "+t.message})}if(Xr(e)){return dataResponse(null,{message:"Error fetching calendars: "+e.error?.message})}this.nylasSchedulerConfigStore.state.calendars=e.data;return dataResponse(e.data)}async getConfigurationById(e,t=false){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching configuration: Nylas API Request is not initialized"})}if(!t){const t=this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e));if(t){this.nylasSchedulerConfigStore.state.selectedConfiguration=t;return dataResponse(t)}}const[n,i]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations/${e}`});if(i){return dataResponse(null,{message:"Error fetching configuration: "+i.message})}if(Xr(n)){return dataResponse(null,{message:"Error fetching configuration: "+n.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=n.data;if(this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e))){this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.map((t=>t.id===e?n.data:t))}else{this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,n.data]}return dataResponse(n.data)}async getConfigurations(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching configurations: Nylas API Request is not initialized"})}const t=50;const[n,i]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations?limit=${t}${e?`&page_token=${e}`:""}`});if(i){return dataResponse(null,{message:"Error fetching configurations: "+i.message})}if(Xr(n)){return dataResponse(null,{message:"Error fetching configurations: "+n.error?.message})}this.nylasSchedulerConfigStore.state.configurations=n.data;this.nylasSchedulerConfigStore.state.listConfigurationsNextCursor=n.next_cursor||null;return dataResponse(n.data)}async getMasterEventById(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching master event: Nylas API Request is not initialized"})}const t=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const n=t?.event?.calendar_id;if(!n){console.warn("Calendar ID is not present");return dataResponse(null,{message:"Error fetching master event: Calendar ID is not present"})}const i=new URLSearchParams;i.append("calendar_id",n);const[s,r]=await this.nylasApiRequest.request({method:"GET",path:`events/${e}?${i.toString()}`});if(r){return dataResponse(null,{message:"Error fetching master event: "+r.message})}if(Xr(s)){return dataResponse(null,{message:"Error fetching master event: "+s.error?.message})}const o=this.nylasSchedulerConfigStore.state.masterGroupEvents;if(o[e]){this.nylasSchedulerConfigStore.state.masterGroupEvents[e]=s.data}else{this.nylasSchedulerConfigStore.state.masterGroupEvents={...o,[e]:s.data}}return dataResponse(s.data)}async createConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error creating configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations`,body:e});if(n){return dataResponse(null,{message:"Error creating configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error creating configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=t.data;this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,t.data];return dataResponse(t.data)}async updateConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error updating configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"PUT",path:`scheduling/configurations/${e.id}`,body:e});if(n){return dataResponse(null,{message:"Error updating configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error updating configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.selectedConfiguration=t.data;if(this.nylasSchedulerConfigStore.state.configurations.find((t=>t.id===e.id))){this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.map((n=>n.id===e.id?t.data:n))}else{this.nylasSchedulerConfigStore.state.configurations=[...this.nylasSchedulerConfigStore.state.configurations,t.data]}return dataResponse(t.data)}async deleteConfiguration(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error deleting configuration: Nylas API Request is not initialized"})}const[t,n]=await this.nylasApiRequest.request({method:"DELETE",path:`scheduling/configurations/${e}`});if(n){return dataResponse(null,{message:"Error deleting configuration: "+n.message})}if(Xr(t)){return dataResponse(null,{message:"Error deleting configuration: "+t.error?.message})}this.nylasSchedulerConfigStore.state.configurations=this.nylasSchedulerConfigStore.state.configurations.filter((t=>t.id!==e));if(this.nylasSchedulerConfigStore.state.selectedConfiguration?.id===e){this.nylasSchedulerConfigStore.resetSelectedConfiguration()}return dataResponse(t.data)}async createGroupEvent(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error creating group event: Nylas API Request is not initialized"})}const[n,i]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations/${t}/group-events`,body:e});if(i){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error creating group event: "+i.message})}if(Xr(n)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error creating group event: "+n.error?.message})}this.nylasSchedulerConfigStore.state.selectedGroupEvent=n.data;await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(n.data)}async getGroupEvents(e){if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error fetching group events: Nylas API Request is not initialized"})}const t=new URLSearchParams;t.append("show_all","true");const n=this.nylasSchedulerConfigStore.state.calendarViewDateRange;if(n){t.append("start_time",n.start_time);t.append("end_time",n.end_time)}else{const{startTime:e,endTime:n}=getCalendarRange((new Date).toISOString(),"week");t.append("start_time",e.toString());t.append("end_time",n.toString())}const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){t.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"GET",path:`scheduling/configurations/${e}/group-events?${t.toString()}`});if(r){return dataResponse(null,{message:"Error fetching group events: "+r.message})}if(Xr(s)){return dataResponse(null,{message:"Error fetching group events: "+s.error?.message})}this.nylasSchedulerConfigStore.state.groupEvents=s.data;return dataResponse(s.data)}async updateGroupEventById(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error updating group event: Nylas API Request is not initialized"})}const n=e.id;delete e.id;const[i,s]=await this.nylasApiRequest.request({method:"PATCH",path:`scheduling/configurations/${t}/group-events/${n}`,body:e});if(s){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error updating group event: "+s.message})}if(Xr(i)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error updating group event: "+i.error?.message})}this.nylasSchedulerConfigStore.state.selectedGroupEvent=i.data;await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(i.data)}async updateGroupEvent(e,t,n){this.nylasSchedulerConfigStore.state.isLoading=true;const i=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const s=i?.event?.master_event_id;const r=i?.event?.id;const o=i?.event?.when?.start_time;const a=i?.group_event_info?.rrule?.[0];const c=a?a.split(";").filter((e=>!e.startsWith("UNTIL"))).join(";"):"";const l=o?dayjs(o*1e3).subtract(1,"minute").format("YYYYMMDDTHHmmss[Z]"):"";if(t==="this"){return this.updateGroupEventById({...e,id:r,recurrence:s?undefined:e.recurrence},n)}else if(t==="future"&&s){const t=await this.createGroupEvent(e,n);const r={location:i?.event?.location,conferencing:i?.event?.conferencing,title:i?.event?.title,description:i?.event?.description,capacity:i?.group_event_info?.capacity,calendar_id:i?.event?.calendar_id,recurrence:c?[c+";UNTIL="+l]:[`RRULE:FREQ=DAILY;UNTIL=${l}`]};await this.updateGroupEventById({...r,id:s},n);return[r,t]}else if(t==="all"){const t=e?.when;const r=i?.event?.when;const o=this.nylasSchedulerConfigStore.state.masterGroupEvents?.[s];let a=o?.when;if(t?.start_time!==r?.start_time){a={...a,start_time:t?.start_time||a?.start_time}}if(t?.end_time!==r?.end_time){a={...a,end_time:t?.end_time||a?.end_time}}if(t?.start_timezone!==r?.start_timezone){a={...a,start_timezone:t?.start_timezone||a?.start_timezone}}if(t?.end_timezone!==r?.end_timezone){a={...a,end_timezone:t?.end_timezone||a?.end_timezone}}return this.updateGroupEventById({...e,when:a,id:s},n)}this.nylasSchedulerConfigStore.state.isLoading=false;throw new Error("Invalid option")}async deleteGroupEvent(e,t,n){this.nylasSchedulerConfigStore.state.isLoading=true;const i=this.nylasSchedulerConfigStore.state.selectedGroupEvent;const s=i?.event?.master_event_id;const r=i?.event?.id;const o=i?.event?.when?.start_time;const a=i?.group_event_info?.rrule?.[0];const c=a?a.split(";").filter((e=>!e.startsWith("UNTIL"))).join(";"):"";const l=o?dayjs(o*1e3).format("YYYYMMDDTHHmmss[Z]"):"";const u={location:i?.event?.location,conferencing:i?.event?.conferencing,title:i?.event?.title,description:i?.event?.description,capacity:i?.group_event_info?.capacity,calendar_id:i?.event?.calendar_id,recurrence:c?[c+";UNTIL="+l]:[`RRULE:UNTIL=${l}`]};if(t==="this"&&r){return this.deleteGroupEventById(r,n)}else if(t==="future"&&s&&r){await this.deleteGroupEventById(r,n);return await this.updateGroupEventById({...u,id:s},n)}else if(t==="all"&&s){return this.deleteGroupEventById(s,n)}this.nylasSchedulerConfigStore.state.isLoading=false;throw new Error("Invalid option")}async deleteGroupEventById(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error deleting group event: Nylas API Request is not initialized"})}const n=new URLSearchParams;const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){n.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"DELETE",path:`scheduling/configurations/${t}/group-events/${e}?calendar_id=${i}`});if(r){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error deleting group event: "+r.message})}if(Xr(s)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error deleting group event: "+s.error?.message})}await this.getGroupEvents(t);this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(s.data)}async importGroupEvent(e,t){this.nylasSchedulerConfigStore.state.isLoading=true;if(!this.nylasApiRequest){console.warn("Nylas API Request is not initialized");return dataResponse(null,{message:"Error importing group event: Nylas API Request is not initialized"})}const n=new URLSearchParams;const i=this.nylasSchedulerConfigStore.state.selectedConfiguration?.group_booking?.calendar_id;if(i){n.append("calendar_id",i)}const[s,r]=await this.nylasApiRequest.request({method:"POST",path:`scheduling/configurations/${t}/import-group-events?${n.toString()}`,body:e});if(r){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error importing group event: "+r.message})}if(Xr(s)){this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(null,{message:"Error importing group event: "+s.error?.message})}if(s.data?.imported_events?.length>0){await this.getGroupEvents(t)}this.nylasSchedulerConfigStore.state.isLoading=false;return dataResponse(s.data)}}class NylasSchedulerConfigConnector{constructor({nylasApiRequest:e,nylasSchedulerConfigStore:t}){this.nylasApiRequest=e;this.nylasSchedulerConfigStore=t}init(){debug("NylasSchedulerConfigConnector init")}get schedulerConfigStore(){return this.nylasSchedulerConfigStore}get schedulerConfig(){if(this._schedulerConfigConnector){return this._schedulerConfigConnector}this._schedulerConfigConnector=new NylasSchedulerConfigAPIConnector({nylasApiRequest:this.nylasApiRequest,nylasSchedulerConfigStore:this.nylasSchedulerConfigStore});return this._schedulerConfigConnector}resetStores(){debug("NylasSchedulerConfigConnector resetStores");this.nylasSchedulerConfigStore.reset()}async logout(){debug("NylasSchedulerConfigConnector logout");this.resetStores()}}class LocalStorage{get(e){return new Promise((t=>{const n=window.localStorage.getItem(e);if(!n){t(null)}else{t(JSON.parse(n))}}))}async remove(e){window.localStorage.removeItem(e);return new Promise((e=>{e(null)}))}set(e,t){window.localStorage.setItem(e,JSON.stringify(t));return new Promise((e=>{e(null)}))}}const PKCE_KEY="pkce";const GRANT_KEY="grant";const USER_KEY="user";class Storage{Storage=new LocalStorage;constructor(e){if(e){this.Storage=e;return}}setPKCE(e){const t=Buffer.from(e);this.Storage.set(PKCE_KEY,t.toString("base64"))}async getPKCE(){try{const e=await this.Storage.get(PKCE_KEY);if(e){const t=Buffer.from(e,"base64");return t.toString("utf8")}}catch(e){return null}return null}removePKCE(){this.Storage.remove(PKCE_KEY)}setGrant(e,t=false){const{grant_id:n}=e;this.Storage.set(`${GRANT_KEY}${t?"-"+n:""}`,e)}removeGrant(e,t=false){this.Storage.remove(`${GRANT_KEY}${t?"-"+e:""}`)}async getGrant(e,t=false){const n=await this.Storage.get(`${GRANT_KEY}${t?"-"+e:""}`);if(n){return n}return null}async setUserToken(e){const t=await this.getUserTokens();if(t){const n=t.find((t=>t.sub===e.sub));if(!n){const n=[...t,e];this.Storage.set(USER_KEY,n)}else{const n=t.map((t=>{if(t.sub===e.sub){t=e}return t}));this.Storage.set(USER_KEY,n)}}else{this.Storage.set(USER_KEY,[e])}}async getUserToken(e=""){const t=await this.Storage.get(USER_KEY);if(t){if(e===""){return t[0]}const n=t.find((t=>t.sub===e));return n}return null}async getUserTokens(){const e=await this.Storage.get(USER_KEY);if(e){return e}return null}removeUserTokens(){this.Storage.remove(USER_KEY)}async removeUserToken(e){const t=await this.getUserTokens();const n=t?.filter((t=>t.sub!==e));this.Storage.set(USER_KEY,n)}async clearSession(){const e=await this.getUserTokens();e?.forEach((e=>{this.removeGrant(e.sub)}));this.removePKCE();this.removeUserTokens()}}class IndexedDBStorage{databaseName="identity-db";storeName="identity";get(e){const t=this;return new Promise(((n,i)=>{t.openDatabase().then((function(s){const r=s.transaction(t.storeName,"readwrite");const o=r.objectStore(t.storeName);const a=o.get(e);a.onsuccess=()=>{n(a.result)};a.onerror=()=>{i(a.error)};r.oncomplete=()=>{s.close()}}))}))}async remove(e){const t=this;return new Promise(((n,i)=>{const s=indexedDB.open(this.databaseName);s.onupgradeneeded=function(e){const n=e.target.result;n.createObjectStore(t.storeName)};s.onerror=()=>{i(s.error)};s.onsuccess=t=>{const s=t.target.result;const r=s.transaction(this.storeName,"readwrite");const o=r.objectStore(this.storeName);const a=o.delete(e);a.onsuccess=()=>{n(null)};a.onerror=()=>{i(a.error)};r.oncomplete=()=>{s.close()}}}))}set(e,t){return new Promise(((n,i)=>{const s=indexedDB.open(this.databaseName);s.onerror=()=>{i(s.error)};s.onupgradeneeded=e=>{const t=e.target.result;t.createObjectStore(this.storeName)};s.onsuccess=s=>{const r=s.target.result;const o=r.transaction(this.storeName,"readwrite");const a=o.objectStore(this.storeName);const c=a.put(t,e);c.onsuccess=()=>{n(t)};c.onerror=()=>{i(c.error)};o.oncomplete=()=>{r.close()}}}))}openDatabase(){const e=this;return new Promise((function(t,n){const i=indexedDB.open(e.databaseName,2);i.onupgradeneeded=function(t){const n=t.target.result;n.createObjectStore(e.storeName)};i.onsuccess=function(e){t(e.target.result)};i.onerror=function(e){n(e.error)}}))}}var sha256={exports:{}};(function(module){(function(){var ERROR="input is invalid type";var WINDOW=typeof window==="object";var root=WINDOW?window:{};if(root.JS_SHA256_NO_WINDOW){WINDOW=false}var WEB_WORKER=!WINDOW&&typeof self==="object";var NODE_JS=!root.JS_SHA256_NO_NODE_JS&&typeof process==="object"&&process.versions&&process.versions.node;if(NODE_JS){root=commonjsGlobal}else if(WEB_WORKER){root=self}var COMMON_JS=!root.JS_SHA256_NO_COMMON_JS&&"object"==="object"&&module.exports;var ARRAY_BUFFER=!root.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer!=="undefined";var HEX_CHARS="0123456789abcdef".split("");var EXTRA=[-2147483648,8388608,32768,128];var SHIFT=[24,16,8,0];var K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];var OUTPUT_TYPES=["hex","array","digest","arrayBuffer"];var blocks=[];if(root.JS_SHA256_NO_NODE_JS||!Array.isArray){Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}}if(ARRAY_BUFFER&&(root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)){ArrayBuffer.isView=function(e){return typeof e==="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}}var createOutputMethod=function(e,t){return function(n){return new Sha256(t,true).update(n)[e]()}};var createMethod=function(e){var t=createOutputMethod("hex",e);if(NODE_JS){t=nodeWrap(t,e)}t.create=function(){return new Sha256(e)};t.update=function(e){return t.create().update(e)};for(var n=0;n<OUTPUT_TYPES.length;++n){var i=OUTPUT_TYPES[n];t[i]=createOutputMethod(i,e)}return t};var nodeWrap=function(method,is224){var crypto=eval("require('crypto')");var Buffer=eval("require('buffer').Buffer");var algorithm=is224?"sha224":"sha256";var nodeMethod=function(e){if(typeof e==="string"){return crypto.createHash(algorithm).update(e,"utf8").digest("hex")}else{if(e===null||e===undefined){throw new Error(ERROR)}else if(e.constructor===ArrayBuffer){e=new Uint8Array(e)}}if(Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer){return crypto.createHash(algorithm).update(new Buffer(e)).digest("hex")}else{return method(e)}};return nodeMethod};var createHmacOutputMethod=function(e,t){return function(n,i){return new HmacSha256(n,t,true).update(i)[e]()}};var createHmacMethod=function(e){var t=createHmacOutputMethod("hex",e);t.create=function(t){return new HmacSha256(t,e)};t.update=function(e,n){return t.create(e).update(n)};for(var n=0;n<OUTPUT_TYPES.length;++n){var i=OUTPUT_TYPES[n];t[i]=createHmacOutputMethod(i,e)}return t};function Sha256(e,t){if(t){blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0;this.blocks=blocks}else{this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}if(e){this.h0=3238371032;this.h1=914150663;this.h2=812702999;this.h3=4144912697;this.h4=4290775857;this.h5=1750603025;this.h6=1694076839;this.h7=3204075428}else{this.h0=1779033703;this.h1=3144134277;this.h2=1013904242;this.h3=2773480762;this.h4=1359893119;this.h5=2600822924;this.h6=528734635;this.h7=1541459225}this.block=this.start=this.bytes=this.hBytes=0;this.finalized=this.hashed=false;this.first=true;this.is224=e}Sha256.prototype.update=function(e){if(this.finalized){return}var t,n=typeof e;if(n!=="string"){if(n==="object"){if(e===null){throw new Error(ERROR)}else if(ARRAY_BUFFER&&e.constructor===ArrayBuffer){e=new Uint8Array(e)}else if(!Array.isArray(e)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(e)){throw new Error(ERROR)}}}else{throw new Error(ERROR)}t=true}var i,s=0,r,o=e.length,a=this.blocks;while(s<o){if(this.hashed){this.hashed=false;a[0]=this.block;a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0}if(t){for(r=this.start;s<o&&r<64;++s){a[r>>2]|=e[s]<<SHIFT[r++&3]}}else{for(r=this.start;s<o&&r<64;++s){i=e.charCodeAt(s);if(i<128){a[r>>2]|=i<<SHIFT[r++&3]}else if(i<2048){a[r>>2]|=(192|i>>6)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}else if(i<55296||i>=57344){a[r>>2]|=(224|i>>12)<<SHIFT[r++&3];a[r>>2]|=(128|i>>6&63)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}else{i=65536+((i&1023)<<10|e.charCodeAt(++s)&1023);a[r>>2]|=(240|i>>18)<<SHIFT[r++&3];a[r>>2]|=(128|i>>12&63)<<SHIFT[r++&3];a[r>>2]|=(128|i>>6&63)<<SHIFT[r++&3];a[r>>2]|=(128|i&63)<<SHIFT[r++&3]}}}this.lastByteIndex=r;this.bytes+=r-this.start;if(r>=64){this.block=a[16];this.start=r-64;this.hash();this.hashed=true}else{this.start=r}}if(this.bytes>4294967295){this.hBytes+=this.bytes/4294967296<<0;this.bytes=this.bytes%4294967296}return this};Sha256.prototype.finalize=function(){if(this.finalized){return}this.finalized=true;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block;e[t>>2]|=EXTRA[t&3];this.block=e[16];if(t>=56){if(!this.hashed){this.hash()}e[0]=this.block;e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0}e[14]=this.hBytes<<3|this.bytes>>>29;e[15]=this.bytes<<3;this.hash()};Sha256.prototype.hash=function(){var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7,c=this.blocks,l,u,d,h,f,p,g,y,w,m,_;for(l=16;l<64;++l){f=c[l-15];u=(f>>>7|f<<25)^(f>>>18|f<<14)^f>>>3;f=c[l-2];d=(f>>>17|f<<15)^(f>>>19|f<<13)^f>>>10;c[l]=c[l-16]+u+c[l-7]+d<<0}_=t&n;for(l=0;l<64;l+=4){if(this.first){if(this.is224){y=300032;f=c[0]-1413257819;a=f-150054599<<0;i=f+24177077<<0}else{y=704751109;f=c[0]-210244248;a=f-1521486534<<0;i=f+143694565<<0}this.first=false}else{u=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10);d=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7);y=e&t;h=y^e&n^_;g=s&r^~s&o;f=a+d+g+K[l]+c[l];p=u+h;a=i+f<<0;i=f+p<<0}u=(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10);d=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7);w=i&e;h=w^i&t^y;g=a&s^~a&r;f=o+d+g+K[l+1]+c[l+1];p=u+h;o=n+f<<0;n=f+p<<0;u=(n>>>2|n<<30)^(n>>>13|n<<19)^(n>>>22|n<<10);d=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7);m=n&i;h=m^n&e^w;g=o&a^~o&s;f=r+d+g+K[l+2]+c[l+2];p=u+h;r=t+f<<0;t=f+p<<0;u=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10);d=(r>>>6|r<<26)^(r>>>11|r<<21)^(r>>>25|r<<7);_=t&n;h=_^t&i^m;g=r&o^~r&a;f=s+d+g+K[l+3]+c[l+3];p=u+h;s=e+f<<0;e=f+p<<0}this.h0=this.h0+e<<0;this.h1=this.h1+t<<0;this.h2=this.h2+n<<0;this.h3=this.h3+i<<0;this.h4=this.h4+s<<0;this.h5=this.h5+r<<0;this.h6=this.h6+o<<0;this.h7=this.h7+a<<0};Sha256.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7;var c=HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[e&15]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[t&15]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[n&15]+HEX_CHARS[i>>28&15]+HEX_CHARS[i>>24&15]+HEX_CHARS[i>>20&15]+HEX_CHARS[i>>16&15]+HEX_CHARS[i>>12&15]+HEX_CHARS[i>>8&15]+HEX_CHARS[i>>4&15]+HEX_CHARS[i&15]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[s&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[r&15]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[o&15];if(!this.is224){c+=HEX_CHARS[a>>28&15]+HEX_CHARS[a>>24&15]+HEX_CHARS[a>>20&15]+HEX_CHARS[a>>16&15]+HEX_CHARS[a>>12&15]+HEX_CHARS[a>>8&15]+HEX_CHARS[a>>4&15]+HEX_CHARS[a&15]}return c};Sha256.prototype.toString=Sha256.prototype.hex;Sha256.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,i=this.h3,s=this.h4,r=this.h5,o=this.h6,a=this.h7;var c=[e>>24&255,e>>16&255,e>>8&255,e&255,t>>24&255,t>>16&255,t>>8&255,t&255,n>>24&255,n>>16&255,n>>8&255,n&255,i>>24&255,i>>16&255,i>>8&255,i&255,s>>24&255,s>>16&255,s>>8&255,s&255,r>>24&255,r>>16&255,r>>8&255,r&255,o>>24&255,o>>16&255,o>>8&255,o&255];if(!this.is224){c.push(a>>24&255,a>>16&255,a>>8&255,a&255)}return c};Sha256.prototype.array=Sha256.prototype.digest;Sha256.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32);var t=new DataView(e);t.setUint32(0,this.h0);t.setUint32(4,this.h1);t.setUint32(8,this.h2);t.setUint32(12,this.h3);t.setUint32(16,this.h4);t.setUint32(20,this.h5);t.setUint32(24,this.h6);if(!this.is224){t.setUint32(28,this.h7)}return e};function HmacSha256(e,t,n){var i,s=typeof e;if(s==="string"){var r=[],o=e.length,a=0,c;for(i=0;i<o;++i){c=e.charCodeAt(i);if(c<128){r[a++]=c}else if(c<2048){r[a++]=192|c>>6;r[a++]=128|c&63}else if(c<55296||c>=57344){r[a++]=224|c>>12;r[a++]=128|c>>6&63;r[a++]=128|c&63}else{c=65536+((c&1023)<<10|e.charCodeAt(++i)&1023);r[a++]=240|c>>18;r[a++]=128|c>>12&63;r[a++]=128|c>>6&63;r[a++]=128|c&63}}e=r}else{if(s==="object"){if(e===null){throw new Error(ERROR)}else if(ARRAY_BUFFER&&e.constructor===ArrayBuffer){e=new Uint8Array(e)}else if(!Array.isArray(e)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(e)){throw new Error(ERROR)}}}else{throw new Error(ERROR)}}if(e.length>64){e=new Sha256(t,true).update(e).array()}var l=[],u=[];for(i=0;i<64;++i){var d=e[i]||0;l[i]=92^d;u[i]=54^d}Sha256.call(this,t,n);this.update(u);this.oKeyPad=l;this.inner=true;this.sharedMemory=n}HmacSha256.prototype=new Sha256;HmacSha256.prototype.finalize=function(){Sha256.prototype.finalize.call(this);if(this.inner){this.inner=false;var e=this.array();Sha256.call(this,this.is224,this.sharedMemory);this.update(this.oKeyPad);this.update(e);Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports;exports.sha224=createMethod(true);exports.sha256.hmac=createHmacMethod();exports.sha224.hmac=createHmacMethod(true);if(COMMON_JS){module.exports=exports}else{root.sha256=exports.sha256;root.sha224=exports.sha224}})()})(sha256);var getRandomValues;var rnds8=new Uint8Array(16);function rng(){if(!getRandomValues){getRandomValues=typeof crypto!=="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!=="undefined"&&typeof msCrypto.getRandomValues==="function"&&msCrypto.getRandomValues.bind(msCrypto);if(!getRandomValues){throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported")}}return getRandomValues(rnds8)}const REGEX=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function validate(e){return typeof e==="string"&®EX.test(e)}var byteToHex=[];for(var i=0;i<256;++i){byteToHex.push((i+256).toString(16).substr(1))}function stringify(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var n=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!validate(n)){throw TypeError("Stringified UUID is invalid")}return n}function v4(e,t,n){e=e||{};var i=e.random||(e.rng||rng)();i[6]=i[6]&15|64;i[8]=i[8]&63|128;if(t){n=n||0;for(var s=0;s<16;++s){t[n+s]=i[s]}return t}return stringify(i)}async function getBytes(e,t){const n=e.getReader();let i;while(!(i=await n.read()).done){t(i.value)}}function getLines(e){let t;let n;let i;let s=false;return function r(o){if(t===undefined){t=o;n=0;i=-1}else{t=concat(t,o)}const a=t.length;let c=0;while(n<a){if(s){if(t[n]===10){c=++n}s=false}let r=-1;for(;n<a&&r===-1;++n){switch(t[n]){case 58:if(i===-1){i=n-c}break;case 13:s=true;case 10:r=n;break}}if(r===-1){break}e(t.subarray(c,r),i);c=n;i=-1}if(c===a){t=undefined}else if(c!==0){t=t.subarray(c);n-=c}}}function getMessages(e,t,n){let i=newMessage();const s=new TextDecoder;return function r(o,a){if(o.length===0){n===null||n===void 0?void 0:n(i);i=newMessage()}else if(a>0){const n=s.decode(o.subarray(0,a));const r=a+(o[a+1]===32?2:1);const c=s.decode(o.subarray(r));switch(n){case"data":i.data=i.data?i.data+"\n"+c:c;break;case"event":i.event=c;break;case"id":e(i.id=c);break;case"retry":const n=parseInt(c,10);if(!isNaN(n)){t(i.retry=n)}break}}}}function concat(e,t){const n=new Uint8Array(e.length+t.length);n.set(e);n.set(t,e.length);return n}function newMessage(){return{data:"",event:"",id:"",retry:undefined}}var __rest=undefined&&undefined.__rest||function(e,t){var n={};for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0)n[i]=e[i];if(e!=null&&typeof Object.getOwnPropertySymbols==="function")for(var s=0,i=Object.getOwnPropertySymbols(e);s<i.length;s++){if(t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s]))n[i[s]]=e[i[s]]}return n};const EventStreamContentType="text/event-stream";const DefaultRetryInterval=1e3;const LastEventId="last-event-id";function fetchEventSource(e,t){var{signal:n,headers:i,onopen:s,onmessage:r,onclose:o,onerror:a,openWhenHidden:c,fetch:l}=t,u=__rest(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(((t,d)=>{const h=Object.assign({},i);if(!h.accept){h.accept=EventStreamContentType}let f;function p(){f.abort();if(!document.hidden){b()}}if(!c){document.addEventListener("visibilitychange",p)}let g=DefaultRetryInterval;let y=0;function w(){document.removeEventListener("visibilitychange",p);window.clearTimeout(y);f.abort()}n===null||n===void 0?void 0:n.addEventListener("abort",(()=>{w();t()}));const m=l!==null&&l!==void 0?l:window.fetch;const _=s!==null&&s!==void 0?s:defaultOnOpen;async function b(){var n;f=new AbortController;try{const n=await m(e,Object.assign(Object.assign({},u),{headers:h,signal:f.signal}));await _(n);await getBytes(n.body,getLines(getMessages((e=>{if(e){h[LastEventId]=e}else{delete h[LastEventId]}}),(e=>{g=e}),r)));o===null||o===void 0?void 0:o();w();t()}catch(e){if(!f.signal.aborted){try{const t=(n=a===null||a===void 0?void 0:a(e))!==null&&n!==void 0?n:g;window.clearTimeout(y);y=window.setTimeout(b,t)}catch(e){w();d(e)}}}}b()}))}function defaultOnOpen(e){const t=e.headers.get("content-type");if(!(t===null||t===void 0?void 0:t.startsWith(EventStreamContentType))){throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${t}`)}}function Base64EncodeUrl(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function getTimestamp(){return Math.floor(Date.now()/1e3)}function e(e){this.message=e}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r$1="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var n=String(t).replace(/=+$/,"");if(n.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,s,r=0,o=0,a="";s=n.charAt(o++);~s&&(i=r%4?64*i+s:s,r++%4)?a+=String.fromCharCode(255&i>>(-2*r&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return a};function t$1(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(r$1(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return r$1(t)}}function n$1(e){this.message=e}function o(e,t){if("string"!=typeof e)throw new n$1("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(t$1(e.split(".")[n]))}catch(e){throw new n$1("Invalid token specified: "+e.message)}}n$1.prototype=new Error,n$1.prototype.name="InvalidTokenError";class NylasSessions{clientId;redirectUri;accessType="online";domain="http://api.nylas.com";versioned=false;Storage;hosted=false;multiAccount=false;loginId="";constructor(e){this.clientId=e.clientId;this.redirectUri=e.redirectUri;if(e.domain){this.domain=e.domain;const t=this.domain.substring(this.domain.length-3);if(t.includes("/v")){this.versioned=true}}if(e.multiAccount){this.multiAccount=e.multiAccount}if(e.sw){const e=new IndexedDBStorage;this.Storage=new Storage(e)}else{this.Storage=new Storage}if(e.accessType){this.accessType=e.accessType}if(e.loginId){this.loginId=e.loginId}if(e.hosted){this.hosted=e.hosted}if(e.disableInitCodeExchange!==true){this.codeExchange(null)}}async validateAccessToken(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const{access_token:n}=t;try{const e=await fetch(`${this.domain}/connect/tokeninfo?access_token=${n}`,{method:"GET"});const t=await e.json();if(!t.data){return false}return true}catch(e){return false}}async validateIDToken(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const{id_token:n}=t;try{const e=await fetch(`${this.domain}/connect/tokeninfo?id_token=${n}`,{method:"GET"});if(e.status!==200){return false}const t=await e.json();if(!t.data){return false}return true}catch(e){return false}}getDomain(){return this.domain}async auth(e){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){await this.hostedSetCodeChallenge()}const t=await this.generateAuthURL(e);if(e.popup){this.popUp(t);return}return t}async generateAuthURL(e){const t=await this.getCodeChallege();let n=`${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;if(t){n+=`&code_challenge=${t}&code_challenge_method=S256&options=rotate_refresh_token`}if(e.provider){n+=`&provider=${e.provider}`}if(e.loginHint){n+=`&login_hint=${e.loginHint}`;if(e.includeGrantScopes){n+=`&include_grant_scopes=${e.includeGrantScopes}`}}if(e.scope){n+=`&scope=${e.scope.join(" ")}`}if(e.prompt){n+=`&prompt=${e.prompt}`}if(e.metadata){n+=`&metadata=${e.metadata}`}if(e.state||this.loginId){n+=`&state=${this.loginId?this.loginId:e.state}`}return n}async generateReauthURL(e,t){if(!e){throw new Error("Grant ID is required")}const n=await this.Storage.getUserToken(e);const i=await this.getCodeChallege();let s=`${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;if(i){s+=`&code_challenge=${i}&code_challenge_method=S256&options=rotate_refresh_token`}if(n?.provider){s+=`&provider=${n.provider}`}if(n?.email){s+=`&login_hint=${n.email}`}if(t){s+=`&scope=${t.join(" ")}`}return s}async generateCodeChallenge(){const e=await this.Storage.getPKCE();if(e){return}const t=v4();this.Storage.setPKCE(t);return}async hostedSetCodeChallenge(){if(!this.hosted){throw console.error("Method only used with hosted flag enabled")}const e=new URLSearchParams(window.location.search);const t=e.get("code_challenge");if(!t){const e=await this.Storage.getPKCE();if(e){return}console.warn("Code challenge is recomended");return}this.Storage.setPKCE(t)}async getCodeChallege(){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){const e=new URLSearchParams(window.location.search);const t=e.get("code_challenge");if(!t){console.warn("Code challenge is recomended");return""}return t}const e=await this.Storage.getPKCE();if(e){const t=sha256.exports.sha256(e);let n=Buffer.from(t).toString("base64");n=Base64EncodeUrl(n);return n}return""}async isLoggedIn(){if(this.hosted&&(this.domain===window.location.origin||this.versioned&&this.domain.includes(window.location.origin))){return false}const e=await this.Storage.getUserTokens();if(e&&e.length>0){if(this.multiAccount){await this.generateCodeChallenge()}return true}await this.generateCodeChallenge();return false}isMultiAccount(){return this.multiAccount}async logout(){const e=await this.getProfile();await this.Storage.clearSession();const t={detail:e};window.dispatchEvent(new CustomEvent("onLogoutSuccess",t))}async getProfile(e=""){let t;if(e){t=await this.Storage.getUserToken(e)}else{t=await this.Storage.getUserToken()}if(t){return t}return null}async getProfiles(){const e=await this.Storage.getUserTokens();if(e){return e}return null}async removeProfile(e){await this.Storage.removeUserToken(e);await this.Storage.removeGrant(e);return null}async authIMAP(e){const t=await this.getCodeChallege();const n={imap_username:e.imap_username,imap_password:e.imap_password,imap_host:e.imap_host,imap_port:e.imap_port,type:e.type,smtp_host:e.smtp_host,smtp_port:e.smtp_port,provider:e.provider,redirect_uri:this.redirectUri,state:e.state,public_application_id:this.clientId,access_type:this.accessType};if(this.loginId){n.id=this.loginId}if(e.smtp_username&&e.smtp_password){n.smtp_username=e.smtp_username;n.smtp_password=e.smtp_password}if(t!=""){n.code_challenge=t;n.code_challenge_method="S256"}const i=await fetch(`${this.domain}/connect/login/imap`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(n)});const s=await i.json();return s}async authEWS(e){const t=await this.getCodeChallege();const n={...e,provider:"ews",redirect_uri:this.redirectUri,public_application_id:this.clientId,access_type:this.accessType};if(this.loginId){n.id=this.loginId}if(t!=""){n.code_challenge=t;n.code_challenge_method="S256"}const i=await fetch(`${this.domain}/connect/login/ews`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(n)});const s=await i.json();return s}async detectEmail(e){const t=await fetch(`${this.versioned?this.domain:this.domain+"/connect"}/providers/detect?client_id=${this.clientId}&email=${e}`,{method:"POST",headers:new Headers({"content-type":"application/json"})});const n=await t.json();return n}async applicationInfo(){const e=await fetch(`${this.versioned?this.domain:this.domain+"/connect"}/applications?client_id=${this.clientId}`,{method:"GET",headers:new Headers({"content-type":"application/json"})});const t=await e.json();return t.data}async getAvailableProviders(){const e=await fetch(`${this.domain}/connect/providers/find?client_id=${this.clientId}`,{method:"GET",headers:new Headers({"content-type":"application/json"})});if(e){const t=await e.json();const n=t.data;return n}return null}onLoginSuccess(e){window.addEventListener("onLoginSuccess",(t=>e(t)))}onLogoutSuccess(e){window.addEventListener("onLogoutSuccess",(t=>e(t)))}onLoginFail(e){window.addEventListener("onLoginFail",(t=>e(t)))}onTokenRefreshSuccess(e){window.addEventListener("onTokenRefreshSuccess",(t=>e(t)))}onTokenRefreshFail(e){window.addEventListener("onTokenRefreshFail",(t=>e(t)))}onSessionExpired(e){window.addEventListener("onSessionExpired",(t=>e(t)))}async codeExchange(e){let t=new URLSearchParams(window.location.search);if(e){t=new URLSearchParams(e)}const n=t.get("code");const i=t.get("state");const s=t.get("error");const r=t.get("error_description");const o=t.get("error_code");if(s&&r&&o){const e={detail:{error:s,error_description:r,error_code:o}};window.dispatchEvent(new CustomEvent("onLoginFail",e));window.history.pushState({},document.title,window.location.pathname);return false}if(!n){console.warn("No code found");return false}if(window.opener&&window.name==="uas-popup"){console.warn("Popup window detected");return false}const a=await this.Storage.getPKCE();if(!a){console.warn("No code verifier found");return false}try{const e={client_id:this.clientId,redirect_uri:this.redirectUri,code:n,grant_type:"authorization_code",code_verifier:a};const t=await fetch(`${this.domain}/connect/token`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(e)});const s=await t.json();if(s){if(s.error){const e={detail:s};window.dispatchEvent(new CustomEvent("onLoginFail",e));return true}const e=await this.handleCodeExchangeResponse(s);if(!e.valid){const t={detail:e.data};window.dispatchEvent(new CustomEvent("onLoginFail",t));return true}else{if(i){e.data.state=i}const t={detail:e.data};window.dispatchEvent(new CustomEvent("onLoginSuccess",t));window.history.pushState({},document.title,window.location.pathname)}}this.Storage.removePKCE();return true}catch(s){const e={detail:s};window.dispatchEvent(new CustomEvent("onLoginFail",e));window.history.pushState({},document.title,window.location.pathname);return false}}async tokenExchange(e=""){const t=await this.Storage.getGrant(e,this.multiAccount);if(!t){return false}const n=t.refresh_token;try{const t={client_id:this.clientId,redirect_uri:this.redirectUri,refresh_token:n,grant_type:"refresh_token"};const i=await fetch(`${this.domain}/connect/token`,{method:"POST",headers:new Headers({"content-type":"application/json"}),body:JSON.stringify(t)});const s=await i.json();if(s){if(s.error){const e={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",e));return true}const t=getTimestamp();s.expires_in=t+s.expires_in;this.Storage.setGrant(s,this.multiAccount);const n=await this.validateIDToken(e);if(!n){const e={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",e));return true}const i={detail:s};window.dispatchEvent(new CustomEvent("onTokenRefreshSuccess",i));return true}this.Storage.removePKCE()}catch(e){const t={detail:e};window.dispatchEvent(new CustomEvent("onTokenRefreshFail",t));return false}}async handleCodeExchangeResponse(e){const t=true;if(e.error){return{data:e,valid:false}}const n=getTimestamp();e.expires_in=n+e.expires_in;this.Storage.setGrant(e,this.multiAccount);const i=o(e.id_token);i.status="authenticated";this.Storage.setUserToken(i);const s=await this.validateIDToken(i.sub);if(!s){return{data:e,valid:false}}return{data:e,valid:t}}async popUp(e){const t=500;const n=600;const i=window.screenX+(window.outerWidth-t)/2;const s=window.screenY+(window.outerHeight-n)/2.5;const r=`uas-popup`;const o=e;const a=window.open(o,r,`width=${t},height=${n},left=${i},top=${s}`);if(!a){return}const c=setInterval((async()=>{if(a.closed){const e={detail:{error_description:"OAuth provider window closed"}};window.dispatchEvent(new CustomEvent("onLoginFail",e));c&&clearInterval(c);return}try{const e=a.location.href.split("?");if(!e[0]){return}const t=a.location.search;a.history.pushState({},document.title,window.location.pathname);if(e[0]===this.redirectUri&&e.length>1){const e=await this.codeExchange(t);a.close();if(e){location.reload()}c&&clearInterval(c);return}}catch(e){return}}),1e3)}async getAccessToken(e=""){const t=getTimestamp();const n=await this.Storage.getGrant(e,this.multiAccount);if(!n){return null}const{access_token:i,expires_in:s}=n;const r=i;if(r){if(s&&s>getTimestamp()){const e=s-t;if(e>30){return r}}}await this.tokenExchange(e);const o=await this.Storage.getGrant(e,this.multiAccount);return o.access_token}async sse(e,t){const n=t.headers||{};const i=n["Grant-ID"];let s="";if(this.multiAccount){if(!i){this.logout();throw new Error("Grant ID is required for multi account calls")}s=await this.getAccessToken(i)}else{s=await this.getAccessToken()}delete n["Grant-ID"];n["Authorization"]=`Bearer ${s}`;if(!n["content-type"]){n["content-type"]="application/json"}return fetchEventSource(`${this.domain}/${e}`,{...t,headers:n})}async fetch(e,t,n=true,i){let s="";let r=1;if(this.multiAccount){if(!t.grant_id){this.logout();throw new Error("Grant ID is required for multi account calls")}const e=await this.getProfiles();r=e?e.length:1;s=await this.getAccessToken(t.grant_id)}else{s=await this.getAccessToken()}if(!s){throw new Error("Access token not found")}let o=t.headers;if(!Headers.prototype.isPrototypeOf(o)){o=new Headers({Authorization:`Bearer ${s}`,"content-type":"application/json"})}else{o.append("Authorization",`Bearer ${s}`);if(!o.has("content-type")){o.append("content-type","application/json")}}try{if(t?.body){t.body=JSON.stringify(t?.body)}const s=await fetch(`${i||this.domain}/${e}`,{...t,headers:o});if(!n){return s}const a=await(s?.json());const c=await this.isAuthenticatedResponse(s.status,a);if(!c){if(r>1){const e=await this.getProfile(t.grant_id);if(e){e.status="unauthorized";await this.Storage.setUserToken(e);const t={detail:{user:e}};window.dispatchEvent(new CustomEvent("onSessionExpired",t))}}else{const e=await this.Storage.getUserToken();const t={detail:{user:e}};window.dispatchEvent(new CustomEvent("onSessionExpired",t))}this.logout();return}return a}catch(e){throw e}}async fetchRequest(e,t,n,i=true,s,r){const o=await this.isLoggedIn();const a=new URL(e,s??this.domain);const c=new Headers;c.append("Accept","application/json");c.append("Content-Type","application/json");c.append("User-Agent","nylas-identity");if(o){const e=await this.getAccessToken();c.append("Authorization",`Bearer ${e}`)}const l=await fetch(a.toString(),{method:t||"GET",headers:c,mode:"cors",referrer:location.origin,body:n?JSON.stringify(n):undefined,...r||{}});if(!i){return l.body}const u=await l.json();return u}async isAuthenticatedResponse(e,t){if(e==401&&t?.error?.type=="token.unauthorized_access"){return false}return true}addAPIKey(e,t,n){this.Storage.setUserToken({aud:"https://api-staging.us.nylas.com/",exp:2e9,email_verified:true,iat:getTimestamp(),iss:"",email:t,provider:"virtual-calendar",status:"authenticated",name:t,sub:e});this.Storage.setGrant({grant_id:e,access_token:n,expires_in:2e9},this.multiAccount)}}var react_production_min={};
|
|
2
2
|
/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react.production.min.js
|
|
@@ -8,4 +8,4 @@ import{h,F as Fragment,r as registerInstance,c as createEvent,H as Host,a as get
|
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
10
|
*/var l=Symbol.for("react.element"),n=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),t=Symbol.for("react.provider"),u=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),z=Symbol.iterator;function A(e){if(null===e||"object"!==typeof e)return null;e=z&&e[z]||e["@@iterator"];return"function"===typeof e?e:null}var B={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},C=Object.assign,D={};function E(e,t,n){this.props=e;this.context=t;this.refs=D;this.updater=n||B}E.prototype.isReactComponent={};E.prototype.setState=function(e,t){if("object"!==typeof e&&"function"!==typeof e&&null!=e)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};E.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function F(){}F.prototype=E.prototype;function G(e,t,n){this.props=e;this.context=t;this.refs=D;this.updater=n||B}var H=G.prototype=new F;H.constructor=G;C(H,E.prototype);H.isPureReactComponent=!0;var I=Array.isArray,J=Object.prototype.hasOwnProperty,K={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};function M(e,t,n){var i,s={},r=null,o=null;if(null!=t)for(i in void 0!==t.ref&&(o=t.ref),void 0!==t.key&&(r=""+t.key),t)J.call(t,i)&&!L.hasOwnProperty(i)&&(s[i]=t[i]);var a=arguments.length-2;if(1===a)s.children=n;else if(1<a){for(var c=Array(a),u=0;u<a;u++)c[u]=arguments[u+2];s.children=c}if(e&&e.defaultProps)for(i in a=e.defaultProps,a)void 0===s[i]&&(s[i]=a[i]);return{$$typeof:l,type:e,key:r,ref:o,props:s,_owner:K.current}}function N(e,t){return{$$typeof:l,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function O(e){return"object"===typeof e&&null!==e&&e.$$typeof===l}function escape(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,(function(e){return t[e]}))}var P=/\/+/g;function Q(e,t){return"object"===typeof e&&null!==e&&null!=e.key?escape(""+e.key):t.toString(36)}function R(e,t,i,s,r){var o=typeof e;if("undefined"===o||"boolean"===o)e=null;var a=!1;if(null===e)a=!0;else switch(o){case"string":case"number":a=!0;break;case"object":switch(e.$$typeof){case l:case n:a=!0}}if(a)return a=e,r=r(a),e=""===s?"."+Q(a,0):s,I(r)?(i="",null!=e&&(i=e.replace(P,"$&/")+"/"),R(r,t,i,"",(function(e){return e}))):null!=r&&(O(r)&&(r=N(r,i+(!r.key||a&&a.key===r.key?"":(""+r.key).replace(P,"$&/")+"/")+e)),t.push(r)),1;a=0;s=""===s?".":s+":";if(I(e))for(var c=0;c<e.length;c++){o=e[c];var u=s+Q(o,c);a+=R(o,t,i,u,r)}else if(u=A(e),"function"===typeof u)for(e=u.call(e),c=0;!(o=e.next()).done;)o=o.value,u=s+Q(o,c++),a+=R(o,t,i,u,r);else if("object"===o)throw t=String(e),Error("Objects are not valid as a React child (found: "+("[object Object]"===t?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return a}function S(e,t,n){if(null==e)return e;var i=[],s=0;R(e,i,"","",(function(e){return t.call(n,e,s++)}));return i}function T(e){if(-1===e._status){var t=e._result;t=t();t.then((function(t){if(0===e._status||-1===e._status)e._status=1,e._result=t}),(function(t){if(0===e._status||-1===e._status)e._status=2,e._result=t}));-1===e._status&&(e._status=0,e._result=t)}if(1===e._status)return e._result.default;throw e._result}var U={current:null},V={transition:null},W={ReactCurrentDispatcher:U,ReactCurrentBatchConfig:V,ReactCurrentOwner:K};react_production_min.Children={map:S,forEach:function(e,t,n){S(e,(function(){t.apply(this,arguments)}),n)},count:function(e){var t=0;S(e,(function(){t++}));return t},toArray:function(e){return S(e,(function(e){return e}))||[]},only:function(e){if(!O(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};react_production_min.Component=E;react_production_min.Fragment=p;react_production_min.Profiler=r;react_production_min.PureComponent=G;react_production_min.StrictMode=q;react_production_min.Suspense=w;react_production_min.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=W;react_production_min.cloneElement=function(e,t,n){if(null===e||void 0===e)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var i=C({},e.props),s=e.key,r=e.ref,o=e._owner;if(null!=t){void 0!==t.ref&&(r=t.ref,o=K.current);void 0!==t.key&&(s=""+t.key);if(e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in t)J.call(t,c)&&!L.hasOwnProperty(c)&&(i[c]=void 0===t[c]&&void 0!==a?a[c]:t[c])}var c=arguments.length-2;if(1===c)i.children=n;else if(1<c){a=Array(c);for(var u=0;u<c;u++)a[u]=arguments[u+2];i.children=a}return{$$typeof:l,type:e.type,key:s,ref:r,props:i,_owner:o}};react_production_min.createContext=function(e){e={$$typeof:u,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};e.Provider={$$typeof:t,_context:e};return e.Consumer=e};react_production_min.createElement=M;react_production_min.createFactory=function(e){var t=M.bind(null,e);t.type=e;return t};react_production_min.createRef=function(){return{current:null}};react_production_min.forwardRef=function(e){return{$$typeof:v,render:e}};react_production_min.isValidElement=O;react_production_min.lazy=function(e){return{$$typeof:y,_payload:{_status:-1,_result:e},_init:T}};react_production_min.memo=function(e,t){return{$$typeof:x,type:e,compare:void 0===t?null:t}};react_production_min.startTransition=function(e){var t=V.transition;V.transition={};try{e()}finally{V.transition=t}};react_production_min.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.")};react_production_min.useCallback=function(e,t){return U.current.useCallback(e,t)};react_production_min.useContext=function(e){return U.current.useContext(e)};react_production_min.useDebugValue=function(){};react_production_min.useDeferredValue=function(e){return U.current.useDeferredValue(e)};react_production_min.useEffect=function(e,t){return U.current.useEffect(e,t)};react_production_min.useId=function(){return U.current.useId()};react_production_min.useImperativeHandle=function(e,t,n){return U.current.useImperativeHandle(e,t,n)};react_production_min.useInsertionEffect=function(e,t){return U.current.useInsertionEffect(e,t)};react_production_min.useLayoutEffect=function(e,t){return U.current.useLayoutEffect(e,t)};react_production_min.useMemo=function(e,t){return U.current.useMemo(e,t)};react_production_min.useReducer=function(e,t,n){return U.current.useReducer(e,t,n)};react_production_min.useRef=function(e){return U.current.useRef(e)};react_production_min.useState=function(e){return U.current.useState(e)};react_production_min.useSyncExternalStore=function(e,t,n){return U.current.useSyncExternalStore(e,t,n)};react_production_min.useTransition=function(){return U.current.useTransition()};react_production_min.version="18.2.0";const LoginRequired=({authenticationUrl:e})=>h("div",{class:"login-required",part:"nse__login-required login-component"},h("div",{class:"card",part:"nse__login-required-card"},h("p",{part:"nse__login-required-text"},"Log into your account to use the Scheduler Editor."),h("button",{class:"google-button",part:"nse__login-required-google-button",onClick:async t=>{t.preventDefault();const n=await e("google");if(n){window.location.href=n}else{console.error(`[nylas-scheduler-editor] Unable to get authentication URL.`)}}},h("span",{class:"icon"},h("google-logo-icon",{width:"15",height:"15"})),"Continue with Google"),h("button",{class:"microsoft-button",part:"nse__login-required-microsoft-button",onClick:async t=>{t.preventDefault();const n=await e("microsoft");if(n){window.location.href=n}else{console.error(`[nylas-scheduler-editor] Unable to get authentication URL.`)}}},h("span",{class:"icon"},h("microsoft-logo-icon",{width:"15",height:"15"})),"Continue with Microsoft"),h("button",{class:"other-provider-button",part:"nse__login-required-other-provider-button",onClick:async t=>{t.preventDefault();const n=await e();if(n){window.location.href=n}else{console.error(`[nylas-scheduler-editor] Unable to get authentication URL.`)}}},"View all providers ",h("chevron-icon",{width:"17",height:"17"})),h("small",{class:"disclaimer-text",part:"nse__login-required-disclaimer-text"},"* You will be redirected to authenticate your account.")));function ExpressFlow({currentUser:e,calendars:t,selectedEventType:n,experimentalFeatures:i}){const s=t?.find((e=>e.is_primary))||t?.[0];const r=i?.[EXPERIMENTAL_FEATURES.group_events]||false;switch(n){case CONFIGURATION_EVENT_TYPE.one_on_one:case CONFIGURATION_EVENT_TYPE.max_availability:case CONFIGURATION_EVENT_TYPE.max_fairness:{return h(Fragment,null,h("nylas-event-info",null,h("div",{slot:"inputs"},h("nylas-event-title",null),h("nylas-event-duration",null),h("nylas-event-location",{userProvider:e.provider}))),h("nylas-booking-calendar-picker",{expressFlow:true,calendars:t,currentUser:e,defaultBookingCalendar:s?.id}),!r&&h("nylas-scheduling-method",{exportparts:"nsm, nsm__header, nsm__input-label, nsm__dropdown, nsm__dropdown-button, nsm__dropdown-content"}),h("nylas-custom-event-slug",{name:"custom-event-slug",exportparts:"nces, nces__body, nces__header, nces__drawer-toggle--container, nces__input-textfield"}))}case CONFIGURATION_EVENT_TYPE.collective:{return h(Fragment,null,h("nylas-event-info",null,h("div",{slot:"inputs"},h("nylas-event-title",null),h("nylas-event-duration",null),h("nylas-event-location",{userProvider:e.provider}))),h("nylas-booking-calendar-picker",{expressFlow:true,calendars:t,currentUser:e,defaultBookingCalendar:s?.id}),!r&&h("nylas-scheduling-method",{exportparts:"nsm, nsm__header, nsm__input-label, nsm__dropdown, nsm__dropdown-button, nsm__dropdown-content"}),h("nylas-custom-event-slug",{name:"custom-event-slug",exportparts:"nces, nces__body, nces__header, nces__drawer-toggle--container, nces__input-textfield"}),h("nylas-additional-participants",{name:"participants",eventParticipants:[{name:e?.name||e?.email,email:e?.email||"",is_organizer:true}],exportparts:"nadtnlpart, nadtnlpart__title, nadtnlpart__subtitle, nadtnlpart__content, nadtnlpart__input_group, nadtnlpart__input_wrapper, nadtnlpart__input, nadtnlpart__remove-participant"}))}case CONFIGURATION_EVENT_TYPE.group:{return h(Fragment,null,h("nylas-event-info",null,h("div",{slot:"inputs"},h("nylas-event-title",null),h("nylas-event-description",{hideAutoPopulateButton:true}),h("nylas-event-location",{userProvider:e.provider}),h("nylas-event-timeslot",{name:"event-timeslot"}),h("nylas-event-capacity",null))),h("nylas-booking-calendar-picker",{expressFlow:true,calendars:t,currentUser:e,defaultBookingCalendar:s?.id}),h("nylas-additional-participants",{name:"participants",eventParticipants:[{name:e?.name||e?.email,email:e?.email||"",is_organizer:true}],exportparts:"nadtnlpart, nadtnlpart__title, nadtnlpart__subtitle, nadtnlpart__content, nadtnlpart__input_group, nadtnlpart__input_wrapper, nadtnlpart__input, nadtnlpart__remove-participant"}),h("nylas-page-name",{requirePageName:true,pageName:"Group events page"}),h("nylas-custom-event-slug",{name:"custom-event-slug",exportparts:"nces, nces__body, nces__header, nces__drawer-toggle--container, nces__input-textfield"}))}}}const nylasSchedulerEditorCss=':host{display:flex;flex-direction:column;overflow:visible;border-radius:var(--nylas-border-radius-2x);width:fit-content;background:var(--nylas-base-0);position:relative;box-shadow:0px 0px 6px -2px rgba(0, 0, 0, 0.05), 0px 5px 15px -3px rgba(0, 0, 0, 0.1);--nylas-primary:#2563eb;--nylas-error:#cc4841;--nylas-error-pressed:#992222;--nylas-wraning:#f06c00;--nylas-success:#16a392;--nylas-info:#2b8fc2;--nylas-base-0:#ffffff;--nylas-base-25:#fcfcfd;--nylas-base-50:#f8f9fc;--nylas-base-100:#eaecf5;--nylas-base-200:#d5d9eb;--nylas-base-300:#b3b8d8;--nylas-base-400:#717bbc;--nylas-base-500:#4e5ba6;--nylas-base-600:#3e4784;--nylas-base-700:#263f72;--nylas-base-800:#293056;--nylas-base-900:#101323;--nylas-base-950:#0e101b;--nylas-color-blue-100:#e0e6f9;--nylas-border-radius:0.25rem;--nylas-border-radius-2x:0.5rem;--nylas-border-radius-3x:0.75rem;--nylas-font-family:"Inter", sans-serif;--nylas-color-black:#000000;--nylas-color-grey-900:#2c2c2c;--nylas-color-grey-800:#4b4b4b;--nylas-color-grey-700:#6e6e6e;--nylas-color-grey-600:#8e8e8e;--nylas-color-grey-500:#b3b3b3;--nylas-color-grey-400:#cacaca;--nylas-color-grey-300:#e1e1e1;--nylas-color-grey-200:#eaeaea;--nylas-color-grey-100:#f5f5f5;--nylas-color-grey-50:#fbfcfe;--nylas-color-white:#ffffff;--nylas-color-red-900:#992222;--nylas-color-red-700:#cc4841;--nylas-color-red-500:#ff786a;--nylas-color-red-300:#ffa79e;--nylas-color-red-100:#ffc5bf;--nylas-color-red-50:#ffeae8;--nylas-color-blue-900:#213571;--nylas-color-blue-700:#314fa9;--nylas-color-blue-500:#4169e1;--nylas-color-blue-300:#bdccf9;--nylas-color-blue-100:#e0e6f9;--nylas-color-blue-50:#f6f8fd;--nylas-color-yellow-900:#7c6506;--nylas-color-yellow-700:#c29f09;--nylas-color-yellow-500:#f7c90b;--nylas-color-yellow-300:#f9de70;--nylas-color-yellow-100:#fceba9;--nylas-color-yellow-50:#fdf4ce;--nylas-color-green-900:#0e6b60;--nylas-color-green-700:#16a392;--nylas-color-green-500:#17c3b2;--nylas-color-green-300:#74dbd1;--nylas-color-green-100:#a2e7e0;--nylas-color-green-50:#d1f3f0;--nylas-color-purple-900:#643554;--nylas-color-purple-700:#954f7d;--nylas-color-purple-500:#c769a7;--nylas-color-purple-300:#dda5ca;--nylas-color-purple-100:#e0bdd6;--nylas-color-purple-50:#e9dde5;--nylas-color-sky-900:#20698f;--nylas-color-sky-700:#2b8fc2;--nylas-color-sky-500:#6dceff;--nylas-color-sky-300:#8fdaff;--nylas-color-sky-100:#b8e7ff;--nylas-color-sky-50:#d9f2ff}@media screen and (max-width: 768px){:host{width:-moz-available;width:-webkit-fill-available;width:fill-available;min-width:325px}}div.scheduler-editor-content{height:610px}div.scheduler-editor-content.scheduler-editor-content--group_feature_enabled{height:900px}@media screen and (max-width: 768px){div.scheduler-editor-content.scheduler-editor-content--group_feature_enabled{height:auto}}@media screen and (max-width: 768px){div.scheduler-editor-content{height:auto}}div.scheduler-editor-content--group{height:900px}@media screen and (max-width: 768px){div.scheduler-editor-content--group{height:auto}}div.scheduler-editor-header{display:grid;grid-template-columns:1fr auto auto;align-items:center;justify-content:space-between;padding:1rem;border-bottom:1px solid var(--nylas-base-200);color:var(--nylas-base-900);min-width:924px}@media screen and (max-width: 768px){div.scheduler-editor-header{width:auto;min-width:calc(325px - 1rem)}}div.scheduler-editor-header h1.scheduler-editor-title{display:flex;align-items:center;gap:0.5rem;margin:0;font-size:18px;line-height:24px;font-weight:600}div.scheduler-editor-header button{background:transparent;border:none;cursor:pointer}div.scheduler-editor-header button:hover,div.scheduler-editor-header button:active{color:var(--nylas-primary);background-color:transparent}div.scheduler-editor-header button:disabled{cursor:not-allowed}div.scheduler-editor-header div.language select-dropdown::part(sd_dropdown-button){border:none;padding:4px;margin-right:8px}div.scheduler-editor-header div.language select-dropdown::part(sd_dropdown-button):hover{outline:none;color:var(--nylas-primary)}@media screen and (max-width: 768px){div.scheduler-editor-header div.language select-dropdown::part(sd_dropdown-content){width:-webkit-fill-available;width:fill-available;width:-moz-available}}nylas-select-event-type{height:inherit;width:calc(924px + 2rem)}@media screen and (max-width: 768px){nylas-select-event-type{width:auto}}nylas-editor-tabs,nylas-editor-tabs-group{width:auto;height:inherit}nylas-editor-tabs .row,nylas-editor-tabs-group .row{display:flex;gap:1rem}nylas-editor-tabs .composable,nylas-editor-tabs-group .composable{height:inherit;overflow:auto}nylas-editor-tabs nylas-event-info div[slot=inputs],nylas-editor-tabs nylas-event-limits div[slot=inputs],nylas-editor-tabs-group nylas-event-info div[slot=inputs],nylas-editor-tabs-group nylas-event-limits div[slot=inputs]{display:flex;flex-direction:column;gap:1rem}.card{display:flex;flex-direction:column;padding:2rem;background-color:var(--nylas-base-0);border:1px solid var(--nylas-base-200);border-radius:5px;max-width:fit-content;align-self:center}.login-required{height:inherit;overflow-y:auto;display:flex;flex-direction:column;justify-content:center;padding:2rem 1rem;background-color:var(--nylas-base-25);border-radius:var(--nylas-border-radius-2x)}@media screen and (max-width: 768px){.login-required{height:auto}}.login-required p{margin:0 0 1rem}.login-required .microsoft-button,.login-required .google-button{height:48px;border:1px solid var(--nylas-base-300);border-radius:var(--nylas-border-radius-2x);font-size:16px;line-height:24px;padding:0 1rem;background-color:var(--nylas-base-0);font-weight:600;cursor:pointer;display:flex;margin-bottom:1rem;background-color:var(--nylas-base-0);border:1px solid var(--nylas-base-200);border-radius:5px;justify-content:center;gap:0.5rem;align-items:center}.login-required .microsoft-button:hover,.login-required .google-button:hover{background-color:var(--nylas-base-25)}.login-required .microsoft-button:hover,.login-required .google-button:hover{background-color:var(--nylas-base-25)}.login-required .other-provider-button{height:48px;border:1px solid var(--nylas-base-300);border-radius:var(--nylas-border-radius-2x);font-size:16px;line-height:24px;padding:0 1rem;background-color:var(--nylas-base-0);font-weight:600;cursor:pointer;display:flex;border:0;background-color:var(--nylas-base-0);height:48px;margin-bottom:1rem;font-size:0.95rem;justify-content:center;gap:0.25rem;align-items:center}.login-required .other-provider-button:hover{background-color:var(--nylas-base-25)}.login-required .other-provider-button svg{transform:rotate(180deg)}.login-required .other-provider-button:hover{background-color:var(--nylas-base-25)}.login-required .disclaimer-text{font-size:0.75rem;color:var(--nylas-base-600);align-self:center}.list-configurations{padding:2rem;height:inherit;background:var(--nylas-base-25);border-radius:var(--nylas-border-radius-2x)}@media screen and (max-width: 768px){.list-configurations{height:auto;padding:2rem 1rem}}.list-configurations nylas-list-configurations{height:inherit;display:flex;flex-direction:column}';const NylasSchedulerEditorStyle0=nylasSchedulerEditorCss;const NylasSchedulerEditor=class{constructor(e){registerInstance(this,e);this.init=createEvent(this,"init",7);this.loggedIn=createEvent(this,"loggedIn",7);this.loggedOut=createEvent(this,"loggedOut",7);this.schedulerConfigCloseClicked=createEvent(this,"schedulerConfigCloseClicked",7);this.handleSchedulerConfigCloseClicked=e=>{const t=this.schedulerConfigCloseClicked.emit(this.host);if("schedulerConfigCloseClicked"in this.eventOverrides){this.eventOverrides.schedulerConfigCloseClicked(t,this.nylasSchedulerConfigConnector)}if(!t.defaultPrevented){localStorage.removeItem("grant");localStorage.removeItem("user");window.location.reload()}};this.authenticationUrl=async e=>{if(!this.nylasApiRequest){console.error(`[nylas-scheduler-editor] Nylas API Request is not initialized.`);return""}const t=await this.nylasApiRequest.authenticationUrl({provider:e});return t||""};this.configurationId=undefined;this.nylasApiRequest=undefined;this.nylasSessionsConfig=undefined;this.defaultAuthArgs=undefined;this.eventOverrides={};this.schedulerPreviewLink="";this.defaultSchedulerConfigState=undefined;this.mode="app";this.additionalParticipants=undefined;this.hideEditorTabs=[];this.conferenceProviders=undefined;this.requiresSlug=false;this.enableUserFeedback=true;this.defaultLanguage=undefined;this.localization=undefined;this.nylasBranding=true;this.experimentalFeatures=undefined;this.automaticComponentRegistration=true;this.selectedLanguage=this.defaultLanguage||LANGUAGE_CODE.en;this.langVersion=0}connectedCallback(){debug(`[nylas-scheduler-editor] connectedCallback`)}async componentWillLoad(){debug(`[nylas-scheduler-editor] componentWillLoad`);const e=this.additionalParticipants?.filter((e=>{const t=e.calendars?.length>0?e.calendars.filter((e=>e.id&&e.name)):[];if(e.name&&e.email&&t.length>0){return{name:e.name,email:e.email,calendars:t}}}));this.stores={schedulerConfig:CreateNylasSchedulerConfigStore({...this.defaultSchedulerConfigState,additionalParticipants:e,conferenceProviders:this.conferenceProviders,requiresSlug:this.requiresSlug,selectedLanguage:this.defaultLanguage||LANGUAGE_CODE.en,nylasBranding:this.nylasBranding,experimentalFeatures:this.experimentalFeatures})};if(!this.nylasApiRequest&&this.nylasSessionsConfig){const e=new NylasSessions(this.nylasSessionsConfig);await e.isLoggedIn();e.onLoginSuccess((async()=>{const e=await(this.nylasSchedulerConfigConnector?.schedulerConfig?.currentUser());if(e){const t=this.loggedIn.emit(this.host);if("loggedIn"in this.eventOverrides){await this.eventOverrides.loggedIn(t,this.nylasSchedulerConfigConnector)}if(!t.defaultPrevented){await this.loggedInHandler(e)}}}));e.onLoginFail((async()=>{this.stores?.schedulerConfig?.set("currentUser",null);const e=this.loggedOut.emit(this.host);if("loggedOut"in this.eventOverrides){await this.eventOverrides.loggedOut(e,this.nylasSchedulerConfigConnector);if(e.defaultPrevented){return}}}));this.nylasApiRequest=new NylasIdentityRequestWrapper(e)}if(this.nylasApiRequest&&this.defaultAuthArgs){this.nylasApiRequest.setDefaultAuthArgs(this.defaultAuthArgs)}this.baseProvider=new NylasBaseProvider(this.host,this.stores,this.automaticComponentRegistration,this.eventOverrides);const t=this.baseProvider.getStore("schedulerConfig");this.nylasSchedulerConfigConnector=new NylasSchedulerConfigConnector({nylasApiRequest:this.nylasApiRequest,nylasSchedulerConfigStore:t});const n=this.init.emit(this.host);if("init"in this.eventOverrides){await this.eventOverrides.init(n,this.nylasSchedulerConfigConnector)}if(!n.defaultPrevented){const e=await(this.nylasSchedulerConfigConnector?.schedulerConfig?.currentUser());if(e){const t=this.loggedIn.emit(this.host);if("loggedIn"in this.eventOverrides){await this.eventOverrides.loggedIn(t,this.nylasSchedulerConfigConnector)}if(!t.defaultPrevented){await this.loggedInHandler(e)}}else{this.stores?.schedulerConfig?.set("currentUser",null);const e=this.loggedOut.emit(this.host);if("loggedOut"in this.eventOverrides){await this.eventOverrides.loggedOut(e,this.nylasSchedulerConfigConnector);if(e.defaultPrevented){return}}}}this.stores?.schedulerConfig?.onChange("selectedConfiguration",(async e=>{if(e&&e.id){this.configurationId=e.id}}));this.baseProvider?.componentWillLoad(this.nylasSchedulerConfigConnector)}async componentDidLoad(){debug(`[nylas-scheduler-editor] componentDidLoad`);await(this.baseProvider?.componentDidLoad());this.updateLocalization(this.localization)}async componentDisconnected(){await(this.baseProvider?.componentDisconnected())}async configurationIdChanged(e){if(e){await(this.nylasSchedulerConfigConnector?.schedulerConfig?.getConfigurationById(e));this.stores?.schedulerConfig?.set("action","edit")}else{this.stores?.schedulerConfig?.set("selectedConfiguration",{});this.stores?.schedulerConfig?.set("action",null)}}updateLocalization(e){if(!e){return}Object.keys(e).forEach((t=>{if(!(t in LANGUAGE_CODE)){return}instance.addResourceBundle(t,"translation",e[t],false,true)}));this.langVersion++}updateNylasBranding(e){this.stores?.schedulerConfig?.set("nylasBranding",e)}updateExperimentalFeatures(e){this.stores?.schedulerConfig?.set("experimentalFeatures",e)}async store(){return this.stores?.schedulerConfig}async schedulerConnector(){return this.nylasSchedulerConfigConnector}async registerComponentHandler(e){this.baseProvider?.registerComponent(e.detail)}async unregisterComponentHandler(e){this.baseProvider?.unregisterComponent(e.detail)}nylasFormDropdownChangedHandler(e){const{name:t,value:n}=e.detail;if(t==="language"){this.selectedLanguage=LANGUAGE_CODE[n];instance.changeLanguage(this.selectedLanguage);this.stores?.schedulerConfig?.set("selectedLanguage",this.selectedLanguage)}}async loggedInHandler(e){this.stores?.schedulerConfig?.set("currentUser",e);if(!this.nylasSchedulerConfigConnector){return}await(this.nylasSchedulerConfigConnector.schedulerConfig?.getCalendars());if(this.configurationId){const e=await(this.nylasSchedulerConfigConnector.schedulerConfig?.getConfigurationById(this.configurationId));if(e&&e[0]?.id){this.stores?.schedulerConfig?.set("action","edit")}}}render(){const e=this.host.querySelector('[slot="custom-page-style-inputs"]');const t=this.stores?.schedulerConfig?.state.selectedConfiguration?.id;const n=Object.keys(LANGUAGE_MAP).map((e=>({label:LANGUAGE_MAP[e],value:e})));const i=this.stores?.schedulerConfig?.state.selectedEventType===CONFIGURATION_EVENT_TYPE.group||this.stores?.schedulerConfig?.state.selectedConfiguration?.type===CONFIGURATION_EVENT_TYPE.group;return h(Host,{key:"0053ea345fb1297974b68e859adc7caf738f0f35"},h("div",{key:"e3059c866be7f1d804b451fb54e01a5c219019b1",class:"scheduler-editor-header",part:"nse__header"},h("h1",{key:"56712052dd6fe1b8ff8a428c8ad3f0f491beac23",class:"scheduler-editor-title",part:"nse__title"},h("calendar-icon",{key:"dfe74ae46374c05c480b419124ba2055606b400a",width:"18",height:"18"}),instance.t("schedulerEditorTitle")),h("div",{key:"f4ba96f86e1e6e79d720273e0808d87528d74fc1",class:{language:true},part:"nse__language"},h("select-dropdown",{key:"3bfe4634f550553f0e2002aa5fec9b39b1cd9e75",name:"language",options:n,withChevron:false,defaultSelectedOption:n.find((e=>e.value==this.selectedLanguage)),exportparts:"sd_dropdown: nse__language-dropdown, sd_dropdown-button: nse__language-drop-button, sd_dropdown-content: nse__language-drop-content, sd_dropdown_label: nse__language-drop-label"},h("span",{key:"9926723981f56a7606ff94f213215e93bf51c472",slot:"select-icon"},h("translate-icon",{key:"d22a01ac1cef04ff5f2015c2cc73932c6fd7885c",width:"20",height:"20"})))),h("button",{key:"8f256e2b3978b33a0887bd3af8c987ab2b6b5782",class:"scheduler-editor-close",title:"logout",onClick:e=>this.handleSchedulerConfigCloseClicked(e),part:"nse__close-button"},h("close-icon",{key:"acd07b2fc1509f11440f4ad5047d20b3693e0750",width:"18",height:"18"}))),h("div",{key:"d39be68578574cbba4993ca63d2a8f087cecff04",class:{"scheduler-editor-content":true,"scheduler-editor-content--group_feature_enabled":!!this.stores?.schedulerConfig?.state.experimentalFeatures?.[EXPERIMENTAL_FEATURES.group_events],"scheduler-editor-content--group":i},part:"nse__content"},this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action===null&&h("div",{class:"list-configurations",part:"nse__list-configurations"},h("nylas-list-configurations",{exportparts:"nlc__create-new-cta, actions__dropdown, actions__dropdown-button, actions__dropdown-content, actions-Copy, actions-Preview, actions-Delete"})),this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action==="create-select"&&this.stores?.schedulerConfig?.state.experimentalFeatures?.[EXPERIMENTAL_FEATURES.group_events]&&h("nylas-select-event-type",null),this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action==="create"&&i&&h("nylas-editor-tabs-group",{mode:"composable"},h(ExpressFlow,{experimentalFeatures:this.stores?.schedulerConfig?.state?.experimentalFeatures,selectedEventType:this.stores?.schedulerConfig?.state?.selectedEventType||CONFIGURATION_EVENT_TYPE.one_on_one,currentUser:this.stores?.schedulerConfig?.state.currentUser,calendars:this.stores?.schedulerConfig?.state?.calendars,selectedConfiguration:this.stores?.schedulerConfig?.state?.selectedConfiguration})),this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action==="create"&&!i&&h("nylas-editor-tabs",{mode:"composable"},h(ExpressFlow,{experimentalFeatures:this.stores?.schedulerConfig?.state?.experimentalFeatures,selectedEventType:this.stores?.schedulerConfig?.state?.selectedEventType||CONFIGURATION_EVENT_TYPE.one_on_one,currentUser:this.stores?.schedulerConfig?.state.currentUser,calendars:this.stores?.schedulerConfig?.state?.calendars,selectedConfiguration:this.stores?.schedulerConfig?.state?.selectedConfiguration})),this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action==="edit"&&i&&h("nylas-editor-tabs-group",{key:t,mode:this.mode},this.mode==="composable"&&h("slot",null),this.mode==="app"&&e&&h("div",{style:{display:"none"},slot:"custom-page-style-inputs",key:t},h("slot",{name:"custom-page-style-inputs"}))),this.stores?.schedulerConfig?.state.currentUser&&this.stores.schedulerConfig.state.action==="edit"&&!i&&h("nylas-editor-tabs",{key:t,mode:this.mode},this.mode==="composable"&&h("slot",null),this.mode==="app"&&e&&h("div",{style:{display:"none"},slot:"custom-page-style-inputs",key:t},h("slot",{name:"custom-page-style-inputs"}))),!this.stores?.schedulerConfig?.state.currentUser&&h("slot",{name:"login-required"},h(LoginRequired,{authenticationUrl:this.authenticationUrl}))))}get host(){return getElement(this)}static get watchers(){return{configurationId:["configurationIdChanged"],localization:["updateLocalization"],nylasBranding:["updateNylasBranding"],experimentalFeatures:["updateExperimentalFeatures"]}}};NylasSchedulerEditor.style=NylasSchedulerEditorStyle0;export{NylasSchedulerEditor as nylas_scheduler_editor};
|
|
11
|
-
//# sourceMappingURL=p-
|
|
11
|
+
//# sourceMappingURL=p-eedabd6a.entry.js.map
|